From bc9dc386625021fec517f2dbf0644ccafe1e32c2 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 5 Nov 2018 03:00:04 +0800 Subject: WIP migrating over from `ammonite.ops` to `os` module. __.compile works, haven't run tests yet --- main/core/src/mill/define/BaseModule.scala | 3 +- main/core/src/mill/define/Ctx.scala | 6 +- main/core/src/mill/define/Module.scala | 3 +- main/core/src/mill/define/Task.scala | 4 +- main/core/src/mill/eval/Evaluator.scala | 50 ++++---- main/core/src/mill/eval/PathRef.scala | 37 ++---- main/core/src/mill/util/ClassLoader.scala | 2 +- main/core/src/mill/util/Ctx.scala | 11 +- main/core/src/mill/util/JsonFormatters.scala | 15 ++- main/core/src/mill/util/Logger.scala | 7 +- main/core/src/mill/util/Scripts.scala | 14 +-- .../src/mill/main/graphviz/GraphvizTools.scala | 3 +- main/src/mill/MillMain.scala | 7 +- main/src/mill/main/MainModule.scala | 7 +- main/src/mill/main/MainRunner.scala | 9 +- main/src/mill/main/ReplApplyHandler.scala | 3 +- main/src/mill/main/RunScript.scala | 19 ++- main/src/mill/main/VisualizeModule.scala | 5 +- main/src/mill/modules/Assembly.scala | 17 ++- main/src/mill/modules/Jvm.scala | 131 ++++++++++----------- main/src/mill/modules/Util.scala | 21 ++-- .../resources/examples/foreign/conflict/build.sc | 3 +- .../examples/foreign/conflict/inner/build.sc | 3 +- .../test/resources/examples/foreign/outer/build.sc | 3 +- .../examples/foreign/outer/inner/build.sc | 3 +- .../resources/examples/foreign/project/build.sc | 33 +++--- .../examples/foreign/project/inner/build.sc | 3 +- main/test/resources/examples/javac/build.sc | 5 +- main/test/src/mill/UTestFramework.scala | 4 +- main/test/src/mill/define/BasePathTests.scala | 9 +- main/test/src/mill/define/CacherTests.scala | 1 - main/test/src/mill/eval/CrossTests.scala | 2 +- main/test/src/mill/eval/EvaluationTests.scala | 2 +- main/test/src/mill/eval/FailureTests.scala | 1 - main/test/src/mill/eval/JavaCompileJarTests.scala | 35 +++--- main/test/src/mill/eval/ModuleTests.scala | 10 +- main/test/src/mill/eval/TaskTests.scala | 14 +-- main/test/src/mill/main/ClientServerTests.scala | 5 +- main/test/src/mill/main/ForeignBuildsTest.scala | 5 +- main/test/src/mill/main/ForeignConflictTest.scala | 6 +- main/test/src/mill/main/JavaCompileJarTests.scala | 15 ++- main/test/src/mill/util/ScriptTestSuite.scala | 19 ++- main/test/src/mill/util/TestEvaluator.scala | 3 +- main/test/src/mill/util/TestUtil.scala | 9 +- 44 files changed, 260 insertions(+), 307 deletions(-) (limited to 'main') diff --git a/main/core/src/mill/define/BaseModule.scala b/main/core/src/mill/define/BaseModule.scala index 03bdeccc..cd79f73e 100644 --- a/main/core/src/mill/define/BaseModule.scala +++ b/main/core/src/mill/define/BaseModule.scala @@ -1,12 +1,11 @@ package mill.define -import ammonite.ops.Path object BaseModule{ case class Implicit(value: BaseModule) } -abstract class BaseModule(millSourcePath0: Path, +abstract class BaseModule(millSourcePath0: os.Path, external0: Boolean = false, foreign0 : Boolean = false) (implicit millModuleEnclosing0: sourcecode.Enclosing, diff --git a/main/core/src/mill/define/Ctx.scala b/main/core/src/mill/define/Ctx.scala index ba4fae9e..c21e53b4 100644 --- a/main/core/src/mill/define/Ctx.scala +++ b/main/core/src/mill/define/Ctx.scala @@ -1,8 +1,6 @@ package mill.define -import ammonite.ops.Path - import scala.annotation.implicitNotFound sealed trait Segment{ @@ -18,7 +16,7 @@ object Segment{ case class Cross(value: Seq[Any]) extends Segment } -case class BasePath(value: Path) +case class BasePath(value: os.Path) /** @@ -64,7 +62,7 @@ object Segments { case class Ctx(enclosing: String, lineNum: Int, segment: Segment, - millSourcePath: Path, + millSourcePath: os.Path, segments: Segments, overrides: Int, external: Boolean, diff --git a/main/core/src/mill/define/Module.scala b/main/core/src/mill/define/Module.scala index f72ec8ca..a8fc5be7 100644 --- a/main/core/src/mill/define/Module.scala +++ b/main/core/src/mill/define/Module.scala @@ -2,7 +2,6 @@ package mill.define import java.lang.reflect.Modifier -import ammonite.ops.Path import mill.util.ParseArgs import scala.language.experimental.macros @@ -27,7 +26,7 @@ class Module(implicit outerCtx0: mill.define.Ctx) lazy val millModuleDirectChildren = millInternal.reflectNestedObjects[Module].toSeq def millOuterCtx = outerCtx0 - def millSourcePath: Path = millOuterCtx.millSourcePath / millOuterCtx.segment.pathSegments + def millSourcePath: os.Path = millOuterCtx.millSourcePath / millOuterCtx.segment.pathSegments implicit def millModuleExternal: Ctx.External = Ctx.External(millOuterCtx.external) implicit def millModuleShared: Ctx.Foreign = Ctx.Foreign(millOuterCtx.foreign) implicit def millModuleBasePath: BasePath = BasePath(millSourcePath) diff --git a/main/core/src/mill/define/Task.scala b/main/core/src/mill/define/Task.scala index 64e868f8..07576724 100644 --- a/main/core/src/mill/define/Task.scala +++ b/main/core/src/mill/define/Task.scala @@ -109,11 +109,11 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul ) } - def sources(values: Result[ammonite.ops.Path]*) + def sources(values: Result[os.Path]*) (implicit ctx: mill.define.Ctx): Sources = macro sourcesImpl1 def sourcesImpl1(c: Context) - (values: c.Expr[Result[ammonite.ops.Path]]*) + (values: c.Expr[Result[os.Path]]*) (ctx: c.Expr[mill.define.Ctx]): c.Expr[Sources] = { import c.universe._ val wrapped = diff --git a/main/core/src/mill/eval/Evaluator.scala b/main/core/src/mill/eval/Evaluator.scala index 2ffc469b..7cf55fdb 100644 --- a/main/core/src/mill/eval/Evaluator.scala +++ b/main/core/src/mill/eval/Evaluator.scala @@ -5,7 +5,6 @@ import java.net.URLClassLoader import scala.collection.JavaConverters._ import mill.util.Router.EntryPoint -import ammonite.ops._ import ammonite.runtime.SpecialClassLoader import mill.define.{Ctx => _, _} import mill.eval.Result.OuterStack @@ -29,17 +28,17 @@ case class Labelled[T](task: NamedTask[T], } } -case class Evaluator(home: Path, - outPath: Path, - externalOutPath: Path, +case class Evaluator(home: os.Path, + outPath: os.Path, + externalOutPath: os.Path, rootModule: mill.define.BaseModule, log: Logger, - classLoaderSig: Seq[(Either[String, Path], Long)] = Evaluator.classLoaderSig, + classLoaderSig: Seq[(Either[String, os.Path], Long)] = Evaluator.classLoaderSig, workerCache: mutable.Map[Segments, (Int, Any)] = mutable.Map.empty, env : Map[String, String] = Evaluator.defaultEnv){ val classLoaderSignHash = classLoaderSig.hashCode() def evaluate(goals: Agg[Task[_]]): Evaluator.Results = { - mkdir(outPath) + os.makeDir.all(outPath) val (sortedGroups, transitive) = Evaluator.plan(rootModule, goals) @@ -76,7 +75,7 @@ case class Evaluator(home: Path, vs.items.flatMap(results.get).collect{case f: Result.Failing[_] => f.map(_._1)} ) } - write.over( + os.write.over( outPath / "mill-profile.json", upickle.default.write( timings .map{case (k, v, b) => @@ -133,7 +132,7 @@ case class Evaluator(home: Path, destSegments(labelledNamedTask) ) - if (!exists(paths.out)) mkdir(paths.out) + if (!os.exists(paths.out)) os.makeDir.all(paths.out) val cached = for{ cached <- try Some(upickle.default.read[Evaluator.Cached](paths.meta.toIO)) @@ -158,14 +157,13 @@ case class Evaluator(home: Path, (newResults, Nil, true) case _ => - val Seq(first, rest @_*) = labelledNamedTask.segments.value val msgParts = Seq(first.asInstanceOf[Segment.Label].value) ++ rest.map{ case Segment.Label(s) => "." + s case Segment.Cross(s) => "[" + s.mkString(",") + "]" } - if (labelledNamedTask.task.flushDest) rm(paths.dest) + if (labelledNamedTask.task.flushDest) os.remove.all(paths.dest) val (newResults, newEvaluated) = evaluateGroup( group, @@ -188,7 +186,7 @@ case class Evaluator(home: Path, // a following run won't look at the cached metadata file and // assume it's associated with the possibly-borked state of the // destPath after an evaluation failure. - rm(paths.meta) + os.remove.all(paths.meta) } (newResults, newEvaluated, false) @@ -218,7 +216,7 @@ case class Evaluator(home: Path, def handleTaskResult(v: Any, hashCode: Int, - metaPath: Path, + metaPath: os.Path, inputsHash: Int, labelledNamedTask: Labelled[_]) = { labelledNamedTask.task.asWorker match{ @@ -230,7 +228,7 @@ case class Evaluator(home: Path, .map(w => upickle.default.writeJs(v)(w) -> v) for((json, v) <- terminalResult){ - write.over( + os.write.over( metaPath, upickle.default.write( Evaluator.Cached(json, hashCode, inputsHash), @@ -270,7 +268,13 @@ case class Evaluator(home: Path, for (task <- nonEvaluatedTargets) { newEvaluated.append(task) val targetInputValues = task.inputs - .map(x => newResults.getOrElse(x, results(x))) + .map{x => + val res = newResults.getOrElse(x, results(x)) + if (!res.isInstanceOf[Result.Success[_]]){ + println("FAILURE " + x) + } + res + } .collect{ case Result.Success((v, hashCode)) => v } val res = @@ -291,7 +295,7 @@ case class Evaluator(home: Path, paths match{ case Some(dest) => - if (usedDest.isEmpty) mkdir(dest.dest) + if (usedDest.isEmpty) os.makeDir.all(dest.dest) usedDest = Some((task, new Exception().getStackTrace)) dest.dest case None => @@ -340,7 +344,7 @@ case class Evaluator(home: Path, (newResults, newEvaluated) } - def resolveLogger(logPath: Option[Path]): Logger = logPath match{ + def resolveLogger(logPath: Option[os.Path]): Logger = logPath match{ case None => log case Some(path) => MultiLogger(log.colored, log, FileLogger(log.colored, path, debugEnabled = true)) } @@ -355,9 +359,9 @@ object Evaluator{ implicit val rw: upickle.default.ReadWriter[Cached] = upickle.default.macroRW } case class State(rootModule: mill.define.BaseModule, - classLoaderSig: Seq[(Either[String, Path], Long)], + classLoaderSig: Seq[(Either[String, os.Path], Long)], workerCache: mutable.Map[Segments, (Int, Any)], - watched: Seq[(Path, Long)]) + watched: Seq[(os.Path, Long)]) // This needs to be a ThreadLocal because we need to pass it into the body of // the TargetScopt#read call, which does not accept additional parameters. // Until we migrate our CLI parsing off of Scopt (so we can pass the BaseModule @@ -366,15 +370,15 @@ object Evaluator{ val defaultEnv: Map[String, String] = System.getenv().asScala.toMap - case class Paths(out: Path, - dest: Path, - meta: Path, - log: Path) + case class Paths(out: os.Path, + dest: os.Path, + meta: os.Path, + log: os.Path) def makeSegmentStrings(segments: Segments) = segments.value.flatMap{ case Segment.Label(s) => Seq(s) case Segment.Cross(values) => values.map(_.toString) } - def resolveDestPaths(workspacePath: Path, segments: Segments): Paths = { + def resolveDestPaths(workspacePath: os.Path, segments: Segments): Paths = { val segmentStrings = makeSegmentStrings(segments) val targetPath = workspacePath / segmentStrings Paths(targetPath, targetPath / 'dest, targetPath / "meta.json", targetPath / 'log) diff --git a/main/core/src/mill/eval/PathRef.scala b/main/core/src/mill/eval/PathRef.scala index 4983f040..92ef8d24 100644 --- a/main/core/src/mill/eval/PathRef.scala +++ b/main/core/src/mill/eval/PathRef.scala @@ -7,54 +7,41 @@ import java.nio.{file => jnio} import java.security.{DigestOutputStream, MessageDigest} import upickle.default.{ReadWriter => RW} -import ammonite.ops.Path import mill.util.{DummyOutputStream, IO, JsonFormatters} /** - * A wrapper around `ammonite.ops.Path` that calculates it's hashcode based + * A wrapper around `os.Path` that calculates it's hashcode based * on the contents of the filesystem underneath it. Used to ensure filesystem * changes can bust caches which are keyed off hashcodes. */ -case class PathRef(path: ammonite.ops.Path, quick: Boolean, sig: Int){ +case class PathRef(path: os.Path, quick: Boolean, sig: Int){ override def hashCode() = sig } object PathRef{ - def apply(path: ammonite.ops.Path, quick: Boolean = false) = { + def apply(path: os.Path, quick: Boolean = false) = { val sig = { val digest = MessageDigest.getInstance("MD5") val digestOut = new DigestOutputStream(DummyOutputStream, digest) - jnio.Files.walkFileTree( - path.toNIO, - java.util.EnumSet.of(jnio.FileVisitOption.FOLLOW_LINKS), - Integer.MAX_VALUE, - new FileVisitor[jnio.Path] { - def preVisitDirectory(dir: jnio.Path, attrs: BasicFileAttributes) = { - digest.update(dir.toAbsolutePath.toString.getBytes) - FileVisitResult.CONTINUE - } - - def visitFile(file: jnio.Path, attrs: BasicFileAttributes) = { - digest.update(file.toAbsolutePath.toString.getBytes) + if (os.exists(path)){ + for((path, attrs) <- os.walk.attrs(path, includeTarget = true, followLinks = true)){ + digest.update(path.toString.getBytes) + if (!attrs.isDir) { if (quick){ - val value = (path.mtime.toMillis, path.size).hashCode() + val value = (attrs.mtime, attrs.size).hashCode() digest.update((value >>> 24).toByte) digest.update((value >>> 16).toByte) digest.update((value >>> 8).toByte) digest.update(value.toByte) - } else if (jnio.Files.isReadable(file)) { - val is = jnio.Files.newInputStream(file) + } else if (jnio.Files.isReadable(path.toNIO)) { + val is = os.read.inputStream(path) IO.stream(is, digestOut) is.close() } - FileVisitResult.CONTINUE } - - def visitFileFailed(file: jnio.Path, exc: IOException) = FileVisitResult.CONTINUE - def postVisitDirectory(dir: jnio.Path, exc: IOException) = FileVisitResult.CONTINUE } - ) + } java.util.Arrays.hashCode(digest.digest()) @@ -71,7 +58,7 @@ object PathRef{ s => { val Array(prefix, hex, path) = s.split(":", 3) PathRef( - Path(path), + os.Path(path), prefix match{ case "qref" => true case "ref" => false}, // Parsing to a long and casting to an int is the only way to make // round-trip handling of negative numbers work =( diff --git a/main/core/src/mill/util/ClassLoader.scala b/main/core/src/mill/util/ClassLoader.scala index ebe8e50b..07ab1ca9 100644 --- a/main/core/src/mill/util/ClassLoader.scala +++ b/main/core/src/mill/util/ClassLoader.scala @@ -2,7 +2,7 @@ package mill.util import java.net.{URL, URLClassLoader} -import ammonite.ops._ + import io.github.retronym.java9rtexport.Export import scala.util.Try diff --git a/main/core/src/mill/util/Ctx.scala b/main/core/src/mill/util/Ctx.scala index 6c8b2afb..bbc243b7 100644 --- a/main/core/src/mill/util/Ctx.scala +++ b/main/core/src/mill/util/Ctx.scala @@ -1,6 +1,5 @@ package mill.util -import ammonite.ops.Path import mill.define.Applicative.ImplicitStub import scala.annotation.compileTimeOnly @@ -12,16 +11,16 @@ object Ctx{ implicit def taskCtx: Ctx = ??? object Dest { - implicit def pathToCtx(path: Path): Dest = new Dest { def dest = path } + implicit def pathToCtx(path: os.Path): Dest = new Dest { def dest = path } } trait Dest{ - def dest: Path + def dest: os.Path } trait Log{ def log: Logger } trait Home{ - def home: Path + def home: os.Path } trait Env{ def env: Map[String, String] @@ -37,9 +36,9 @@ object Ctx{ } class Ctx(val args: IndexedSeq[_], - dest0: () => Path, + dest0: () => os.Path, val log: Logger, - val home: Path, + val home: os.Path, val env : Map[String, String]) extends Ctx.Dest with Ctx.Log diff --git a/main/core/src/mill/util/JsonFormatters.scala b/main/core/src/mill/util/JsonFormatters.scala index 2728d94d..e2c3073f 100644 --- a/main/core/src/mill/util/JsonFormatters.scala +++ b/main/core/src/mill/util/JsonFormatters.scala @@ -1,15 +1,14 @@ package mill.util -import ammonite.ops.{Bytes, Path} import upickle.Js import upickle.default.{ReadWriter => RW} import scala.util.matching.Regex object JsonFormatters extends JsonFormatters trait JsonFormatters { - implicit val pathReadWrite: RW[ammonite.ops.Path] = upickle.default.readwriter[String] - .bimap[ammonite.ops.Path]( + implicit val pathReadWrite: RW[os.Path] = upickle.default.readwriter[String] + .bimap[os.Path]( _.toString, - Path(_) + os.Path(_) ) implicit val regexReadWrite: RW[Regex] = upickle.default.readwriter[String] @@ -18,14 +17,14 @@ trait JsonFormatters { _.r ) - implicit val bytesReadWrite: RW[Bytes] = upickle.default.readwriter[String] + implicit val bytesReadWrite: RW[os.Bytes] = upickle.default.readwriter[String] .bimap( - o => javax.xml.bind.DatatypeConverter.printBase64Binary(o.array), - str => new Bytes(javax.xml.bind.DatatypeConverter.parseBase64Binary(str)) + o => java.util.Base64.getEncoder.encodeToString(o.array), + str => new os.Bytes(java.util.Base64.getDecoder.decode(str)) ) - implicit lazy val crFormat: RW[ammonite.ops.CommandResult] = upickle.default.macroRW + implicit lazy val crFormat: RW[os.CommandResult] = upickle.default.macroRW implicit lazy val modFormat: RW[coursier.Module] = upickle.default.macroRW implicit lazy val depFormat: RW[coursier.Dependency]= upickle.default.macroRW diff --git a/main/core/src/mill/util/Logger.scala b/main/core/src/mill/util/Logger.scala index 1db66039..4857953d 100644 --- a/main/core/src/mill/util/Logger.scala +++ b/main/core/src/mill/util/Logger.scala @@ -2,7 +2,6 @@ package mill.util import java.io._ -import ammonite.ops.{Path, rm} import ammonite.util.Colors /** @@ -142,17 +141,17 @@ case class PrintLogger( } } -case class FileLogger(colored: Boolean, file: Path, debugEnabled: Boolean) extends Logger { +case class FileLogger(colored: Boolean, file: os.Path, debugEnabled: Boolean) extends Logger { private[this] var outputStreamUsed: Boolean = false lazy val outputStream = { - if (!outputStreamUsed) rm(file) + if (!outputStreamUsed) os.remove.all(file) outputStreamUsed = true new PrintStream(new FileOutputStream(file.toIO.getAbsolutePath)) } lazy val errorStream = { - if (!outputStreamUsed) rm(file) + if (!outputStreamUsed) os.remove.all(file) outputStreamUsed = true new PrintStream(new FileOutputStream(file.toIO.getAbsolutePath)) } diff --git a/main/core/src/mill/util/Scripts.scala b/main/core/src/mill/util/Scripts.scala index 1815b6de..65eb6b2b 100644 --- a/main/core/src/mill/util/Scripts.scala +++ b/main/core/src/mill/util/Scripts.scala @@ -2,7 +2,7 @@ package mill.util import java.nio.file.NoSuchFileException -import ammonite.ops._ + import ammonite.runtime.Evaluator.AmmoniteExit import ammonite.util.Name.backtickWrap import ammonite.util.Util.CodeSource @@ -31,15 +31,15 @@ object Scripts { scriptArgs } - def runScript(wd: Path, - path: Path, + def runScript(wd: os.Path, + path: os.Path, interp: ammonite.interp.Interpreter, scriptArgs: Seq[(String, Option[String])] = Nil) = { interp.watch(path) val (pkg, wrapper) = Util.pathToPackageWrapper(Seq(), path relativeTo wd) for{ - scriptTxt <- try Res.Success(Util.normalizeNewlines(read(path))) catch{ + scriptTxt <- try Res.Success(Util.normalizeNewlines(os.read(path))) catch{ case e: NoSuchFileException => Res.Failure("Script file not found: " + path) } @@ -169,7 +169,7 @@ object Scripts { for((lhs, rhs) <- args) yield { val lhsPadded = lhs.padTo(leftColWidth, ' ') - val rhsPadded = rhs.lines.mkString(Util.newLine) + val rhsPadded = rhs.linesIterator.mkString(Util.newLine) s"$leftIndentStr $lhsPadded $rhsPadded" } val mainDocSuffix = main.doc match{ @@ -273,7 +273,7 @@ object Scripts { } def softWrap(s: String, leftOffset: Int, maxWidth: Int) = { - val oneLine = s.lines.mkString(" ").split(' ') + val oneLine = s.linesIterator.mkString(" ").split(' ') lazy val indent = " " * leftOffset @@ -325,6 +325,6 @@ object Scripts { /** * Additional [[scopt.Read]] instance to teach it how to read Ammonite paths */ - implicit def pathScoptRead: scopt.Read[Path] = scopt.Read.stringRead.map(Path(_, pwd)) + implicit def pathScoptRead: scopt.Read[os.Path] = scopt.Read.stringRead.map(os.Path(_, os.pwd)) } diff --git a/main/graphviz/src/mill/main/graphviz/GraphvizTools.scala b/main/graphviz/src/mill/main/graphviz/GraphvizTools.scala index 4e8c59ce..9812c81f 100644 --- a/main/graphviz/src/mill/main/graphviz/GraphvizTools.scala +++ b/main/graphviz/src/mill/main/graphviz/GraphvizTools.scala @@ -1,10 +1,9 @@ package mill.main.graphviz -import ammonite.ops.Path import guru.nidi.graphviz.attribute.Style import mill.define.{Graph, NamedTask} import org.jgrapht.graph.{DefaultEdge, SimpleDirectedGraph} object GraphvizTools{ - def apply(targets: Seq[NamedTask[Any]], rs: Seq[NamedTask[Any]], dest: Path) = { + def apply(targets: Seq[NamedTask[Any]], rs: Seq[NamedTask[Any]], dest: os.Path) = { val transitive = Graph.transitiveTargets(rs.distinct) val topoSorted = Graph.topoSorted(transitive) val goalSet = rs.toSet diff --git a/main/src/mill/MillMain.scala b/main/src/mill/MillMain.scala index 1598d5f3..d36b6f42 100644 --- a/main/src/mill/MillMain.scala +++ b/main/src/mill/MillMain.scala @@ -4,7 +4,6 @@ import java.io.{InputStream, PrintStream} import scala.collection.JavaConverters._ import ammonite.main.Cli._ -import ammonite.ops._ import io.github.retronym.java9rtexport.Export import mill.eval.Evaluator import mill.util.DummyInputStream @@ -110,7 +109,7 @@ object MillMain { predefCode = s"""import $$file.build, build._ |implicit val replApplyHandler = mill.main.ReplApplyHandler( - | ammonite.ops.Path(${pprint.apply(cliConfig.home.toIO.getCanonicalPath.replaceAllLiterally("$", "$$")).plainText}), + | os.Path(${pprint.apply(cliConfig.home.toIO.getCanonicalPath.replaceAllLiterally("$", "$$")).plainText}), | $disableTicker, | interp.colors(), | repl.pprinter(), @@ -137,7 +136,7 @@ object MillMain { if (mill.main.client.Util.isJava9OrAbove) { val rt = cliConfig.home / Export.rtJarName - if (!exists(rt)) { + if (!os.exists(rt)) { runner.printInfo(s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ...") Export.rtTo(rt.toIO, false) } @@ -147,7 +146,7 @@ object MillMain { runner.printInfo("Loading...") (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) } else { - (runner.runScript(pwd / "build.sc", leftoverArgs), runner.stateCache) + (runner.runScript(os.pwd / "build.sc", leftoverArgs), runner.stateCache) } } diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index 929ad3dc..a740a2e6 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -2,7 +2,6 @@ package mill.main import java.util.concurrent.LinkedBlockingQueue -import ammonite.ops.Path import mill.T import mill.define.{NamedTask, Task} import mill.eval.{Evaluator, PathRef, Result} @@ -200,7 +199,7 @@ trait MainModule extends mill.Module{ val KeepPattern = "(mill-.+)".r.anchored - def keepPath(path: Path) = path.segments.lastOption match { + def keepPath(path: os.Path) = path.segments.toSeq.lastOption match { case Some(KeepPattern(_)) => true case _ => false } @@ -220,7 +219,7 @@ trait MainModule extends mill.Module{ case Left(err) => Result.Failure(err) case Right(paths) => - paths.foreach(ammonite.ops.rm) + paths.foreach(os.remove.all) Result.Success(()) } } @@ -245,7 +244,7 @@ trait MainModule extends mill.Module{ } } - private type VizWorker = (LinkedBlockingQueue[(scala.Seq[_], scala.Seq[_], Path)], + private type VizWorker = (LinkedBlockingQueue[(scala.Seq[_], scala.Seq[_], os.Path)], LinkedBlockingQueue[Result[scala.Seq[PathRef]]]) private def visualize0(evaluator: Evaluator, targets: Seq[String], ctx: Ctx, vizWorker: VizWorker, diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index 4f31a724..e50ed370 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -3,7 +3,6 @@ import java.io.{InputStream, PrintStream} import ammonite.Main import ammonite.interp.{Interpreter, Preprocessor} -import ammonite.ops.Path import ammonite.util.Util.CodeSource import ammonite.util._ import mill.eval.{Evaluator, PathRef} @@ -33,7 +32,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, var stateCache = stateCache0 - override def watchAndWait(watched: Seq[(Path, Long)]) = { + override def watchAndWait(watched: Seq[(os.Path, Long)]) = { printInfo(s"Watching for changes to ${watched.length} files... (Ctrl-C to exit)") def statAll() = watched.forall{ case (file, lastMTime) => Interpreter.pathSignature(file) == lastMTime @@ -50,7 +49,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, */ @tailrec final def watchLoop2[T](isRepl: Boolean, printing: Boolean, - run: Main => (Res[T], () => Seq[(Path, Long)])): Boolean = { + run: Main => (Res[T], () => Seq[(os.Path, Long)])): Boolean = { val (result, watched) = run(initMain(isRepl)) val success = handleWatchRes(result, printing) @@ -62,7 +61,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, } - override def runScript(scriptPath: Path, scriptArgs: List[String]) = + override def runScript(scriptPath: os.Path, scriptArgs: List[String]) = watchLoop2( isRepl = false, printing = true, @@ -146,7 +145,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, |$imports |import mill._ |object $wrapName - |extends mill.define.BaseModule(ammonite.ops.Path($literalPath), foreign0 = $external)( + |extends mill.define.BaseModule(os.Path($literalPath), foreign0 = $external)( | implicitly, implicitly, implicitly, implicitly, mill.define.Caller(()) |) |with $wrapName{ diff --git a/main/src/mill/main/ReplApplyHandler.scala b/main/src/mill/main/ReplApplyHandler.scala index af69c761..a8e467d4 100644 --- a/main/src/mill/main/ReplApplyHandler.scala +++ b/main/src/mill/main/ReplApplyHandler.scala @@ -1,7 +1,6 @@ package mill.main -import ammonite.ops.Path import mill.define.Applicative.ApplyHandler import mill.define.Segment.Label import mill.define._ @@ -11,7 +10,7 @@ import mill.util.Strict.Agg import scala.collection.mutable object ReplApplyHandler{ - def apply[T](home: Path, + def apply[T](home: os.Path, disableTicker: Boolean, colors: ammonite.util.Colors, pprinter0: pprint.PPrinter, diff --git a/main/src/mill/main/RunScript.scala b/main/src/mill/main/RunScript.scala index 1c8503fe..820b1341 100644 --- a/main/src/mill/main/RunScript.scala +++ b/main/src/mill/main/RunScript.scala @@ -3,7 +3,6 @@ package mill.main import java.nio.file.NoSuchFileException import ammonite.interp.Interpreter -import ammonite.ops.{Path, read} import ammonite.runtime.SpecialClassLoader import ammonite.util.Util.CodeSource import ammonite.util.{Name, Res, Util} @@ -23,15 +22,15 @@ import scala.reflect.ClassTag * subsystem */ object RunScript{ - def runScript(home: Path, - wd: Path, - path: Path, - instantiateInterpreter: => Either[(Res.Failing, Seq[(Path, Long)]), ammonite.interp.Interpreter], + def runScript(home: os.Path, + wd: os.Path, + path: os.Path, + instantiateInterpreter: => Either[(Res.Failing, Seq[(os.Path, Long)]), ammonite.interp.Interpreter], scriptArgs: Seq[String], stateCache: Option[Evaluator.State], log: Logger, env : Map[String, String]) - : (Res[(Evaluator, Seq[PathRef], Either[String, Seq[Js.Value]])], Seq[(Path, Long)]) = { + : (Res[(Evaluator, Seq[PathRef], Either[String, Seq[Js.Value]])], Seq[(os.Path, Long)]) = { val (evalState, interpWatched) = stateCache match{ case Some(s) if watchedSigUnchanged(s.watched) => Res.Success(s) -> s.watched @@ -66,12 +65,12 @@ object RunScript{ (evaluated, interpWatched) } - def watchedSigUnchanged(sig: Seq[(Path, Long)]) = { + def watchedSigUnchanged(sig: Seq[(os.Path, Long)]) = { sig.forall{case (p, l) => Interpreter.pathSignature(p) == l} } - def evaluateRootModule(wd: Path, - path: Path, + def evaluateRootModule(wd: os.Path, + path: os.Path, interp: ammonite.interp.Interpreter, log: Logger ): Res[mill.define.BaseModule] = { @@ -80,7 +79,7 @@ object RunScript{ for { scriptTxt <- - try Res.Success(Util.normalizeNewlines(read(path))) + try Res.Success(Util.normalizeNewlines(os.read(path))) catch { case _: NoSuchFileException => log.info("No build file found, you should create build.sc to do something useful") Res.Success("") diff --git a/main/src/mill/main/VisualizeModule.scala b/main/src/mill/main/VisualizeModule.scala index ea4d46c6..71b9fc22 100644 --- a/main/src/mill/main/VisualizeModule.scala +++ b/main/src/mill/main/VisualizeModule.scala @@ -2,7 +2,6 @@ package mill.main import java.util.concurrent.LinkedBlockingQueue -import ammonite.ops.Path import coursier.Cache import coursier.core.Repository import coursier.maven.MavenRepository @@ -35,7 +34,7 @@ trait VisualizeModule extends mill.define.TaskModule{ * can communicate via in/out queues. */ def worker = T.worker{ - val in = new LinkedBlockingQueue[(Seq[_], Seq[_], Path)]() + val in = new LinkedBlockingQueue[(Seq[_], Seq[_], os.Path)]() val out = new LinkedBlockingQueue[Result[Seq[PathRef]]]() val cl = mill.util.ClassLoader.create( @@ -47,7 +46,7 @@ trait VisualizeModule extends mill.define.TaskModule{ val res = Result.create{ val (targets, tasks, dest) = in.take() cl.loadClass("mill.main.graphviz.GraphvizTools") - .getMethod("apply", classOf[Seq[_]], classOf[Seq[_]], classOf[Path]) + .getMethod("apply", classOf[Seq[_]], classOf[Seq[_]], classOf[os.Path]) .invoke(null, targets, tasks, dest) .asInstanceOf[Seq[PathRef]] } diff --git a/main/src/mill/modules/Assembly.scala b/main/src/mill/modules/Assembly.scala index b7b91248..141bc226 100644 --- a/main/src/mill/modules/Assembly.scala +++ b/main/src/mill/modules/Assembly.scala @@ -4,7 +4,6 @@ import java.io.InputStream import java.util.jar.JarFile import java.util.regex.Pattern -import ammonite.ops._ import geny.Generator import mill.Agg @@ -37,7 +36,7 @@ object Assembly { case class ExcludePattern(pattern: Pattern) extends Rule } - def groupAssemblyEntries(inputPaths: Agg[Path], assemblyRules: Seq[Assembly.Rule]): Map[String, GroupedEntry] = { + def groupAssemblyEntries(inputPaths: Agg[os.Path], assemblyRules: Seq[Assembly.Rule]): Map[String, GroupedEntry] = { val rulesMap = assemblyRules.collect { case r@Rule.Append(path) => path -> r case r@Rule.Exclude(path) => path -> r @@ -76,12 +75,12 @@ object Assembly { } } - private def classpathIterator(inputPaths: Agg[Path]): Generator[AssemblyEntry] = { + private def classpathIterator(inputPaths: Agg[os.Path]): Generator[AssemblyEntry] = { Generator.from(inputPaths) - .filter(exists) + .filter(os.exists) .flatMap { p => - if (p.isFile) { + if (os.isFile(p)) { val jf = new JarFile(p.toIO) Generator.from( for(entry <- jf.entries().asScala if !entry.isDirectory) @@ -89,8 +88,8 @@ object Assembly { ) } else { - ls.rec.iter(p) - .filter(_.isFile) + os.walk.stream(p) + .filter(os.isFile) .map(sub => PathEntry(sub.relativeTo(p).toString, sub)) } } @@ -118,8 +117,8 @@ private[this] sealed trait AssemblyEntry { def inputStream: InputStream } -private[this] case class PathEntry(mapping: String, path: Path) extends AssemblyEntry { - def inputStream: InputStream = read.getInputStream(path) +private[this] case class PathEntry(mapping: String, path: os.Path) extends AssemblyEntry { + def inputStream: InputStream = os.read.inputStream(path) } private[this] case class JarFileEntry(mapping: String, getIs: () => InputStream) extends AssemblyEntry { diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala index 4c26b297..b4a55de3 100644 --- a/main/src/mill/modules/Jvm.scala +++ b/main/src/mill/modules/Jvm.scala @@ -8,7 +8,6 @@ import java.nio.file.attribute.PosixFilePermission import java.util.Collections import java.util.jar.{JarEntry, JarFile, JarOutputStream} -import ammonite.ops._ import coursier.{Cache, Dependency, Fetch, Repository, Resolution} import coursier.util.{Gather, Task} import geny.Generator @@ -23,11 +22,11 @@ import scala.collection.JavaConverters._ object Jvm { def interactiveSubprocess(mainClass: String, - classPath: Agg[Path], + classPath: Agg[os.Path], jvmArgs: Seq[String] = Seq.empty, envArgs: Map[String, String] = Map.empty, mainArgs: Seq[String] = Seq.empty, - workingDir: Path = null, + workingDir: os.Path = null, background: Boolean = false): Unit = { val args = Vector("java") ++ @@ -41,16 +40,16 @@ object Jvm { def baseInteractiveSubprocess(commandArgs: Seq[String], envArgs: Map[String, String], - workingDir: Path) = { + workingDir: os.Path) = { val process = baseInteractiveSubprocess0(commandArgs, envArgs, workingDir) val exitCode = process.waitFor() if (exitCode == 0) () - else throw InteractiveShelloutException() + else throw new Exception("Interactive Subprocess Failed") } def baseInteractiveSubprocess0(commandArgs: Seq[String], envArgs: Map[String, String], - workingDir: Path) = { + workingDir: os.Path) = { val builder = new java.lang.ProcessBuilder() for ((k, v) <- envArgs){ @@ -86,7 +85,7 @@ object Jvm { def runLocal(mainClass: String, - classPath: Agg[Path], + classPath: Agg[os.Path], mainArgs: Seq[String] = Seq.empty) (implicit ctx: Ctx): Unit = { inprocess(classPath, classLoaderOverrideSbtTesting = false, isolated = true, closeContextClassLoaderWhenDone = true, cl => { @@ -110,7 +109,7 @@ object Jvm { - def inprocess[T](classPath: Agg[Path], + def inprocess[T](classPath: Agg[os.Path], classLoaderOverrideSbtTesting: Boolean, isolated: Boolean, closeContextClassLoaderWhenDone: Boolean, @@ -143,11 +142,11 @@ object Jvm { } def subprocess(mainClass: String, - classPath: Agg[Path], + classPath: Agg[os.Path], jvmArgs: Seq[String] = Seq.empty, envArgs: Map[String, String] = Map.empty, mainArgs: Seq[String] = Seq.empty, - workingDir: Path = null) + workingDir: os.Path = null) (implicit ctx: Ctx) = { val commandArgs = @@ -157,7 +156,7 @@ object Jvm { mainArgs val workingDir1 = Option(workingDir).getOrElse(ctx.dest) - mkdir(workingDir1) + os.makeDir.all(workingDir1) val builder = new java.lang.ProcessBuilder() .directory(workingDir1.toIO) @@ -170,10 +169,10 @@ object Jvm { val stdout = proc.getInputStream val stderr = proc.getErrorStream val sources = Seq( - (stdout, Left(_: Bytes), ctx.log.outputStream), - (stderr, Right(_: Bytes),ctx.log.errorStream ) + (stdout, Left(_: os.Bytes), ctx.log.outputStream), + (stderr, Right(_: os.Bytes),ctx.log.errorStream ) ) - val chunks = mutable.Buffer.empty[Either[Bytes, Bytes]] + val chunks = mutable.Buffer.empty[Either[os.Bytes, os.Bytes]] while( // Process.isAlive doesn't exist on JDK 7 =/ util.Try(proc.exitValue).isFailure || @@ -186,7 +185,7 @@ object Jvm { readSomething = true val array = new Array[Byte](subStream.available()) val actuallyRead = subStream.read(array) - chunks.append(wrapper(new ammonite.ops.Bytes(array))) + chunks.append(wrapper(new os.Bytes(array))) parentStream.write(array, 0, actuallyRead) } } @@ -195,8 +194,8 @@ object Jvm { Thread.sleep(2) } - if (proc.exitValue() != 0) throw new InteractiveShelloutException() - else ammonite.ops.CommandResult(proc.exitValue(), chunks) + if (proc.exitValue() != 0) throw new Exception("Subprocess failed") + else os.CommandResult(proc.exitValue(), chunks) } private def createManifest(mainClass: Option[String]) = { @@ -214,42 +213,42 @@ object Jvm { * called out.jar in the implicit ctx.dest folder. An optional main class may * be provided for the jar. An optional filter function may also be provided to * selectively include/exclude specific files. - * @param inputPaths - `Agg` of `Path`s containing files to be included in the jar + * @param inputPaths - `Agg` of `os.Path`s containing files to be included in the jar * @param mainClass - optional main class for the jar * @param fileFilter - optional file filter to select files to be included. - * Given a `Path` (from inputPaths) and a `RelPath` for the individual file, + * Given a `os.Path` (from inputPaths) and a `os.RelPath` for the individual file, * return true if the file is to be included in the jar. * @param ctx - implicit `Ctx.Dest` used to determine the output directory for the jar. * @return - a `PathRef` for the created jar. */ - def createJar(inputPaths: Agg[Path], + def createJar(inputPaths: Agg[os.Path], mainClass: Option[String] = None, - fileFilter: (Path, RelPath) => Boolean = (p: Path, r: RelPath) => true) + fileFilter: (os.Path, os.RelPath) => Boolean = (p: os.Path, r: os.RelPath) => true) (implicit ctx: Ctx.Dest): PathRef = { val outputPath = ctx.dest / "out.jar" - rm(outputPath) + os.remove.all(outputPath) - val seen = mutable.Set.empty[RelPath] - seen.add("META-INF" / "MANIFEST.MF") + val seen = mutable.Set.empty[os.RelPath] + seen.add(os.rel / "META-INF" / "MANIFEST.MF") val jar = new JarOutputStream( new FileOutputStream(outputPath.toIO), createManifest(mainClass) ) try{ - assert(inputPaths.forall(exists(_))) + assert(inputPaths.forall(os.exists(_))) for{ p <- inputPaths (file, mapping) <- - if (p.isFile) Iterator(p -> empty/p.last) - else ls.rec(p).filter(_.isFile).map(sub => sub -> sub.relativeTo(p)) + if (os.isFile(p)) Iterator(p -> os.rel / p.last) + else os.walk(p).filter(os.isFile).map(sub => sub -> sub.relativeTo(p)).sorted if !seen(mapping) && fileFilter(p, mapping) } { seen.add(mapping) val entry = new JarEntry(mapping.toString) - entry.setTime(file.mtime.toMillis) + entry.setTime(os.mtime(file)) jar.putNextEntry(entry) - jar.write(read.bytes(file)) + jar.write(os.read.bytes(file)) jar.closeEntry() } } finally { @@ -259,17 +258,10 @@ object Jvm { PathRef(outputPath) } - def newOutputStream(p: java.nio.file.Path, append: Boolean = false) = { - val options = - if(append) Seq(StandardOpenOption.APPEND) - else Seq(StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) - Files.newOutputStream(p, options:_*) - } - - def createAssembly(inputPaths: Agg[Path], + def createAssembly(inputPaths: Agg[os.Path], mainClass: Option[String] = None, prependShellScript: String = "", - base: Option[Path] = None, + base: Option[os.Path] = None, assemblyRules: Seq[Assembly.Rule] = Assembly.defaultRules) (implicit ctx: Ctx.Dest with Ctx.Log): PathRef = { @@ -279,7 +271,7 @@ object Jvm { val hm = new java.util.HashMap[String, String]() base match{ - case Some(b) => cp(b, tmp) + case Some(b) => os.copy(b, tmp) case None => hm.put("create", "true") } @@ -288,23 +280,25 @@ object Jvm { val manifest = createManifest(mainClass) val manifestPath = zipFs.getPath(JarFile.MANIFEST_NAME) Files.createDirectories(manifestPath.getParent) - val manifestOut = newOutputStream(manifestPath) + val manifestOut = Files.newOutputStream( + manifestPath, + StandardOpenOption.TRUNCATE_EXISTING, + StandardOpenOption.CREATE + ) manifest.write(manifestOut) manifestOut.close() Assembly.groupAssemblyEntries(inputPaths, assemblyRules).view - .map { - case (mapping, aggregate) => - zipFs.getPath(mapping) -> aggregate - } .foreach { - case (path, AppendEntry(entries)) => + case (mapping, AppendEntry(entries)) => + val path = zipFs.getPath(mapping) val concatenated = new SequenceInputStream( Collections.enumeration(entries.map(_.inputStream).asJava)) - writeEntry(path, concatenated, append = Files.exists(path)) - case (path, WriteOnceEntry(entry)) => + writeEntry(os.Path(path), concatenated, append = true) + case (mapping, WriteOnceEntry(entry)) => + val path = zipFs.getPath(mapping) if (Files.notExists(path)) { - writeEntry(path, entry.inputStream, append = false) + writeEntry(os.Path(path), entry.inputStream, append = false) } } @@ -312,33 +306,36 @@ object Jvm { val output = ctx.dest / "out.jar" // Prepend shell script and make it executable - if (prependShellScript.isEmpty) mv(tmp, output) + if (prependShellScript.isEmpty) os.move(tmp, output) else{ val lineSep = if (!prependShellScript.endsWith("\n")) "\n\r\n" else "" - val outputStream = newOutputStream(output.toNIO) - IO.stream(new ByteArrayInputStream((prependShellScript + lineSep).getBytes()), outputStream) - IO.stream(read.getInputStream(tmp), outputStream) - outputStream.close() + os.write( + output, + Seq[os.Source]( + prependShellScript + lineSep, + os.read.inputStream(tmp) + ) + ) if (!scala.util.Properties.isWin) { - val perms = Files.getPosixFilePermissions(output.toNIO) - perms.add(PosixFilePermission.GROUP_EXECUTE) - perms.add(PosixFilePermission.OWNER_EXECUTE) - perms.add(PosixFilePermission.OTHERS_EXECUTE) - Files.setPosixFilePermissions(output.toNIO, perms) + os.perms.set( + output, + os.perms(output) + + PosixFilePermission.GROUP_EXECUTE + + PosixFilePermission.OWNER_EXECUTE + + PosixFilePermission.OTHERS_EXECUTE + ) } } PathRef(output) } - private def writeEntry(p: java.nio.file.Path, is: InputStream, append: Boolean): Unit = { - if (p.getParent != null) Files.createDirectories(p.getParent) - val outputStream = newOutputStream(p, append) - - IO.stream(is, outputStream) + private def writeEntry(p: os.Path, is: InputStream, append: Boolean): Unit = { + if (p.toNIO.getParent != null) Files.createDirectories(p.toNIO.getParent) + if (append) os.write(p, is) + else os.write.append(p, is) - outputStream.close() is.close() } @@ -376,7 +373,7 @@ object Jvm { ) } def createLauncher(mainClass: String, - classPath: Agg[Path], + classPath: Agg[os.Path], jvmArgs: Seq[String]) (implicit ctx: Ctx.Dest)= { val isWin = scala.util.Properties.isWin @@ -387,7 +384,7 @@ object Jvm { val outputPath = ctx.dest / (if (isBatch) "run.bat" else "run") val classPathStrs = classPath.map(_.toString) - write(outputPath, launcherUniversalScript(mainClass, classPathStrs, classPathStrs, jvmArgs)) + os.write(outputPath, launcherUniversalScript(mainClass, classPathStrs, classPathStrs, jvmArgs)) if (!isWin) { val perms = Files.getPosixFilePermissions(outputPath.toNIO) @@ -454,7 +451,7 @@ object Jvm { val (errors, successes) = load(sourceOrJar) if(errors.isEmpty){ mill.Agg.from( - successes.map(p => PathRef(Path(p), quick = true)).filter(_.path.ext == "jar") + successes.map(p => PathRef(os.Path(p), quick = true)).filter(_.path.ext == "jar") ) }else{ val errorDetails = errors.map(e => s"${ammonite.util.Util.newLine} ${e.describe}").mkString diff --git a/main/src/mill/modules/Util.scala b/main/src/mill/modules/Util.scala index 38cd056b..2f57595e 100644 --- a/main/src/mill/modules/Util.scala +++ b/main/src/mill/modules/Util.scala @@ -1,14 +1,13 @@ package mill.modules -import ammonite.ops.{Path, RelPath, empty, mkdir, read} import coursier.Repository import mill.eval.PathRef import mill.util.{Ctx, IO, Loose} object Util { def cleanupScaladoc(v: String) = { - v.lines.map( + v.linesIterator.map( _.dropWhile(_.isWhitespace) .stripPrefix("/**") .stripPrefix("*/") @@ -20,7 +19,7 @@ object Util { .dropWhile(_.isEmpty) .reverse } - def download(url: String, dest: RelPath = "download")(implicit ctx: Ctx.Dest) = { + def download(url: String, dest: os.RelPath = "download")(implicit ctx: Ctx.Dest) = { val out = ctx.dest / dest val website = new java.net.URI(url).toURL @@ -38,26 +37,26 @@ object Util { } } - def downloadUnpackZip(url: String, dest: RelPath = "unpacked") + def downloadUnpackZip(url: String, dest: os.RelPath = "unpacked") (implicit ctx: Ctx.Dest) = { - val tmpName = if (dest == empty / "tmp.zip") "tmp2.zip" else "tmp.zip" + val tmpName = if (dest == os.rel / "tmp.zip") "tmp2.zip" else "tmp.zip" val downloaded = download(url, tmpName) unpackZip(downloaded.path, dest) } - def unpackZip(src: Path, dest: RelPath = "unpacked") + def unpackZip(src: os.Path, dest: os.RelPath = "unpacked") (implicit ctx: Ctx.Dest) = { - val byteStream = read.getInputStream(src) + val byteStream = os.read.inputStream(src) val zipStream = new java.util.zip.ZipInputStream(byteStream) while({ zipStream.getNextEntry match{ case null => false case entry => if (!entry.isDirectory) { - val entryDest = ctx.dest / dest / RelPath(entry.getName) - mkdir(entryDest / ammonite.ops.up) + val entryDest = ctx.dest / dest / os.RelPath(entry.getName) + os.makeDir.all(entryDest / ammonite.ops.up) val fileOut = new java.io.FileOutputStream(entryDest.toString) IO.stream(zipStream, fileOut) fileOut.close() @@ -72,12 +71,12 @@ object Util { def millProjectModule(key: String, artifact: String, repositories: Seq[Repository], - resolveFilter: Path => Boolean = _ => true, + resolveFilter: os.Path => Boolean = _ => true, artifactSuffix: String = "_2.12") = { val localPath = sys.props(key) if (localPath != null) { mill.eval.Result.Success( - Loose.Agg.from(localPath.split(',').map(p => PathRef(Path(p), quick = true))) + Loose.Agg.from(localPath.split(',').map(p => PathRef(os.Path(p), quick = true))) ) } else { mill.modules.Jvm.resolveDependencies( diff --git a/main/test/resources/examples/foreign/conflict/build.sc b/main/test/resources/examples/foreign/conflict/build.sc index d6c08b81..bedd7237 100644 --- a/main/test/resources/examples/foreign/conflict/build.sc +++ b/main/test/resources/examples/foreign/conflict/build.sc @@ -1,6 +1,5 @@ import $file.inner.{build => innerBuild} import mill._ -import ammonite.ops._ // In this build, we have a local module targeting // the 'inner sub-directory, and an imported foreign @@ -20,5 +19,5 @@ def checkDests : T[Unit] = T { } object inner extends mill.Module { - def selfDest = T { T.ctx().dest / up / up } + def selfDest = T { T.ctx().dest / os.up / os.up } } diff --git a/main/test/resources/examples/foreign/conflict/inner/build.sc b/main/test/resources/examples/foreign/conflict/inner/build.sc index 729f4f3d..81e5fc2f 100644 --- a/main/test/resources/examples/foreign/conflict/inner/build.sc +++ b/main/test/resources/examples/foreign/conflict/inner/build.sc @@ -1,4 +1,3 @@ import mill._ -import ammonite.ops._ -def selfDest = T { T.ctx().dest / up / up } +def selfDest = T { T.ctx().dest / os.up / os.up } diff --git a/main/test/resources/examples/foreign/outer/build.sc b/main/test/resources/examples/foreign/outer/build.sc index b53cca70..adef19da 100644 --- a/main/test/resources/examples/foreign/outer/build.sc +++ b/main/test/resources/examples/foreign/outer/build.sc @@ -1,13 +1,12 @@ import $file.inner.build import mill._ -import ammonite.ops._ trait PathAware extends mill.Module { def selfPath = T { millSourcePath } } trait DestAware extends mill.Module { - def selfDest = T { T.ctx().dest / up / up } + def selfDest = T { T.ctx().dest / os.up / os.up } } object sub extends PathAware with DestAware { diff --git a/main/test/resources/examples/foreign/outer/inner/build.sc b/main/test/resources/examples/foreign/outer/inner/build.sc index 2d978292..da103b95 100644 --- a/main/test/resources/examples/foreign/outer/inner/build.sc +++ b/main/test/resources/examples/foreign/outer/inner/build.sc @@ -1,12 +1,11 @@ import mill._ -import ammonite.ops._ trait PathAware extends mill.Module { def selfPath = T { millSourcePath } } trait DestAware extends mill.Module { - def selfDest = T { T.ctx().dest / up / up } + def selfDest = T { T.ctx().dest / os.up / os.up } } object sub extends PathAware with DestAware { diff --git a/main/test/resources/examples/foreign/project/build.sc b/main/test/resources/examples/foreign/project/build.sc index 80c2af9b..54686c2d 100644 --- a/main/test/resources/examples/foreign/project/build.sc +++ b/main/test/resources/examples/foreign/project/build.sc @@ -1,10 +1,9 @@ import $file.^.outer.build import $file.inner.build -import ammonite.ops._ import mill._ -def assertPaths(p1 : Path, p2 : Path) : Unit = if (p1 != p2) throw new Exception( +def assertPaths(p1 : os.Path, p2 : os.Path) : Unit = if (p1 != p2) throw new Exception( s"Paths were not equal : \n- $p1 \n- $p2" ) @@ -17,7 +16,7 @@ object sub extends PathAware with DestAware { } def checkProjectPaths = T { - val thisPath : Path = millSourcePath + val thisPath : os.Path = millSourcePath assert(thisPath.last == "project") assertPaths(sub.selfPath(), thisPath / 'sub) assertPaths(sub.sub.selfPath(), thisPath / 'sub / 'sub) @@ -25,47 +24,47 @@ def checkProjectPaths = T { } def checkInnerPaths = T { - val thisPath : Path = millSourcePath + val thisPath : os.Path = millSourcePath assertPaths(inner.build.millSourcePath, thisPath / 'inner ) assertPaths(inner.build.sub.selfPath(), thisPath / 'inner / 'sub) assertPaths(inner.build.sub.sub.selfPath(), thisPath / 'inner / 'sub / 'sub) } def checkOuterPaths = T { - val thisPath : Path = millSourcePath - assertPaths(^.outer.build.millSourcePath, thisPath / up / 'outer ) - assertPaths(^.outer.build.sub.selfPath(), thisPath / up / 'outer / 'sub) - assertPaths(^.outer.build.sub.sub.selfPath(), thisPath / up / 'outer / 'sub / 'sub) + val thisPath : os.Path = millSourcePath + assertPaths(^.outer.build.millSourcePath, thisPath / os.up / 'outer ) + assertPaths(^.outer.build.sub.selfPath(), thisPath / os.up / 'outer / 'sub) + assertPaths(^.outer.build.sub.sub.selfPath(), thisPath / os.up / 'outer / 'sub / 'sub) } def checkOuterInnerPaths = T { - val thisPath : Path = millSourcePath - assertPaths(^.outer.inner.build.millSourcePath, thisPath / up / 'outer / 'inner ) - assertPaths(^.outer.inner.build.sub.selfPath(), thisPath / up / 'outer / 'inner /'sub) - assertPaths(^.outer.inner.build.sub.sub.selfPath(), thisPath / up / 'outer / 'inner / 'sub / 'sub) + val thisPath : os.Path = millSourcePath + assertPaths(^.outer.inner.build.millSourcePath, thisPath / os.up / 'outer / 'inner ) + assertPaths(^.outer.inner.build.sub.selfPath(), thisPath / os.up / 'outer / 'inner /'sub) + assertPaths(^.outer.inner.build.sub.sub.selfPath(), thisPath / os.up / 'outer / 'inner / 'sub / 'sub) } def checkProjectDests = T { - val outPath : Path = millSourcePath / 'out + val outPath : os.Path = millSourcePath / 'out assertPaths(sub.selfDest(), outPath / 'sub) assertPaths(sub.sub.selfDest(), outPath / 'sub / 'sub) assertPaths(sub.sub2.selfDest(), outPath / 'sub / 'sub2) } def checkInnerDests = T { - val foreignOut : Path = millSourcePath / 'out / "foreign-modules" + val foreignOut : os.Path = millSourcePath / 'out / "foreign-modules" assertPaths(inner.build.sub.selfDest(), foreignOut / 'inner / 'sub) assertPaths(inner.build.sub.sub.selfDest(), foreignOut / 'inner / 'sub / 'sub) } def checkOuterDests = T { - val foreignOut : Path = millSourcePath / 'out / "foreign-modules" + val foreignOut : os.Path = millSourcePath / 'out / "foreign-modules" assertPaths(^.outer.build.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'sub ) assertPaths(^.outer.build.sub.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'sub / 'sub) } def checkOuterInnerDests = T { - val foreignOut : Path = millSourcePath / 'out / "foreign-modules" + val foreignOut : os.Path = millSourcePath / 'out / "foreign-modules" assertPaths(^.outer.inner.build.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'inner / 'sub) assertPaths(^.outer.inner.build.sub.sub.selfDest(), foreignOut / "up-1" / 'outer/ 'inner / 'sub / 'sub) } @@ -77,6 +76,6 @@ trait PathAware extends mill.Module { } trait DestAware extends mill.Module { - def selfDest = T { T.ctx().dest / up / up } + def selfDest = T { T.ctx().dest / os.up / os.up } } diff --git a/main/test/resources/examples/foreign/project/inner/build.sc b/main/test/resources/examples/foreign/project/inner/build.sc index 2d978292..da103b95 100644 --- a/main/test/resources/examples/foreign/project/inner/build.sc +++ b/main/test/resources/examples/foreign/project/inner/build.sc @@ -1,12 +1,11 @@ import mill._ -import ammonite.ops._ trait PathAware extends mill.Module { def selfPath = T { millSourcePath } } trait DestAware extends mill.Module { - def selfDest = T { T.ctx().dest / up / up } + def selfDest = T { T.ctx().dest / os.up / os.up } } object sub extends PathAware with DestAware { diff --git a/main/test/resources/examples/javac/build.sc b/main/test/resources/examples/javac/build.sc index 0783ac17..c45a6e2d 100644 --- a/main/test/resources/examples/javac/build.sc +++ b/main/test/resources/examples/javac/build.sc @@ -1,4 +1,3 @@ -import ammonite.ops._ import mill.T import mill.eval.JavaCompileJarTests.compileAll import mill.eval.PathRef @@ -14,10 +13,10 @@ def resourceRootPath = millSourcePath / 'resources // resourceRoot ----> jar def sourceRoot = T.sources{ sourceRootPath } def resourceRoot = T.sources{ resourceRootPath } -def allSources = T{ sourceRoot().flatMap(p => ls.rec(p.path)).map(PathRef(_)) } +def allSources = T{ sourceRoot().flatMap(p => os.walk(p.path)).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } def jar = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path)) } def run(mainClsName: String) = T.command{ - %%('java, "-cp", classFiles().path, mainClsName)(T.ctx().dest) + os.proc('java, "-cp", classFiles().path, mainClsName).call(T.ctx().dest) } diff --git a/main/test/src/mill/UTestFramework.scala b/main/test/src/mill/UTestFramework.scala index 6c0d5191..c234151b 100644 --- a/main/test/src/mill/UTestFramework.scala +++ b/main/test/src/mill/UTestFramework.scala @@ -5,7 +5,7 @@ class UTestFramework extends utest.runner.Framework { s.getClassName.startsWith("mill.") } override def setup() = { - import ammonite.ops._ - rm(pwd / 'target / 'workspace) + + os.remove.all(os.pwd / 'target / 'workspace) } } diff --git a/main/test/src/mill/define/BasePathTests.scala b/main/test/src/mill/define/BasePathTests.scala index d5167081..b8a653c8 100644 --- a/main/test/src/mill/define/BasePathTests.scala +++ b/main/test/src/mill/define/BasePathTests.scala @@ -2,7 +2,6 @@ package mill.define import mill.util.{TestGraphs, TestUtil} import utest._ -import ammonite.ops._ import mill.{Module, T} object BasePathTests extends TestSuite{ val testGraphs = new TestGraphs @@ -54,7 +53,7 @@ object BasePathTests extends TestSuite{ } 'overriden - { object overridenBasePath extends TestUtil.BaseModule { - override def millSourcePath = pwd / 'overridenBasePathRootValue + override def millSourcePath = os.pwd / 'overridenBasePathRootValue object nested extends Module{ override def millSourcePath = super.millSourcePath / 'overridenBasePathNested object nested extends Module{ @@ -63,9 +62,9 @@ object BasePathTests extends TestSuite{ } } assert( - overridenBasePath.millSourcePath == pwd / 'overridenBasePathRootValue, - overridenBasePath.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested, - overridenBasePath.nested.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested + overridenBasePath.millSourcePath == os.pwd / 'overridenBasePathRootValue, + overridenBasePath.nested.millSourcePath == os.pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested, + overridenBasePath.nested.nested.millSourcePath == os.pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested ) } diff --git a/main/test/src/mill/define/CacherTests.scala b/main/test/src/mill/define/CacherTests.scala index 98f2b7f8..84a8d840 100644 --- a/main/test/src/mill/define/CacherTests.scala +++ b/main/test/src/mill/define/CacherTests.scala @@ -1,6 +1,5 @@ package mill.define -import ammonite.ops.pwd import mill.util.{DummyLogger, TestEvaluator, TestUtil} import mill.util.Strict.Agg import mill.T diff --git a/main/test/src/mill/eval/CrossTests.scala b/main/test/src/mill/eval/CrossTests.scala index 3dec0222..f194924e 100644 --- a/main/test/src/mill/eval/CrossTests.scala +++ b/main/test/src/mill/eval/CrossTests.scala @@ -1,6 +1,6 @@ package mill.eval -import ammonite.ops._ + import mill.define.Discover import mill.util.TestEvaluator diff --git a/main/test/src/mill/eval/EvaluationTests.scala b/main/test/src/mill/eval/EvaluationTests.scala index 75a5bbe3..74f9088c 100644 --- a/main/test/src/mill/eval/EvaluationTests.scala +++ b/main/test/src/mill/eval/EvaluationTests.scala @@ -9,7 +9,7 @@ import mill.util.Strict.Agg import utest._ import utest.framework.TestPath -import ammonite.ops._ + object EvaluationTests extends TestSuite{ class Checker[T <: TestUtil.BaseModule](module: T)(implicit tp: TestPath) { diff --git a/main/test/src/mill/eval/FailureTests.scala b/main/test/src/mill/eval/FailureTests.scala index 22021079..bf45119c 100644 --- a/main/test/src/mill/eval/FailureTests.scala +++ b/main/test/src/mill/eval/FailureTests.scala @@ -1,7 +1,6 @@ package mill.eval import mill.T import mill.util.{TestEvaluator, TestUtil} -import ammonite.ops.{Path, pwd, rm} import mill.eval.Result.OuterStack import utest._ import utest.framework.TestPath diff --git a/main/test/src/mill/eval/JavaCompileJarTests.scala b/main/test/src/mill/eval/JavaCompileJarTests.scala index d4bdbd87..8e931747 100644 --- a/main/test/src/mill/eval/JavaCompileJarTests.scala +++ b/main/test/src/mill/eval/JavaCompileJarTests.scala @@ -1,7 +1,5 @@ package mill.eval -import ammonite.ops.ImplicitWd._ -import ammonite.ops._ import mill.define.{Discover, Input, Target, Task} import mill.modules.Jvm import mill.util.Ctx.Dest @@ -12,19 +10,19 @@ import utest._ import mill._ object JavaCompileJarTests extends TestSuite{ def compileAll(sources: mill.util.Loose.Agg[PathRef])(implicit ctx: Dest) = { - mkdir(ctx.dest) - import ammonite.ops._ - %("javac", sources.map(_.path.toString()).toSeq, "-d", ctx.dest)(wd = ctx.dest) + os.makeDir.all(ctx.dest) + + os.proc("javac", sources.map(_.path.toString()).toSeq, "-d", ctx.dest).call(ctx.dest) PathRef(ctx.dest) } val tests = Tests{ 'javac { - val javacSrcPath = pwd / 'main / 'test / 'resources / 'examples / 'javac + val javacSrcPath = os.pwd / 'main / 'test / 'resources / 'examples / 'javac val javacDestPath = TestUtil.getOutPath() / 'src - mkdir(javacDestPath / up) - cp(javacSrcPath, javacDestPath) + os.makeDir.all(javacDestPath / os.up) + os.copy(javacSrcPath, javacDestPath) object Build extends TestUtil.BaseModule{ def sourceRootPath = javacDestPath / 'src @@ -36,14 +34,14 @@ object JavaCompileJarTests extends TestSuite{ // resourceRoot ----> jar def sourceRoot = T.sources{ sourceRootPath } def resourceRoot = T.sources{ resourceRootPath } - def allSources = T{ sourceRoot().flatMap(p => ls.rec(p.path)).map(PathRef(_)) } + def allSources = T{ sourceRoot().flatMap(p => os.walk(p.path)).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } def jar = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path)) } // Test createJar() with optional file filter. - def filterJar(fileFilter: (Path, RelPath) => Boolean) = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path), None, fileFilter) } + def filterJar(fileFilter: (os.Path, os.RelPath) => Boolean) = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path), None, fileFilter) } def run(mainClsName: String) = T.command{ - %%('java, "-Duser.language=en", "-cp", classFiles().path, mainClsName) + os.proc('java, "-Duser.language=en", "-cp", classFiles().path, mainClsName).call() } } @@ -57,7 +55,7 @@ object JavaCompileJarTests extends TestSuite{ evaluator.check(targets, expected) } - def append(path: Path, txt: String) = ammonite.ops.write.append(path, txt) + def append(path: os.Path, txt: String) = ammonite.ops.write.append(path, txt) check( @@ -67,7 +65,6 @@ object JavaCompileJarTests extends TestSuite{ // Re-running with no changes results in nothing being evaluated check(targets = Agg(jar), expected = Agg()) - // Appending an empty string gets ignored due to file-content hashing append(sourceRootPath / "Foo.java", "") check(targets = Agg(jar), expected = Agg()) @@ -106,7 +103,7 @@ object JavaCompileJarTests extends TestSuite{ check(targets = Agg(allSources), expected = Agg(allSources)) check(targets = Agg(jar), expected = Agg(classFiles, jar)) - val jarContents = %%('jar, "-tf", evaluator.outPath/'jar/'dest/"out.jar")(evaluator.outPath).out.string + val jarContents = os.proc('jar, "-tf", evaluator.outPath/'jar/'dest/"out.jar").call(evaluator.outPath).out.string val expectedJarContents = """META-INF/MANIFEST.MF |test/Bar.class @@ -116,16 +113,16 @@ object JavaCompileJarTests extends TestSuite{ |test/FooTwo.class |hello.txt |""".stripMargin - assert(jarContents.lines.toSeq == expectedJarContents.lines.toSeq) + assert(jarContents.linesIterator.toSeq == expectedJarContents.linesIterator.toSeq) // Create the Jar again, but this time, filter out the Foo files. def noFoos(s: String) = !s.contains("Foo") - val filterFunc = (p: Path, r: RelPath) => noFoos(r.last) + val filterFunc = (p: os.Path, r: os.RelPath) => noFoos(r.last) eval(filterJar(filterFunc)) - val filteredJarContents = %%('jar, "-tf", evaluator.outPath/'filterJar/'dest/"out.jar")(evaluator.outPath).out.string - assert(filteredJarContents.lines.toSeq == expectedJarContents.lines.filter(noFoos(_)).toSeq) + val filteredJarContents = os.proc('jar, "-tf", evaluator.outPath/'filterJar/'dest/"out.jar").call(evaluator.outPath).out.string + assert(filteredJarContents.linesIterator.toSeq == expectedJarContents.linesIterator.filter(noFoos(_)).toSeq) - val executed = %%('java, "-cp", evaluator.outPath/'jar/'dest/"out.jar", "test.Foo")(evaluator.outPath).out.string + val executed = os.proc('java, "-cp", evaluator.outPath/'jar/'dest/"out.jar", "test.Foo").call(evaluator.outPath).out.string assert(executed == (31337 + 271828) + System.lineSeparator) for(i <- 0 until 3){ diff --git a/main/test/src/mill/eval/ModuleTests.scala b/main/test/src/mill/eval/ModuleTests.scala index 0b4a7c80..f28fc9b6 100644 --- a/main/test/src/mill/eval/ModuleTests.scala +++ b/main/test/src/mill/eval/ModuleTests.scala @@ -1,6 +1,6 @@ package mill.eval -import ammonite.ops._ + import mill.util.{TestEvaluator, TestUtil} import mill.T import mill.define.Discover @@ -19,15 +19,15 @@ object ModuleTests extends TestSuite{ def z = T{ ExternalModule.x() + ExternalModule.inner.y() } } val tests = Tests { - rm(TestEvaluator.externalOutPath) + os.remove.all(TestEvaluator.externalOutPath) 'externalModuleTargetsAreNamespacedByModulePackagePath - { val check = new TestEvaluator(Build) val zresult = check.apply(Build.z) assert( zresult == Right((30, 1)), - read(check.evaluator.outPath / 'z / "meta.json").contains("30"), - read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"), - read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'inner / 'y / "meta.json").contains("17") + os.read(check.evaluator.outPath / 'z / "meta.json").contains("30"), + os.read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"), + os.read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'inner / 'y / "meta.json").contains("17") ) } 'externalModuleMustBeGlobalStatic - { diff --git a/main/test/src/mill/eval/TaskTests.scala b/main/test/src/mill/eval/TaskTests.scala index 4ba65e17..0bfd8efc 100644 --- a/main/test/src/mill/eval/TaskTests.scala +++ b/main/test/src/mill/eval/TaskTests.scala @@ -1,7 +1,7 @@ package mill.eval import utest._ -import ammonite.ops._ + import mill.T import mill.util.TestEvaluator @@ -34,15 +34,15 @@ object TaskTests extends TestSuite{ def persistent = T.persistent{ input() // force re-computation - mkdir(T.ctx().dest) - write.append(T.ctx().dest/'count, "hello\n") - read.lines(T.ctx().dest/'count).length + os.makeDir.all(T.ctx().dest) + os.write.append(T.ctx().dest/'count, "hello\n") + os.read.lines(T.ctx().dest/'count).length } def nonPersistent = T{ input() // force re-computation - mkdir(T.ctx().dest) - write.append(T.ctx().dest/'count, "hello\n") - read.lines(T.ctx().dest/'count).length + os.makeDir.all(T.ctx().dest) + os.write.append(T.ctx().dest/'count, "hello\n") + os.read.lines(T.ctx().dest/'count).length } def staticWorkerDownstream = T{ diff --git a/main/test/src/mill/main/ClientServerTests.scala b/main/test/src/mill/main/ClientServerTests.scala index 2462f650..05238a5f 100644 --- a/main/test/src/mill/main/ClientServerTests.scala +++ b/main/test/src/mill/main/ClientServerTests.scala @@ -1,6 +1,5 @@ package mill.main import java.io._ -import java.nio.file.Path import mill.main.client.{Util, Locks} @@ -47,7 +46,7 @@ object ClientServerTests extends TestSuite{ (tmpDir, locks) } - def spawnEchoServer(tmpDir : Path, locks: Locks): Unit = { + def spawnEchoServer(tmpDir : java.nio.file.Path, locks: Locks): Unit = { new Thread(() => new Server( tmpDir.toString, new EchoServer(), @@ -57,7 +56,7 @@ object ClientServerTests extends TestSuite{ ).run()).start() } - def runClientAux(tmpDir : Path, locks: Locks) + def runClientAux(tmpDir : java.nio.file.Path, locks: Locks) (env : Map[String, String], args: Array[String]) = { val (in, out, err) = initStreams() Server.lockBlock(locks.clientLock){ diff --git a/main/test/src/mill/main/ForeignBuildsTest.scala b/main/test/src/mill/main/ForeignBuildsTest.scala index 085ada02..cfc8d00c 100644 --- a/main/test/src/mill/main/ForeignBuildsTest.scala +++ b/main/test/src/mill/main/ForeignBuildsTest.scala @@ -1,14 +1,13 @@ package mill.main -import ammonite.ops._ import mill.util.ScriptTestSuite import utest._ object ForeignBuildsTest extends ScriptTestSuite(fork = false) { def workspaceSlug = "foreign-builds" def scriptSourcePath = - pwd / 'main / 'test / 'resources / 'examples / 'foreign - override def buildPath = 'project / "build.sc" + os.pwd / 'main / 'test / 'resources / 'examples / 'foreign + override def buildPath = os.rel / 'project / "build.sc" val tests = Tests { initWorkspace() diff --git a/main/test/src/mill/main/ForeignConflictTest.scala b/main/test/src/mill/main/ForeignConflictTest.scala index c5d99c9f..a4352bb6 100644 --- a/main/test/src/mill/main/ForeignConflictTest.scala +++ b/main/test/src/mill/main/ForeignConflictTest.scala @@ -1,14 +1,14 @@ package mill.main -import ammonite.ops._ + import mill.util.ScriptTestSuite import utest._ object ForeignConflictTest extends ScriptTestSuite(fork = false) { def workspaceSlug = "foreign-conflict" def scriptSourcePath = - pwd / 'main / 'test / 'resources / 'examples / 'foreign - override def buildPath = 'conflict / "build.sc" + os.pwd / 'main / 'test / 'resources / 'examples / 'foreign + override def buildPath = os.rel / 'conflict / "build.sc" val tests = Tests { initWorkspace() diff --git a/main/test/src/mill/main/JavaCompileJarTests.scala b/main/test/src/mill/main/JavaCompileJarTests.scala index 6c45b454..37c64b05 100644 --- a/main/test/src/mill/main/JavaCompileJarTests.scala +++ b/main/test/src/mill/main/JavaCompileJarTests.scala @@ -1,12 +1,11 @@ package mill.main -import ammonite.ops._ import mill.util.ScriptTestSuite import utest._ object JavaCompileJarTests extends ScriptTestSuite(fork = false) { def workspaceSlug = "java-compile-jar" - def scriptSourcePath = pwd / 'main / 'test / 'resources / 'examples / 'javac + def scriptSourcePath = os.pwd / 'main / 'test / 'resources / 'examples / 'javac val tests = Tests{ initWorkspace() 'test - { @@ -31,8 +30,8 @@ object JavaCompileJarTests extends ScriptTestSuite(fork = false) { ) // If we update resources, classFiles are unchanged but jar changes - for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "txt")){ - write.append(scalaFile, "\n") + for(scalaFile <- os.walk(workspacePath).filter(_.ext == "txt")){ + os.write.append(scalaFile, "\n") } assert(eval("classFiles")) @@ -48,15 +47,15 @@ object JavaCompileJarTests extends ScriptTestSuite(fork = false) { // We can intentionally break the code, have the targets break, then // fix the code and have them recover. - for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "java")){ - write.append(scalaFile, "\n}") + for(scalaFile <- os.walk(workspacePath).filter(_.ext == "java")){ + os.write.append(scalaFile, "\n}") } assert(!eval("classFiles")) assert(!eval("jar")) - for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "java")){ - write.over(scalaFile, read(scalaFile).dropRight(2)) + for(scalaFile <- os.walk(workspacePath).filter(_.ext == "java")){ + os.write.over(scalaFile, os.read(scalaFile).dropRight(2)) } assert(eval("classFiles")) diff --git a/main/test/src/mill/util/ScriptTestSuite.scala b/main/test/src/mill/util/ScriptTestSuite.scala index 9d3edb65..b324f94c 100644 --- a/main/test/src/mill/util/ScriptTestSuite.scala +++ b/main/test/src/mill/util/ScriptTestSuite.scala @@ -2,16 +2,15 @@ package mill.util import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream} -import ammonite.ops._ import utest._ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ def workspaceSlug: String - def scriptSourcePath: Path - def buildPath: RelPath = "build.sc" + def scriptSourcePath: os.Path + def buildPath: os.RelPath = "build.sc" - val workspacePath = pwd / 'target / 'workspace / workspaceSlug - val wd = workspacePath / buildPath / up + val workspacePath = os.pwd / 'target / 'workspace / workspaceSlug + val wd = workspacePath / buildPath / os.up val stdOutErr = new PrintStream(new ByteArrayOutputStream()) val stdIn = new ByteArrayInputStream(Array()) val disableTicker = false @@ -25,7 +24,7 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ if (!fork) runner.runScript(workspacePath / buildPath , s.toList) else{ try { - %(home / "mill-release", "-i", s)(wd) + os.proc(os.home / "mill-release", "-i", s).call(wd) true }catch{case e: Throwable => false} } @@ -33,17 +32,17 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ def meta(s: String) = { val (List(selector), args) = ParseArgs.apply(Seq(s), multiSelect = false).right.get - read(wd / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json") + os.read(wd / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json") } def initWorkspace() = { - rm(workspacePath) - mkdir(workspacePath / up) + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) // The unzipped git repo snapshots we get from github come with a // wrapper-folder inside the zip file, so copy the wrapper folder to the // destination instead of the folder containing the wrapper. - cp(scriptSourcePath, workspacePath) + os.copy(scriptSourcePath, workspacePath) } } diff --git a/main/test/src/mill/util/TestEvaluator.scala b/main/test/src/mill/util/TestEvaluator.scala index 6e7fe484..67ba96dc 100644 --- a/main/test/src/mill/util/TestEvaluator.scala +++ b/main/test/src/mill/util/TestEvaluator.scala @@ -1,6 +1,5 @@ package mill.util -import ammonite.ops.pwd import mill.define.{Input, Target, Task} import mill.eval.Result.OuterStack import mill.eval.{Evaluator, Result} @@ -10,7 +9,7 @@ import utest.framework.TestPath import language.experimental.macros object TestEvaluator{ - val externalOutPath = pwd / 'target / 'external + val externalOutPath = os.pwd / 'target / 'external def static(module: TestUtil.BaseModule)(implicit fullName: sourcecode.FullName) = { diff --git a/main/test/src/mill/util/TestUtil.scala b/main/test/src/mill/util/TestUtil.scala index b4e3af89..e5fe906e 100644 --- a/main/test/src/mill/util/TestUtil.scala +++ b/main/test/src/mill/util/TestUtil.scala @@ -1,7 +1,6 @@ package mill.util import mill.util.Router.Overrides -import ammonite.ops.pwd import mill.define._ import mill.eval.Result import mill.eval.Result.OuterStack @@ -14,17 +13,17 @@ import scala.collection.mutable object TestUtil { def getOutPath()(implicit fullName: sourcecode.FullName, tp: TestPath) = { - pwd / 'target / 'workspace / (fullName.value.split('.') ++ tp.value) + os.pwd / 'target / 'workspace / (fullName.value.split('.') ++ tp.value) } def getOutPathStatic()(implicit fullName: sourcecode.FullName) = { - pwd / 'target / 'workspace / fullName.value.split('.') + os.pwd / 'target / 'workspace / fullName.value.split('.') } def getSrcPathStatic()(implicit fullName: sourcecode.FullName) = { - pwd / 'target / 'worksources / fullName.value.split('.') + os.pwd / 'target / 'worksources / fullName.value.split('.') } def getSrcPathBase() = { - pwd / 'target / 'worksources + os.pwd / 'target / 'worksources } class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing, -- cgit v1.2.3