Skip to content
Browse files

Merge pull request #74 from duboisf/issue_68

Added JavacLogger, closes #68
  • Loading branch information...
2 parents e73ebda + 2f4be49 commit 48940bf23c0fcda96247c8036b26bbdcbff6ce97 @harrah committed
Showing with 36 additions and 3 deletions.
  1. +36 −3 main/actions/Compiler.scala
View
39 main/actions/Compiler.scala
@@ -86,7 +86,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
}
}
@@ -95,8 +102,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, definesClass, 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()
+ }
+}

0 comments on commit 48940bf

Please sign in to comment.
Something went wrong with that request. Please try again.