Permalink
Browse files

Forward log messages from Sbt to the sdt.core logger.

Made ClasspathManagement use a self-type.
  • Loading branch information...
1 parent 6602924 commit 3f3a3eba680603fe5bfd0d519aa51f071a5a5835 @dragos dragos committed May 25, 2012
@@ -54,20 +54,12 @@ object ScalaClasspath {
* JDK entries, Scala library entries, and user entries. It also validates the classpath and
* manages the classpath error markers for the given Scala project.
*/
-trait ClasspathManagement extends HasLogger {
-
- val scalaProject: ScalaProject
-
- /** Hook to reset compilers when the classpath has changed. */
- def resetCompilers(implicit monitor: IProgressMonitor = null): Unit
-
- private def javaProject: IJavaProject = scalaProject.javaProject
- private def underlying: IProject = scalaProject.underlying
+trait ClasspathManagement extends HasLogger { self: ScalaProject =>
/** Return the Scala classpath breakdown for the managed project. */
def scalaClasspath: ScalaClasspath = {
val jdkEntries = jdkPaths
- val cp = scalaProject.classpath.filterNot(jdkEntries.toSet)
+ val cp = classpath.filterNot(jdkEntries.toSet)
scalaPackageFragments match {
case Seq((pf, version), _*) => new ScalaClasspath(jdkEntries, Some(pf.getPath()), cp.filterNot(_ == pf.getPath), version)
@@ -62,7 +62,7 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
sources: Seq[File], reporter: Reporter, settings: Settings,
compOrder: CompileOrder.Value, compOptions: Seq[String] = Nil,
javaSrcBases: Seq[File] = Nil, javacOptions: Seq[String] = Nil,
- analysisMap: Map[File, Analysis] = Map.empty, maxErrors: Int = 100)(log: FlushableLogger): Analysis = {
+ analysisMap: Map[File, Analysis] = Map.empty, maxErrors: Int = 100)(log: sbt.Logger): Analysis = {
val currentSetup = new CompileSetup(conf.outputDirectory, new CompileOptions(compOptions, javacOptions),
scalac.scalaInstance.actualVersion, compOrder)
import currentSetup._
@@ -130,7 +130,6 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
logger.debug("Error running the SBT builder on Java sources:\n " + e)
logger.debug("Running a full Java build")
javac.build(org.eclipse.core.resources.IncrementalProjectBuilder.FULL_BUILD)
- log.flush()
}
try {
@@ -140,7 +139,6 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
sbt.classfile.Analyze(conf.outputDirectories, javaSrcs, log)(callback, loader, readAPI) {
javac.build(org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD)
- log.flush()
}
BuildManagerStore.INSTANCE.setJavaSourceFilesToCompile(null, conf.project.underlying)
@@ -194,8 +192,6 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
reporter.log(SbtConverter.convertToSbt(NoPosition), "The SBT builder crashed while compiling your project. This is a bug in the Scala compiler or SBT. Check the Erorr Log for details. The error message is: " + ex.getMessage(), xsbti.Severity.Error)
null
- } finally {
- log.flush()
}
}
@@ -1,60 +1,25 @@
package scala.tools.eclipse.buildmanager.sbtintegration
import scala.tools.eclipse.buildmanager.BuildReporter
-
import scala.tools.nsc.util.{ Position, NoPosition, FakePos }
import scala.collection.mutable
+import scala.tools.eclipse.logging.HasLogger
-trait FlushableLogger extends sbt.Logger {
- def flush(): Unit
-}
-
-/** An Sbt logger that publishes java errors to the underlying build reporter. */
-class SbtBuildLogger(underlying: BuildReporter) extends FlushableLogger {
- // This needs to be improved but works for most of the java errors
- val javaErrorBegin = ".*\\.java:(\\d+):.*".r
- val buff = mutable.ListBuffer[Tuple2[sbt.Level.Value, String]]()
+/** An Sbt logger that forwards to our logging infrastructure. */
+class SbtBuildLogger(underlying: BuildReporter) extends sbt.Logger with HasLogger {
def trace(t: => Throwable) {
- // ignore for now?
+ logger.debug("Exception during Sbt compilation", t)
}
- def success(message: => String) { }
+
+ def success(message: => String) { logger.info("success: " + message) }
+
def log(level: sbt.Level.Value, message: => String) {
- import sbt.Level.{Info, Warn, Error, Debug}
+ import sbt.Level.{ Info, Warn, Error, Debug }
level match {
- case Info => ()
- case Warn => buff += ((level, message)) //underlying.warning(NoPosition, message)
- case Error => buff += ((level, message)) //underlying.error(NoPosition, message)
- case Debug => ()
- }
- }
-
- // This will at least ensure that we print log in the order required by eclipse for java problems
- // This is a temporary solution until the parsing of java error/warning messages is done correctly
- def flush() {
- def publishMsg(level: sbt.Level.Value, msg: String) = {
- level match {
- case sbt.Level.Warn =>
- underlying.warning(NoPosition, msg)
- case sbt.Level.Error =>
- underlying.error(NoPosition, msg)
- }
+ case Info => logger.info(message)
+ case Warn => logger.warn(message)
+ case Error => logger.error(message)
+ case Debug => logger.debug(message)
}
- import scala.collection
- val localBuff = new mutable.ListBuffer[String]()
- val buff0 = buff.dropRight(1) // remove number of error message
- var lastLevel: sbt.Level.Value = null
- buff0.foreach(msg => {
- val res = msg._2 match { case javaErrorBegin(_) => true; case _ => false }
-
- if ((msg._1 != lastLevel || res) && !localBuff.isEmpty) {
- assert(lastLevel != null)
- publishMsg(lastLevel, localBuff.mkString("\n"))
- localBuff.clear()
- }
- lastLevel = msg._1
- localBuff.append(msg._2)
- })
- if (!localBuff.isEmpty)
- publishMsg(lastLevel, localBuff.mkString("\n"))
}
}

0 comments on commit 3f3a3eb

Please sign in to comment.