diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/eval/Eval.scala | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index 057fd53..395fc2f 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -94,7 +94,7 @@ class Eval(target: Option[File]) { Seq( new IncludePreprocessor( Seq( - new ClassScopedResolver(getClass), + new ClassLoaderResolver(classLoader), new FilesystemResolver(new File(".")), new FilesystemResolver(new File("." + File.separator + "config")) ) ++ ( @@ -387,15 +387,17 @@ class Eval(target: Option[File]) { new FileInputStream(file(path)) } - class ClassScopedResolver(clazz: Class[_]) extends Resolver { + class ClassLoaderResolver(classLoader: ClassLoader) extends Resolver { private[this] def quotePath(path: String) = "/" + path - def resolvable(path: String): Boolean = - clazz.getResourceAsStream(quotePath(path)) != null + def resolvable(path: String): Boolean = { + classLoader.getResourceAsStream(quotePath(path)) != null + } - def get(path: String): InputStream = - clazz.getResourceAsStream(quotePath(path)) + def get(path: String): InputStream = { + classLoader.getResourceAsStream(quotePath(path)) + } } class ResolutionFailedException(message: String) extends Exception @@ -464,6 +466,12 @@ class Eval(target: Option[File]) { classpath.value = (pathList ::: impliedClassPath).mkString(File.pathSeparator) } + /** Class loader for finding classes compiled by StringCompiler. + * Override if the classloader of Eval does not have access to + * all classes used by the code it compiles. + */ + def classLoader = this.getClass.getClassLoader + /** * Dynamic scala compiler. Lots of (slow) state is created, so it may be advantageous to keep * around one of these and reuse it. @@ -522,7 +530,7 @@ class Eval(target: Option[File]) { * Class loader for finding classes compiled by this StringCompiler. * After each reset, this class loader will not be able to find old compiled classes. */ - var classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader) + var classLoader = new AbstractFileClassLoader(target, Eval.this.classLoader) def reset() { targetDir match { @@ -539,7 +547,7 @@ class Eval(target: Option[File]) { } cache.clear() reporter.reset() - classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader) + classLoader = new AbstractFileClassLoader(target, Eval.this.classLoader) } def resetReporter(): Unit = { |