diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-04 22:28:31 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-04 22:28:31 -0800 |
commit | 9aed4601a04a48b3192d1871ff0ebb98fa352726 (patch) | |
tree | 2d5c01a5fc935a177da4087550d140e54d3ac14d /core/src | |
parent | 52f5a07a2b2b3f1885e83d09414aa3da385f4419 (diff) | |
download | mill-9aed4601a04a48b3192d1871ff0ebb98fa352726.tar.gz mill-9aed4601a04a48b3192d1871ff0ebb98fa352726.tar.bz2 mill-9aed4601a04a48b3192d1871ff0ebb98fa352726.zip |
Standardize on a `mill.util.Logger` class
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/scala/mill/Main.scala | 15 | ||||
-rw-r--r-- | core/src/main/scala/mill/eval/Evaluator.scala | 14 | ||||
-rw-r--r-- | core/src/main/scala/mill/modules/Jvm.scala | 8 | ||||
-rw-r--r-- | core/src/main/scala/mill/util/Ctx.scala | 4 | ||||
-rw-r--r-- | core/src/main/scala/mill/util/Logger.scala | 29 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/CacherTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/EvaluationTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/FailureTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/JavaCompileJarTests.scala | 10 |
9 files changed, 54 insertions, 38 deletions
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala index db7a6c1a..24cd7ed1 100644 --- a/core/src/main/scala/mill/Main.scala +++ b/core/src/main/scala/mill/Main.scala @@ -7,7 +7,7 @@ import ammonite.util.{Colors, Res} import mill.define.Task import mill.discover._ import mill.eval.{Evaluator, Result} -import mill.util.OSet +import mill.util.{Logger, OSet, PrintLogger} import ammonite.main.Scripts.pathScoptRead import ammonite.repl.Repl import mill.define.Task.TaskModule @@ -151,7 +151,7 @@ object Main { watch: Path => Unit, coloredOutput: Boolean): Int = { - val log = new Logger(coloredOutput) + val log = new PrintLogger(coloredOutput) val Seq(selectorString, rest @_*) = args @@ -163,7 +163,7 @@ object Main { case _ => Nil } target <- resolve(sel, disc.mirror, obj, rest, crossSelectors, Nil) - evaluator = new Evaluator(pwd / 'out, Discovered.mapping(obj)(disc), log.info) + evaluator = new Evaluator(pwd / 'out, Discovered.mapping(obj)(disc), log) _ <- evaluate(evaluator, target, watch).toLeft(()) } yield () @@ -231,17 +231,10 @@ object Main { } } -class Logger(coloredOutput: Boolean){ - val colors = - if(coloredOutput) Colors.Default - else Colors.BlackWhite - def info(s: String) = System.err.println(colors.info()(s)) - def error(s: String) = System.err.println(colors.error()(s)) -} class Main(config: Main.Config){ val coloredOutput = config.colored.getOrElse(ammonite.Main.isInteractive()) - val log = new Logger(coloredOutput) + val log = new PrintLogger(coloredOutput) def watchAndWait(watched: Seq[(Path, Long)]) = { diff --git a/core/src/main/scala/mill/eval/Evaluator.scala b/core/src/main/scala/mill/eval/Evaluator.scala index b769c025..619b1521 100644 --- a/core/src/main/scala/mill/eval/Evaluator.scala +++ b/core/src/main/scala/mill/eval/Evaluator.scala @@ -1,17 +1,20 @@ package mill.eval +import java.io.PrintStream + import ammonite.ops._ import ammonite.runtime.SpecialClassLoader import mill.define.{Graph, Target, Task} import mill.discover.Mirror import mill.discover.Mirror.LabelledTarget import mill.util -import mill.util.{Ctx, MultiBiMap, OSet} +import mill.util._ + import scala.collection.mutable class Evaluator(workspacePath: Path, labeling: Map[Target[_], LabelledTarget[_]], - log: String => Unit){ + log: Logger){ def evaluate(goals: OSet[Task[_]]): Evaluator.Results = { mkdir(workspacePath) @@ -133,8 +136,7 @@ class Evaluator(workspacePath: Path, def evaluateGroup(group: OSet[Task[_]], results: collection.Map[Task[_], Result[Any]], targetDestPath: Option[Path], - maybeTargetLabel: Option[String] - ) = { + maybeTargetLabel: Option[String]) = { val newEvaluated = mutable.Buffer.empty[Task[_]] @@ -150,7 +152,7 @@ class Evaluator(workspacePath: Path, val logRun = inputResults.forall(_.isInstanceOf[Result.Success[_]]) - if(logRun) { log("Running " + targetLabel) } + if(logRun) { log.info("Running " + targetLabel) } } for (target <- nonEvaluatedTargets) { @@ -166,7 +168,7 @@ class Evaluator(workspacePath: Path, val args = new Ctx( targetInputValues.toArray[Any], targetDestPath.orNull, - System.out + log ) target.evaluate(args) } diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala index a2277e36..a0f586c3 100644 --- a/core/src/main/scala/mill/modules/Jvm.scala +++ b/core/src/main/scala/mill/modules/Jvm.scala @@ -130,12 +130,4 @@ object Jvm { PathRef(outputPath) } - def jarUp(roots: Task[PathRef]*) = new Task[PathRef]{ - - val inputs = roots - def evaluate(args: Ctx) = { - createJar(args.dest, args.args.map(_.asInstanceOf[PathRef].path)) - PathRef(args.dest) - } - } } diff --git a/core/src/main/scala/mill/util/Ctx.scala b/core/src/main/scala/mill/util/Ctx.scala index f583feaf..7a0a5694 100644 --- a/core/src/main/scala/mill/util/Ctx.scala +++ b/core/src/main/scala/mill/util/Ctx.scala @@ -17,7 +17,7 @@ object Ctx{ def dest: Path } trait LogCtx{ - def log: PrintStream + def log: Logger } trait ArgCtx{ def args: IndexedSeq[_] @@ -25,7 +25,7 @@ object Ctx{ } class Ctx(val args: IndexedSeq[_], val dest: Path, - val log: PrintStream) extends DestCtx with LogCtx with ArgCtx{ + val log: Logger) extends DestCtx with LogCtx with ArgCtx{ def length = args.length def apply[T](index: Int): T = { if (index >= 0 && index < args.length) args(index).asInstanceOf[T] diff --git a/core/src/main/scala/mill/util/Logger.scala b/core/src/main/scala/mill/util/Logger.scala new file mode 100644 index 00000000..d998a601 --- /dev/null +++ b/core/src/main/scala/mill/util/Logger.scala @@ -0,0 +1,29 @@ +package mill.util + +import java.io.{OutputStream, PrintStream} + +import ammonite.util.Colors + + +trait Logger{ + val outputStream: PrintStream + def info(s: String): Unit + def error(s: String): Unit +} + +object DummyLogger extends Logger{ + val outputStream = new PrintStream(new OutputStream { + def write(b: Int) = () + }) + def info(s: String) = () + def error(s: String) = () +} +class PrintLogger(coloredOutput: Boolean) extends Logger{ + val outputStream = System.err + val colors = + if(coloredOutput) Colors.Default + else Colors.BlackWhite + + def info(s: String) = System.err.println(colors.info()(s)) + def error(s: String) = System.err.println(colors.error()(s)) +}
\ No newline at end of file diff --git a/core/src/test/scala/mill/define/CacherTests.scala b/core/src/test/scala/mill/define/CacherTests.scala index bb86ae65..bacfa598 100644 --- a/core/src/test/scala/mill/define/CacherTests.scala +++ b/core/src/test/scala/mill/define/CacherTests.scala @@ -2,7 +2,7 @@ package mill.define import mill.discover.Discovered import mill.eval.Evaluator -import mill.util.OSet +import mill.util.{DummyLogger, OSet} import mill.T import utest._ import utest.framework.TestPath @@ -27,7 +27,7 @@ object CacherTests extends TestSuite{ def eval[T: Discovered, V](base: T, v: Task[V])(implicit tp: TestPath) = { val workspace = ammonite.ops.pwd / 'target / 'workspace / tp.value - val evaluator = new Evaluator(workspace, Discovered.mapping(base), _ => ()) + val evaluator = new Evaluator(workspace, Discovered.mapping(base), DummyLogger) evaluator.evaluate(OSet(v)).values(0) } diff --git a/core/src/test/scala/mill/eval/EvaluationTests.scala b/core/src/test/scala/mill/eval/EvaluationTests.scala index d3c1861f..3b136ba0 100644 --- a/core/src/test/scala/mill/eval/EvaluationTests.scala +++ b/core/src/test/scala/mill/eval/EvaluationTests.scala @@ -5,7 +5,7 @@ import mill.util.TestUtil.{Test, test} import mill.define.{Graph, Target, Task} import mill.{Module, T} import mill.discover.Discovered -import mill.util.{OSet, TestGraphs, TestUtil} +import mill.util.{DummyLogger, OSet, TestGraphs, TestUtil} import utest._ import utest.framework.TestPath @@ -14,7 +14,7 @@ object EvaluationTests extends TestSuite{ val workspace = ammonite.ops.pwd / 'target / 'workspace / tp.value ammonite.ops.rm(ammonite.ops.Path(workspace, ammonite.ops.pwd)) // Make sure data is persisted even if we re-create the evaluator each time - def evaluator = new Evaluator(workspace, Discovered.mapping(base), _ => ()) + def evaluator = new Evaluator(workspace, Discovered.mapping(base), DummyLogger) def apply(target: Task[_], expValue: Any, expEvaled: OSet[Task[_]], diff --git a/core/src/test/scala/mill/eval/FailureTests.scala b/core/src/test/scala/mill/eval/FailureTests.scala index 6977334d..2279d931 100644 --- a/core/src/test/scala/mill/eval/FailureTests.scala +++ b/core/src/test/scala/mill/eval/FailureTests.scala @@ -2,7 +2,7 @@ package mill.eval import mill.define.Target import mill.discover.Discovered -import mill.util.OSet +import mill.util.{DummyLogger, OSet} import utest._ import utest.framework.TestPath @@ -17,7 +17,7 @@ object FailureTests extends TestSuite{ def check[T: Discovered](base: T) (target: T => Target[_], expectedFailCount: Int, expectedRawValues: Seq[Result[_]]) (implicit tp: TestPath) = { - val evaluator = new Evaluator(workspace, Discovered.mapping(base), _ => ()) + val evaluator = new Evaluator(workspace, Discovered.mapping(base), DummyLogger) val res = evaluator.evaluate(OSet(target(base))) assert( res.rawValues == expectedRawValues, diff --git a/core/src/test/scala/mill/eval/JavaCompileJarTests.scala b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala index 6c32f9b8..e0a43c6e 100644 --- a/core/src/test/scala/mill/eval/JavaCompileJarTests.scala +++ b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala @@ -4,10 +4,10 @@ import ammonite.ops.ImplicitWd._ import ammonite.ops._ import mill.define.{Target, Task} import mill.discover.Discovered -import mill.modules.Jvm.jarUp +import mill.modules.Jvm import mill.util.Ctx.DestCtx import mill.{Module, T} -import mill.util.OSet +import mill.util.{DummyLogger, OSet} import utest._ object JavaCompileJarTests extends TestSuite{ @@ -39,7 +39,7 @@ object JavaCompileJarTests extends TestSuite{ def resourceRoot = T.source{ resourceRootPath } def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } - def jar = T{ jarUp(resourceRoot, classFiles) } + def jar = T{ Jvm.createJar(Seq(resourceRoot().path, classFiles().path)) } def run(mainClsName: String) = T.command{ %%('java, "-cp", classFiles().path, mainClsName) @@ -50,7 +50,7 @@ object JavaCompileJarTests extends TestSuite{ val mapping = Discovered.mapping(Build) def eval[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { - val evaluator = new Evaluator(workspacePath, mapping, _ => ()) + val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) val evaluated = evaluator.evaluate(OSet(t)) if (evaluated.failing.keyCount == 0){ @@ -67,7 +67,7 @@ object JavaCompileJarTests extends TestSuite{ } def check(targets: OSet[Task[_]], expected: OSet[Task[_]]) = { - val evaluator = new Evaluator(workspacePath, mapping, _ => ()) + val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) val evaluated = evaluator.evaluate(targets) .evaluated |