diff options
Diffstat (limited to 'sbt-bridge/src/xsbt/ConsoleInterface.scala')
-rw-r--r-- | sbt-bridge/src/xsbt/ConsoleInterface.scala | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sbt-bridge/src/xsbt/ConsoleInterface.scala b/sbt-bridge/src/xsbt/ConsoleInterface.scala new file mode 100644 index 000000000..f56918113 --- /dev/null +++ b/sbt-bridge/src/xsbt/ConsoleInterface.scala @@ -0,0 +1,73 @@ +/* sbt -- Simple Build Tool + * Copyright 2008, 2009 Mark Harrah + */ +package xsbt + +import xsbti.Logger +import scala.tools.nsc.{ GenericRunnerCommand, Interpreter, InterpreterLoop, ObjectRunner, Settings } +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 + +class ConsoleInterface { + def commandArguments( + args: Array[String], + bootClasspathString: String, + classpathString: String, + log: Logger + ): Array[String] = args + + def run(args: Array[String], + bootClasspathString: String, + classpathString: String, + initialCommands: String, + cleanupCommands: String, + loader: ClassLoader, + bindNames: Array[String], + bindValues: Array[Any], + log: Logger + ): Unit = { + val completeArgs = + args :+ + "-bootclasspath" :+ bootClasspathString :+ + "-classpath" :+ classpathString + + println("Starting dotty interpreter...") + val repl = ConsoleInterface.customRepl( + initialCommands :: Nil, + cleanupCommands :: Nil, + bindNames zip bindValues, + loader + ) + repl.process(completeArgs) + } +} + +object ConsoleInterface { + def customConfig( + initCmds: List[String], + cleanupCmds: List[String], + 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 { + override lazy val config = cfg + } + + def customRepl( + initCmds: List[String], + cleanupCmds: List[String], + boundVals: Array[(String, Any)], + loader: ClassLoader + ): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals, loader)) +} |