mirror of https://github.com/sbt/sbt.git
Added JavacLogger, for issue #68
- JavacLogger.msgs uses ListBuffer for constant time append - Synchronized access to JavacLogger.msgs since appends comes from multiple threads - JavacLogger.info uses Level.Info instead of Level.Debug - Wrapped call to javac in allCatch to guarantee logger being flushed
This commit is contained in:
parent
4921be04c8
commit
2f4be49cf6
|
|
@ -84,7 +84,14 @@ object Compiler
|
|||
val exec = javaHome match { case None => "javac"; case Some(jh) => (jh / "bin" / "javac").absolutePath }
|
||||
(args: Seq[String], log: Logger) => {
|
||||
log.debug("Forking javac: " + exec + " " + args.mkString(" "))
|
||||
Process(exec, args) ! log
|
||||
val javacLogger = new JavacLogger(log)
|
||||
var exitCode = -1
|
||||
try {
|
||||
exitCode = Process(exec, args) ! javacLogger
|
||||
} finally {
|
||||
javacLogger.flush(exitCode)
|
||||
}
|
||||
exitCode
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +100,34 @@ object Compiler
|
|||
import in.compilers._
|
||||
import in.config._
|
||||
import in.incSetup._
|
||||
|
||||
|
||||
val agg = new AggressiveCompile(cacheDirectory)
|
||||
agg(scalac, javac, sources, classpath, classesDirectory, options, javacOptions, analysisMap, maxErrors, order)(log)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private[sbt] class JavacLogger(log: Logger) extends ProcessLogger {
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import Level.{Info, Warn, Error, Value => LogLevel}
|
||||
|
||||
private val msgs: ListBuffer[(LogLevel, String)] = new ListBuffer()
|
||||
|
||||
def info(s: => String): Unit =
|
||||
synchronized { msgs += ((Info, s)) }
|
||||
|
||||
def error(s: => String): Unit =
|
||||
synchronized { msgs += ((Error, s)) }
|
||||
|
||||
def buffer[T](f: => T): T = f
|
||||
|
||||
private def print(desiredLevel: LogLevel)(t: (LogLevel, String)) = t match {
|
||||
case (Info, msg) => log.info(msg)
|
||||
case (Error, msg) => log.log(desiredLevel, msg)
|
||||
}
|
||||
|
||||
def flush(exitCode: Int): Unit = {
|
||||
val level = if (exitCode == 0) Warn else Error
|
||||
msgs foreach print(level)
|
||||
msgs.clear()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue