diff options
-rw-r--r-- | bridge/src/main/scala/xsbt/ConsoleInterface.scala | 13 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/REPL.scala | 10 |
3 files changed, 26 insertions, 11 deletions
diff --git a/bridge/src/main/scala/xsbt/ConsoleInterface.scala b/bridge/src/main/scala/xsbt/ConsoleInterface.scala index 1aec2a241..f56918113 100644 --- a/bridge/src/main/scala/xsbt/ConsoleInterface.scala +++ b/bridge/src/main/scala/xsbt/ConsoleInterface.scala @@ -9,6 +9,7 @@ import scala.tools.nsc.interpreter.InteractiveReader import scala.tools.nsc.reporters.Reporter import scala.tools.nsc.util.ClassPath +import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.repl.REPL import dotty.tools.dotc.repl.REPL.Config @@ -39,7 +40,8 @@ class ConsoleInterface { val repl = ConsoleInterface.customRepl( initialCommands :: Nil, cleanupCommands :: Nil, - bindNames zip bindValues + bindNames zip bindValues, + loader ) repl.process(completeArgs) } @@ -49,11 +51,13 @@ object ConsoleInterface { def customConfig( initCmds: List[String], cleanupCmds: List[String], - boundVals: Array[(String, Any)] + boundVals: Array[(String, Any)], + loader: ClassLoader ) = new Config { override val initialCommands: List[String] = initCmds override val cleanupCommands: List[String] = cleanupCmds override val boundValues: Array[(String, Any)] = boundVals + override val classLoader: Option[ClassLoader] = Option(loader) } def customRepl(cfg: Config): REPL = new REPL { @@ -63,6 +67,7 @@ object ConsoleInterface { def customRepl( initCmds: List[String], cleanupCmds: List[String], - boundVals: Array[(String, Any)] - ): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals)) + boundVals: Array[(String, Any)], + loader: ClassLoader + ): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals, loader)) } 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", "") != "" |