diff options
author | Paul Phillips <paulp@improving.org> | 2011-11-21 20:38:58 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-11-21 20:38:58 +0000 |
commit | eb0643210f2007775df3d116f237056ec5916874 (patch) | |
tree | b568cfb05b6a881dc32d67fbff54497fbbcb7a0c /src/compiler/scala/tools/nsc/util/ClassPath.scala | |
parent | f9278123ebc33bbd4833e431575c4d1b22404d57 (diff) | |
download | scala-eb0643210f2007775df3d116f237056ec5916874.tar.gz scala-eb0643210f2007775df3d116f237056ec5916874.tar.bz2 scala-eb0643210f2007775df3d116f237056ec5916874.zip |
Implemented manifest-based class-paths.
If you run a jar directly, like
scala foo.jar
Then if a Class-Path attribute is present in the jar manifest, the
classpath will be constructed from that instead of the arguments. Some
things remain to be determined, like whether it's supposed to replace
a classpath given on the command line or supplement it, and whether
the master jar should be on the classpath or only and exactly the jars
listed in the manifest.
There's a really nice test case, which won't be run of course, but I
can't stand going any further without tests for these hard to test on
all platforms things. The faux .check file shows what I see.
Closes SI-4355, review by harrah.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/ClassPath.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index 484f809e6f..622b4db2a2 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -13,6 +13,7 @@ import io.{ File, Directory, Path, Jar, AbstractFile, ClassAndJarInfo } import scala.tools.util.StringOps.splitWhere import Jar.isJarOrZip import File.pathSeparator +import java.net.MalformedURLException /** <p> * This module provides star expansion of '-classpath' option arguments, behaves the same as @@ -110,11 +111,22 @@ object ClassPath { case dir => dir filter (_.isClassContainer) map (x => new java.io.File(dir.file, x.name) getPath) toList } } + /** Expand manifest jar classpath entries: these are either urls, or paths + * relative to the location of the jar. + */ + def expandManifestPath(jarPath: String): List[URL] = { + val file = File(jarPath) + if (!file.isFile) return Nil + + val baseDir = file.parent + new Jar(file).classPathElements map (elem => + specToURL(elem) getOrElse (baseDir / elem).toURL + ) + } /** A useful name filter. */ def isTraitImplementation(name: String) = name endsWith "$class.class" - import java.net.MalformedURLException def specToURL(spec: String): Option[URL] = try Some(new URL(spec)) catch { case _: MalformedURLException => None } |