summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-07-09 16:14:53 +0000
committermichelou <michelou@epfl.ch>2007-07-09 16:14:53 +0000
commit7ef97b29932407d1413401a82e08215e13b3cd5e (patch)
treeff692890cc26e8a42f85711ea6a45e062c1921e9 /src
parentd46c58d0f7e114300c5b301d9773661520dfb16a (diff)
downloadscala-7ef97b29932407d1413401a82e08215e13b3cd5e.tar.gz
scala-7ef97b29932407d1413401a82e08215e13b3cd5e.tar.bz2
scala-7ef97b29932407d1413401a82e08215e13b3cd5e.zip
added star expansion (Stepan's contrib)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala4
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala9
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala9
-rw-r--r--src/compiler/scala/tools/nsc/ScriptRunner.scala15
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala65
5 files changed, 68 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 1aef6d0742..68210e1fa4 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -17,7 +17,7 @@ import scala.collection.mutable.{ListBuffer, HashSet, ArrayBuffer}
import io.PlainFile
import reporters.{ConsoleReporter, Reporter}
import symtab.Flags
-import util.SourceFile
+import util.{ClassPath, SourceFile}
import nsc.{InterpreterResults=>IR}
/** <p>
@@ -112,7 +112,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
/** the compiler's classpath, as URL's */
val compilerClasspath: List[URL] =
- compiler.settings.classpath.value.split(File.pathSeparator).toList.
+ ClassPath.expandPath(compiler.settings.classpath.value).
map(s => new File(s).toURL)
/** class loader used to load compiled code */
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 80b233fa47..d0b39d1fcd 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -6,12 +6,11 @@
package scala.tools.nsc
-import java.lang.System
-import java.lang.ClassLoader
+import java.lang.{ClassLoader, System}
import java.io.{BufferedReader, InputStreamReader, File, FileReader, PrintWriter}
import java.io.IOException
-import scala.tools.nsc.util.Position
+import scala.tools.nsc.util.{ClassPath, Position}
import nsc.{InterpreterResults=>IR}
/** The
@@ -259,8 +258,8 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
uglinessxxx =
new java.net.URLClassLoader(
- settings.classpath.value.split(File.pathSeparator).
- map(s => new File(s).toURL),
+ ClassPath.expandPath(settings.classpath.value).
+ map(s => new File(s).toURL).toArray,
classOf[InterpreterLoop].getClassLoader)
createInterpreter()
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index b8e9e7e3f8..d98abb19c6 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -12,6 +12,8 @@ import java.lang.{ClassNotFoundException, NoSuchMethodException}
import java.lang.reflect.InvocationTargetException
import java.net.URL
+import util.ClassPath
+
/** An object that runs Scala code. It has three possible
* sources for the code to run: pre-compiled code, a script file,
* or interactive entry.
@@ -89,22 +91,19 @@ object MainGenericRunner {
return
}
- def paths0(str: String): List[String] =
- str.split(File.pathSeparator).toList
-
def fileToURL(f: File): Option[URL] =
try { Some(f.toURL) }
catch { case e => Console.println(e); None }
def paths(str: String): List[URL] =
for (
- file <- paths0(str) map (new File(_)) if file.exists;
+ file <- ClassPath.expandPath(str) map (new File(_)) if file.exists;
val url = fileToURL(file); if !url.isEmpty
) yield url.get
def jars(dirs: String): List[URL] =
for (
- libdir <- paths0(dirs) map (new File(_)) if libdir.isDirectory;
+ libdir <- ClassPath.expandPath(dirs) map (new File(_)) if libdir.isDirectory;
jarfile <- libdir.listFiles if jarfile.isFile && jarfile.getName.endsWith(".jar");
val url = fileToURL(jarfile); if !url.isEmpty
) yield url.get
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala
index f67fc15f80..166764e29a 100644
--- a/src/compiler/scala/tools/nsc/ScriptRunner.scala
+++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -14,7 +14,7 @@ import java.util.jar.{JarEntry, JarOutputStream}
import scala.tools.nsc.io.PlainFile
import scala.tools.nsc.reporters.{Reporter,ConsoleReporter}
-import scala.tools.nsc.util.{CompoundSourceFile, SourceFile, SourceFileFragment}
+import scala.tools.nsc.util.{ClassPath, CompoundSourceFile, SourceFile, SourceFileFragment}
/** An object that runs Scala code in script files.
*
@@ -360,23 +360,20 @@ class ScriptRunner {
}
withCompiledScript(settings, scriptFile)(compiledLocation => {
- def paths0(str: String): List[String] =
- str.split(File.pathSeparator).toList
-
def fileToURL(f: File): Option[URL] =
try { Some(f.toURL) }
catch { case e => Console.println(e); None }
- def paths(str: String): List[URL] =
+ def paths(str: String, expandStar: Boolean): List[URL] =
for (
- file <- paths0(str) map (new File(_)) if file.exists;
+ file <- ClassPath.expandPath(str, expandStar) map (new File(_)) if file.exists;
val url = fileToURL(file); if !url.isEmpty
) yield url.get
val classpath: List[URL] =
- paths(settings.bootclasspath.value) :::
- paths(compiledLocation) :::
- paths(settings.classpath.value)
+ paths(settings.bootclasspath.value, true) :::
+ paths(compiledLocation, false) :::
+ paths(settings.classpath.value, true)
try {
ObjectRunner.run(
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index 754abfc8b8..6ac66ae968 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -1,10 +1,7 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
+/* NSC -- new Scala compiler
+ * Copyright 2006-2007 LAMP/EPFL
+ * @author Martin Odersky
+ */
// $Id$
@@ -18,6 +15,50 @@ import scala.collection.mutable.ArrayBuffer
import scala.tools.nsc.io.AbstractFile
/** <p>
+ * This module provides star expansion of '-classpath' option arguments.
+ * </p>
+ *
+ * @author Stepan Koltsov
+ */
+object ClassPath {
+ /** Expand single path entry */
+ private def expandStar(pattern: String): List[String] = {
+ def nameMatchesStar(name: String) = name.toLowerCase().endsWith(".jar")
+
+ /** Get all jars in directory */
+ def lsJars(f: File) = {
+ val list = f.listFiles()
+ if (list eq null) Nil
+ else list.filter(f => f.isFile() && nameMatchesStar(f.getName())).map(_.getPath()).toList
+ }
+
+ val suffix = File.separator + "*"
+
+ if (pattern == "*") lsJars(new File("."))
+ else if (pattern endsWith suffix) lsJars(new File(pattern.substring(0, pattern.length - suffix.length)))
+ else pattern :: Nil
+ }
+
+ /** Split path using platform-dependent path separator */
+ def splitPath(path: String): List[String] = {
+ val strtok = new StringTokenizer(path, File.pathSeparator)
+ val buf = new ListBuffer[String]
+ while (strtok.hasMoreTokens()) {
+ buf + strtok.nextToken()
+ }
+ buf.toList
+ }
+
+ /** Expand path with expanding stars */
+ def expandPath(path: String): List[String] = splitPath(path).flatMap(expandStar(_))
+
+ def expandPath(path: String, expandStar: Boolean): List[String] =
+ if (expandStar) expandPath(path)
+ else splitPath(path)
+
+}
+
+/** <p>
* Richer classpath abstraction than files.
* </p>
* <p>
@@ -223,17 +264,15 @@ class ClassPath(onlyPresentation: Boolean) {
}
private def addFilesInPath(path: String) {
- val strtok = new StringTokenizer(path, File.pathSeparator)
- while (strtok.hasMoreTokens()) {
- val file = AbstractFile.getDirectory(strtok.nextToken())
+ for (fileName <- ClassPath.expandPath(path)) {
+ val file = AbstractFile.getDirectory(fileName)
if (file ne null) entries += (new Library(file))
}
}
private def addArchivesInExtDirPath(path: String) {
- val strtok = new StringTokenizer(path, File.pathSeparator)
- while (strtok.hasMoreTokens()) {
- val file = AbstractFile.getDirectory(strtok.nextToken())
+ for (fileName <- ClassPath.expandPath(path)) {
+ val file = AbstractFile.getDirectory(fileName)
if (file ne null) {
for (file0 <- file) {
val name = file0.name