diff options
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/REPL.scala | 10 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index b6a3e388e..897011be2 100644 --- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -60,7 +60,11 @@ import printing.SyntaxHighlighting * @param ictx The context to use for initialization of the interpreter, * needed to access the current classpath. */ -class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler with Interpreter { +class CompilingInterpreter( + out: PrintWriter, + ictx: Context, + parentClassLoader: Option[ClassLoader] +) extends Compiler with Interpreter { import ast.untpd._ import CompilingInterpreter._ @@ -136,8 +140,6 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit /** the compiler's classpath, as URL's */ val compilerClasspath: List[URL] = ictx.platform.classPath(ictx).asURLs - protected def parentClassLoader: ClassLoader = classOf[Interpreter].getClassLoader - /* A single class loader is used for all commands interpreted by this Interpreter. It would also be possible to create a new class loader for each command to interpret. The advantages of the current approach are: @@ -153,8 +155,10 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit */ /** class loader used to load compiled code */ val classLoader: ClassLoader = { - val parent = new URLClassLoader(compilerClasspath.toArray, parentClassLoader) - new AbstractFileClassLoader(virtualDirectory, parent) + lazy val parent = new URLClassLoader(compilerClasspath.toArray, + classOf[Interpreter].getClassLoader) + + new AbstractFileClassLoader(virtualDirectory, parentClassLoader.getOrElse(parent)) } // Set the current Java "context" class loader to this interpreter's class loader diff --git a/src/dotty/tools/dotc/repl/REPL.scala b/src/dotty/tools/dotc/repl/REPL.scala index 1fcb055d6..cca5e8d6b 100644 --- a/src/dotty/tools/dotc/repl/REPL.scala +++ b/src/dotty/tools/dotc/repl/REPL.scala @@ -4,7 +4,10 @@ package repl import core.Contexts.Context import reporting.Reporter -import java.io.{BufferedReader, File, FileReader, PrintWriter} +import io.{AbstractFile, PlainFile, VirtualDirectory} +import scala.reflect.io.{PlainDirectory, Directory} +import java.io.{BufferedReader, File => JFile, FileReader, PrintWriter} +import java.net.{URL, URLClassLoader} /** A compiler which stays resident between runs. * Usage: @@ -31,7 +34,7 @@ class REPL extends Driver { } override def newCompiler(implicit ctx: Context): Compiler = - new repl.CompilingInterpreter(config.output, ctx) + new repl.CompilingInterpreter(config.output, ctx, config.classLoader) override def sourcesRequired = false @@ -80,6 +83,9 @@ object REPL { */ val boundValues: Array[(String, Any)] = Array.empty[(String, Any)] + /** To pass a custom ClassLoader to the Dotty REPL, overwride this value */ + val classLoader: Option[ClassLoader] = None + /** The default input reader */ def input(in: Interpreter)(implicit ctx: Context): InteractiveReader = { val emacsShell = System.getProperty("env.emacs", "") != "" |