diff options
author | Paul Phillips <paulp@improving.org> | 2009-10-28 00:33:21 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-10-28 00:33:21 +0000 |
commit | dbdac60079bdf5cdf3cb73d161c3d605a298795e (patch) | |
tree | 52be059fb57c079b29f84121cf10f3507076418f | |
parent | c3b27d3b4d9167400525de379c0c97756a2d8ce1 (diff) | |
download | scala-dbdac60079bdf5cdf3cb73d161c3d605a298795e.tar.gz scala-dbdac60079bdf5cdf3cb73d161c3d605a298795e.tar.bz2 scala-dbdac60079bdf5cdf3cb73d161c3d605a298795e.zip |
Made classpath do more advanced *-globbing.
of all or nothing you can give a java regexp and it will only use
matching jars, example: scala -cp 'foo*bar*.jar'
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index dc0f9524e1..aab74d8c02 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -29,20 +29,28 @@ import ch.epfl.lamp.compiler.msil.{Type => MSILType, Assembly} object ClassPath { /** Expand single path entry */ private def expandS(pattern: String): List[String] = { - def nameMatchesStar(name: String) = name.toLowerCase().endsWith(".jar") + def isJar(name: String) = name.toLowerCase endsWith ".jar" /** Get all jars in directory */ - def lsJars(f: File) = { + def lsJars(f: File, filt: String => Boolean = _ => true) = { val list = f.listFiles() if (list eq null) Nil - else list.filter(f => f.isFile() && nameMatchesStar(f.getName())).map(_.getPath()).toList + else list.filter(f => f.isFile() && filt(f.getName) && isJar(f.getName())).map(_.getPath()).toList } val suffix = File.separator + "*" + def basedir(s: String) = + if (s contains File.separator) s.substring(0, s.lastIndexOf(File.separator)) + else "." + if (pattern == "*") lsJars(new File(".")) - else if (pattern endsWith suffix) lsJars(new File(pattern.substring(0, pattern.length - suffix.length))) - else pattern :: Nil + else if (pattern endsWith suffix) lsJars(new File(pattern dropRight 2)) + else if (pattern contains '*') { + val regexp = ("^%s$" format pattern.replaceAll("""\*""", """.*""")).r + lsJars(new File(basedir(pattern)), regexp findFirstIn _ isDefined) + } + else List(pattern) } /** Split path using platform-dependent path separator */ |