aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-07 02:53:00 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-07 09:31:13 -0500
commit7cda6c28d59bf226c3bef767788ef395e72b8165 (patch)
tree53a4f6169d478dc53d26ce5eb9b97b42462bf654 /libraries
parent7b2f3bbd3741450992d4152d8c64c45b41734d74 (diff)
downloadcbt-7cda6c28d59bf226c3bef767788ef395e72b8165.tar.gz
cbt-7cda6c28d59bf226c3bef767788ef395e72b8165.tar.bz2
cbt-7cda6c28d59bf226c3bef767788ef395e72b8165.zip
Make classloader overridable. CBT isolates classloaders, so Eval could
only see itself, but it often needs to see things in the classloaders of user code, so now we can provie the classloader.
Diffstat (limited to 'libraries')
-rw-r--r--libraries/eval/Eval.scala24
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 = {