diff --git a/compile/inc/Analysis.scala b/compile/inc/Analysis.scala index 795358888..8bf2f95e6 100644 --- a/compile/inc/Analysis.scala +++ b/compile/inc/Analysis.scala @@ -6,6 +6,7 @@ package inc import xsbti.api.Source import java.io.File +import sbt.Util.counted trait Analysis { @@ -20,12 +21,28 @@ trait Analysis def addSource(src: File, api: Source, stamp: Stamp, internalDeps: Iterable[File]): Analysis def addBinaryDep(src: File, dep: File, className: String, stamp: Stamp): Analysis def addExternalDep(src: File, dep: String, api: Source): Analysis - def addProduct(src: File, product: File, stamp: Stamp): Analysis + def addProduct(src: File, product: File, stamp: Stamp): Analysis + + override lazy val toString = Analysis.summary(this) } object Analysis { lazy val Empty: Analysis = new MAnalysis(Stamps.empty, APIs.empty, Relations.empty) + def summary(a: Analysis): String = + { + val (j, s) = a.apis.allInternalSources.partition(_.getName.endsWith(".java")) + val c = a.stamps.allProducts + val ext = a.apis.allExternals + val jars = a.relations.allBinaryDeps.filter(_.getName.endsWith(".jar")) + val sections = + counted("Scala source", "", "s", s.size) ++ + counted("Java source", "", "s", j.size) ++ + counted("class", "", "es", c.size) ++ + counted("external source dependenc", "y", "ies", ext.size) ++ + counted("binary dependenc", "y", "ies", jars.size) + sections.mkString("Analysis: ", ", ", "") + } } private class MAnalysis(val stamps: Stamps, val apis: APIs, val relations: Relations) extends Analysis { diff --git a/compile/interface/API.scala b/compile/interface/API.scala index 3991316c4..8226cb064 100644 --- a/compile/interface/API.scala +++ b/compile/interface/API.scala @@ -24,6 +24,7 @@ final class API(val global: Global, val callback: xsbti.AnalysisCallback) extend { import global._ def error(msg: String) = throw new RuntimeException(msg) + def debug(msg: String) = if(settings.verbose.value) inform(msg) def newPhase(prev: Phase) = new ApiPhase(prev) class ApiPhase(prev: Phase) extends Phase(prev) @@ -35,13 +36,13 @@ final class API(val global: Global, val callback: xsbti.AnalysisCallback) extend val start = System.currentTimeMillis currentRun.units.foreach(processUnit) val stop = System.currentTimeMillis - println("API phase took : " + ((stop - start)/1000.0) + " s") + debug("API phase took : " + ((stop - start)/1000.0) + " s") } def processUnit(unit: CompilationUnit) = if(!unit.isJava) processScalaUnit(unit) def processScalaUnit(unit: CompilationUnit) { val sourceFile = unit.source.file.file - println("Traversing " + sourceFile) + debug("Traversing " + sourceFile) val traverser = new TopLevelHandler(sourceFile) traverser.apply(unit.body) val packages = traverser.packages.toArray[String].map(p => new xsbti.api.Package(p)) diff --git a/main/Command.scala b/main/Command.scala index 6c1eb9c16..c8e7188fe 100644 --- a/main/Command.scala +++ b/main/Command.scala @@ -68,7 +68,7 @@ object Command state => (simpleParser(simple)(state) /: arbs.map(_ parser state) ){ _ | _ } } private[this] def separateCommands(cmds: Seq[Command]): (Seq[SimpleCommand], Seq[ArbitraryCommand]) = - Collections.separate(cmds){ case s: SimpleCommand => Left(s); case a: ArbitraryCommand => Right(a) } + Util.separate(cmds){ case s: SimpleCommand => Left(s); case a: ArbitraryCommand => Right(a) } private[this] def apply1[A,B,C](f: (A,B) => C, a: A): B => () => C = b => () => f(a,b) diff --git a/main/actions/AggressiveCompile.scala b/main/actions/AggressiveCompile.scala index 77592e007..0f1b311f6 100644 --- a/main/actions/AggressiveCompile.scala +++ b/main/actions/AggressiveCompile.scala @@ -57,7 +57,7 @@ class AggressiveCompile(cacheDirectory: File) IO.createDirectory(outputDirectory) val incSrc = sources.filter(include) val (javaSrcs, scalaSrcs) = incSrc partition javaOnly - println("Compiling:\n\t" + incSrc.mkString("\n\t")) + logInputs(log, javaSrcs.size, scalaSrcs.size) def compileScala() = if(!scalaSrcs.isEmpty) { @@ -85,6 +85,14 @@ class AggressiveCompile(cacheDirectory: File) } IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory) } + private[this] def logInputs(log: Logger, javaCount: Int, scalaCount: Int) + { + val scalaMsg = Util.counted("Scala source", "", "s", scalaCount) + val javaMsg = Util.counted("Java source", "", "s", javaCount) + val combined = scalaMsg ++ javaMsg + if(!combined.isEmpty) + log.info(combined.mkString("Compiling ", " and ", "...")) + } private def extract(previous: Option[(Analysis, CompileSetup)]): (Analysis, Option[CompileSetup]) = previous match { diff --git a/util/collection/Util.scala b/util/collection/Util.scala index a3bf330aa..cceb1ec99 100644 --- a/util/collection/Util.scala +++ b/util/collection/Util.scala @@ -3,7 +3,7 @@ */ package sbt -object Collections +object Util { def separate[T,A,B](ps: Seq[T])(f: T => Either[A,B]): (Seq[A], Seq[B]) = ((Nil: Seq[A], Nil: Seq[B]) /: ps)( (xs, y) => prependEither(xs, f(y)) ) @@ -14,4 +14,11 @@ object Collections case Left(l) => (l +: acc._1, acc._2) case Right(r) => (acc._1, r +: acc._2) } + def counted(prefix: String, single: String, plural: String, count: Int): Option[String] = + count match + { + case 0 => None + case 1 => Some("1 " + prefix + single) + case x => Some(x.toString + " " + prefix + plural) + } } \ No newline at end of file diff --git a/util/complete/Parser.scala b/util/complete/Parser.scala index 45067043b..6eb9c135b 100644 --- a/util/complete/Parser.scala +++ b/util/complete/Parser.scala @@ -5,7 +5,7 @@ package sbt.complete import Parser._ import sbt.Types.{left, right, some} - import sbt.Collections.separate + import sbt.Util.separate sealed trait Parser[+T] {