aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorNick Kallen <nkallen@tallbro.local>2010-09-01 22:19:09 -0700
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-07 02:08:36 -0500
commitab6b17de45fd49aef81e969e2b6228a984a5c97a (patch)
treebd5b0d256641e832894d0acc24455b48955d2671 /libraries
parent519db4af85c08a8650d0b722469d427311973967 (diff)
downloadcbt-ab6b17de45fd49aef81e969e2b6228a984a5c97a.tar.gz
cbt-ab6b17de45fd49aef81e969e2b6228a984a5c97a.tar.bz2
cbt-ab6b17de45fd49aef81e969e2b6228a984a5c97a.zip
Nested jars are added to load path when evaluating.
Diffstat (limited to 'libraries')
-rw-r--r--libraries/eval/Eval.scala26
1 files changed, 19 insertions, 7 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala
index da4d05e..791b32e 100644
--- a/libraries/eval/Eval.scala
+++ b/libraries/eval/Eval.scala
@@ -6,6 +6,7 @@ import scala.runtime._
import java.io.{File, FileWriter}
import java.net.{URL, URLClassLoader}
import scala.io.Source
+import java.util.jar._
/**
* Eval is a utility function to evaluate a file and return its results.
@@ -104,6 +105,7 @@ object Eval {
targetFile
}
+ val JarFile = """\.jar$""".r
/**
* Compile a given file into the targetDir
*/
@@ -115,13 +117,24 @@ object Eval {
// TODO: there are likely a ton of corner cases waiting here
val configulousClassLoader = this.getClass.getClassLoader.asInstanceOf[URLClassLoader]
val configulousClasspath = configulousClassLoader.getURLs.map { url =>
- val urlStr = url.toString
- urlStr.substring(5, urlStr.length)
+ val urlStr = url.toString
+ urlStr.substring(5, urlStr.length)
}.toList
+
+ // It's not clear how many nested jars we should open.
+ val classPathAndClassPathsNestedInJars = configulousClasspath.flatMap { fileName =>
+ val nestedClassPath = if (JarFile.findFirstMatchIn(fileName).isDefined) {
+ val nestedClassPathAttribute = new JarFile(fileName).getManifest.getMainAttributes.getValue("Class-Path")
+ if (nestedClassPathAttribute != null) {
+ nestedClassPathAttribute.split(" ").toList
+ } else Nil
+ } else Nil
+ List(fileName) ::: nestedClassPath
+ }
val bootClassPath = origBootclasspath.split(java.io.File.pathSeparator).toList
// the classpath for compile is our app path + boot path + make sure we have compiler/lib there
- val pathList = bootClassPath ::: (configulousClasspath ::: List(compilerPath, libPath))
+ val pathList = bootClassPath ::: (classPathAndClassPathsNestedInJars ::: List(compilerPath, libPath))
val pathString = pathList.mkString(java.io.File.pathSeparator)
settings.bootclasspath.value = pathString
settings.classpath.value = pathString
@@ -132,7 +145,7 @@ object Eval {
val reporter = new ConsoleReporter(settings)
val compiler = new Global(settings, reporter)
(new compiler.Run).compile(List(file.toString))
-
+
if (reporter.hasErrors || reporter.WARNING.count > 0) {
// TODO: throw ...
}
@@ -149,7 +162,7 @@ object Eval {
val newClassLoader = URLClassLoader.newInstance(Array(targetDir.toURL), scalaClassLoader)
newClassLoader.loadClass(className)
}
-
+
private def jarPathOfClass(className: String) = {
val resource = className.split('.').mkString("/", "/", ".class")
//println("resource for %s is %s".format(className, resource))
@@ -158,5 +171,4 @@ object Eval {
val indexOfSeparator = path.lastIndexOf('!')
path.substring(indexOfFile, indexOfSeparator)
}
-
-} \ No newline at end of file
+}