Files
sbt/compile/interface/ConsoleInterface.scala
T
Mark Harrah a76d75bca6 more flexible scalac logging
the custom scalac Reporter now delegates to an instance of
  an sbt interface called xsbti.Reporter
handling compilation logging is now mainly done on the sbt-side of the
  compiler interface
the xsbti.Reporter interface provides access to richer information
  about errors and warnings, including source file, line, and offset
xsbti.Reporter can be implemented by users to get access to
  detailed information without needing to parse the logging output
the CompileFailed exception that is thrown when compilation fails now
  includes an array of the problems, providing detailed
  error and warning information that can, for example, be consumed
  by doing a mapFailure on 'compile' and using 'Compile.allProblems'
2010-10-23 16:34:22 -04:00

65 lines
2.2 KiB
Scala

/* 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
class ConsoleInterface
{
def run(args: Array[String], bootClasspathString: String, classpathString: String, initialCommands: String, loader: ClassLoader, bindNames: Array[String], bindValues: Array[Any], log: Logger)
{
val options = args.toList
lazy val interpreterSettings = xsbt.MakeSettings(options, log)
val compilerSettings = xsbt.MakeSettings(options, log)
if(!bootClasspathString.isEmpty)
compilerSettings.bootclasspath.value = bootClasspathString
compilerSettings.classpath.value = classpathString
log.info(Message("Starting scala interpreter..."))
log.debug(Message(" Boot classpath: " + compilerSettings.bootclasspath.value))
log.debug(Message(" Classpath: " + compilerSettings.classpath.value))
log.info(Message(""))
val loop = new InterpreterLoop {
override def createInterpreter() = {
if(loader ne null)
{
in = InteractiveReader.createDefault()
interpreter = new Interpreter(settings)
{
override protected def parentClassLoader = if(loader eq null) super.parentClassLoader else loader
override protected def newCompiler(settings: Settings, reporter: Reporter) = super.newCompiler(compilerSettings, reporter)
}
interpreter.setContextClassLoader()
}
else
super.createInterpreter()
for( (id, value) <- bindNames zip bindValues)
interpreter.bind(id, value.asInstanceOf[AnyRef].getClass.getName, value)
if(!initialCommands.isEmpty)
interpreter.interpret(initialCommands)
}
}
loop.main(if(loader eq null) compilerSettings else interpreterSettings)
}
}
object MakeSettings
{
def apply(args: List[String], log: Logger) =
{
val command = new GenericRunnerCommand(args, message => log.error(Message(message)))
if(command.ok)
command.settings
else
throw new InterfaceCompileFailed(Array(), Array(), command.usageMsg)
}
}