diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-11-05 03:00:04 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-11-05 21:14:58 +0800 |
commit | bc9dc386625021fec517f2dbf0644ccafe1e32c2 (patch) | |
tree | 12db6817470708c7aa274aa231ef35eb79f2123a /scalalib | |
parent | 8afe79afe33be68f59f89b8410984e508c3e8d08 (diff) | |
download | mill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.tar.gz mill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.tar.bz2 mill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.zip |
WIP migrating over from `ammonite.ops` to `os` module.
__.compile works, haven't run tests yet
Diffstat (limited to 'scalalib')
18 files changed, 226 insertions, 243 deletions
diff --git a/scalalib/src/mill/scalalib/GenIdeaImpl.scala b/scalalib/src/mill/scalalib/GenIdeaImpl.scala index b4f77f16..87b039df 100644 --- a/scalalib/src/mill/scalalib/GenIdeaImpl.scala +++ b/scalalib/src/mill/scalalib/GenIdeaImpl.scala @@ -1,6 +1,5 @@ package mill.scalalib -import ammonite.ops._ import ammonite.runtime.SpecialClassLoader import coursier.{Cache, CoursierPaths, Repository} import mill.define._ @@ -34,21 +33,21 @@ object GenIdeaImpl { discover: Discover[_]): Unit = { val pp = new scala.xml.PrettyPrinter(999, 4) - val jdkInfo = extractCurrentJdk(pwd / ".idea" / "misc.xml").getOrElse(("JDK_1_8", "1.8 (1)")) + val jdkInfo = extractCurrentJdk(os.pwd / ".idea" / "misc.xml").getOrElse(("JDK_1_8", "1.8 (1)")) - rm! pwd/".idea"/"libraries" - rm! pwd/".idea"/"scala_compiler.xml" - rm! pwd/".idea_modules" + os.remove.all(os.pwd/".idea"/"libraries") + os.remove.all(os.pwd/".idea"/"scala_compiler.xml") + os.remove.all(os.pwd/".idea_modules") - val evaluator = new Evaluator(ctx.home, pwd / 'out, pwd / 'out, rootModule, ctx.log) + val evaluator = new Evaluator(ctx.home, os.pwd / 'out, os.pwd / 'out, rootModule, ctx.log) for((relPath, xml) <- xmlFileLayout(evaluator, rootModule, jdkInfo)){ - write.over(pwd/relPath, pp.format(xml)) + os.write.over(os.pwd/relPath, pp.format(xml)) } } - def extractCurrentJdk(ideaPath: Path): Option[(String,String)] = { + def extractCurrentJdk(ideaPath: os.Path): Option[(String,String)] = { import scala.xml.XML Try { val xml = XML.loadFile(ideaPath.toString) @@ -62,7 +61,7 @@ object GenIdeaImpl { def xmlFileLayout(evaluator: Evaluator, rootModule: mill.Module, jdkInfo: (String,String), - fetchMillModules: Boolean = true): Seq[(RelPath, scala.xml.Node)] = { + fetchMillModules: Boolean = true): Seq[(os.RelPath, scala.xml.Node)] = { val modules = rootModule.millInternal.segmentsToModules.values .collect{ case x: scalalib.JavaModule => (x.millModuleSegments, x)} @@ -71,7 +70,7 @@ object GenIdeaImpl { val buildLibraryPaths = if (!fetchMillModules) Nil else sys.props.get("MILL_BUILD_LIBRARIES") match { - case Some(found) => found.split(',').map(Path(_)).distinct.toList + case Some(found) => found.split(',').map(os.Path(_)).distinct.toList case None => val repos = modules.foldLeft(Set.empty[Repository]) { _ ++ _._2.repositories } val artifactNames = Seq("main-moduledefs", "main-core", "scalalib", "scalajslib") @@ -91,7 +90,7 @@ object GenIdeaImpl { .asInstanceOf[SpecialClassLoader] ).map { _.allJars - .map(url => Path(url.getFile)) + .map(url => os.Path(url.getFile)) .filter(_.toIO.exists) }.getOrElse(Seq()) @@ -138,8 +137,8 @@ object GenIdeaImpl { val commonPrefix = if (allResolved.isEmpty) 0 else { - val minResolvedLength = allResolved.map(_.segments.length).min - allResolved.map(_.segments.take(minResolvedLength)) + val minResolvedLength = allResolved.map(_.segmentCount).min + allResolved.map(_.segments.take(minResolvedLength).toList) .transpose .takeWhile(_.distinct.length == 1) .length @@ -148,37 +147,37 @@ object GenIdeaImpl { // only resort to full long path names if the jar name is a duplicate val pathShortLibNameDuplicate = allResolved .distinct - .map{p => p.segments.last -> p} + .map{p => p.last -> p} .groupBy(_._1) .filter(_._2.size > 1) .keySet val pathToLibName = allResolved .map{p => - if (pathShortLibNameDuplicate(p.segments.last)) + if (pathShortLibNameDuplicate(p.last)) (p, p.segments.drop(commonPrefix).mkString("_")) else - (p, p.segments.last) + (p, p.last) } .toMap - sealed trait ResolvedLibrary { def path : Path } - case class CoursierResolved(path : Path, pom : Path, sources : Option[Path]) + sealed trait ResolvedLibrary { def path : os.Path } + case class CoursierResolved(path : os.Path, pom : os.Path, sources : Option[os.Path]) extends ResolvedLibrary - case class OtherResolved(path : Path) extends ResolvedLibrary + case class OtherResolved(path : os.Path) extends ResolvedLibrary // Tries to group jars with their poms and sources. - def toResolvedJar(path : Path) : Option[ResolvedLibrary] = { - val inCoursierCache = path.startsWith(Path(CoursierPaths.cacheDirectory())) - val isSource = path.segments.last.endsWith("sources.jar") + def toResolvedJar(path : os.Path) : Option[ResolvedLibrary] = { + val inCoursierCache = path.startsWith(os.Path(CoursierPaths.cacheDirectory())) + val isSource = path.last.endsWith("sources.jar") val isPom = path.ext == "pom" if (inCoursierCache && (isSource || isPom)) { // Remove sources and pom as they'll be recovered from the jar path None } else if (inCoursierCache && path.ext == "jar") { - val withoutExt = path.segments.last.dropRight(path.ext.length + 1) - val pom = path / up / s"$withoutExt.pom" - val sources = Some(path / up / s"$withoutExt-sources.jar") + val withoutExt = path.last.dropRight(path.ext.length + 1) + val pom = path / os.up / s"$withoutExt.pom" + val sources = Some(path / os.up / s"$withoutExt-sources.jar") .filter(_.toIO.exists()) Some(CoursierResolved(path, pom, sources)) } else Some(OtherResolved(path)) @@ -186,7 +185,7 @@ object GenIdeaImpl { // Hack so that Intellij does not complain about unresolved magic // imports in build.sc when in fact they are resolved - def sbtLibraryNameFromPom(pom : Path) : String = { + def sbtLibraryNameFromPom(pom : os.Path) : String = { val xml = scala.xml.XML.loadFile(pom.toIO) val groupId = (xml \ "groupId").text @@ -206,12 +205,12 @@ object GenIdeaImpl { pathToLibName(path) } - def resolvedLibraries(resolved : Seq[Path]) : Seq[ResolvedLibrary] = resolved + def resolvedLibraries(resolved : Seq[os.Path]) : Seq[ResolvedLibrary] = resolved .map(toResolvedJar) .collect { case Some(r) => r} val compilerSettings = resolved - .foldLeft(Map[(Loose.Agg[Path], Seq[String]), Vector[JavaModule]]()) { + .foldLeft(Map[(Loose.Agg[os.Path], Seq[String]), Vector[JavaModule]]()) { (r, q) => val key = (q._4, q._5) r + (key -> (r.getOrElse(key, Vector()) :+ q._3)) @@ -221,10 +220,10 @@ object GenIdeaImpl { resolvedLibraries(buildLibraryPaths ++ buildDepsPaths).toSet val fixedFiles = Seq( - Tuple2(".idea"/"misc.xml", miscXmlTemplate(jdkInfo)), - Tuple2(".idea"/"scala_settings.xml", scalaSettingsTemplate()), + Tuple2(os.rel/".idea"/"misc.xml", miscXmlTemplate(jdkInfo)), + Tuple2(os.rel/".idea"/"scala_settings.xml", scalaSettingsTemplate()), Tuple2( - ".idea"/"modules.xml", + os.rel/".idea"/"modules.xml", allModulesXmlTemplate( modules .filter(!_._2.skipIdea) @@ -232,14 +231,14 @@ object GenIdeaImpl { ) ), Tuple2( - ".idea_modules"/"mill-build.iml", + os.rel/".idea_modules"/"mill-build.iml", rootXmlTemplate( for(lib <- allBuildLibraries) yield libraryName(lib) ) ), Tuple2( - ".idea"/"scala_compiler.xml", + os.rel/".idea"/"scala_compiler.xml", scalaCompilerTemplate(compilerSettings) ) ) @@ -252,7 +251,7 @@ object GenIdeaImpl { case CoursierResolved(_, _, s) => s.map(p => "jar://" + p + "!/") case OtherResolved(_) => None } - Tuple2(".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, url, sources)) + Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, url, sources)) } val moduleFiles = resolved.map{ case (path, resolvedDeps, mod, _, _) => @@ -293,7 +292,7 @@ object GenIdeaImpl { Strict.Agg.from(mod.moduleDeps.map{ m => moduleName(moduleLabels(m))}.distinct), isTest ) - Tuple2(".idea_modules"/s"${moduleName(path)}.iml", elem) + Tuple2(os.rel/".idea_modules"/s"${moduleName(path)}.iml", elem) } fixedFiles ++ libraries ++ moduleFiles @@ -306,8 +305,8 @@ object GenIdeaImpl { } } - def relify(p: Path) = { - val r = p.relativeTo(pwd/".idea_modules") + def relify(p: os.Path) = { + val r = p.relativeTo(os.pwd/".idea_modules") (Seq.fill(r.ups)("..") ++ r.segments).mkString("/") } @@ -387,13 +386,13 @@ object GenIdeaImpl { </library> </component> } - def moduleXmlTemplate(basePath: Path, + def moduleXmlTemplate(basePath: os.Path, scalaVersionOpt: Option[String], - resourcePaths: Strict.Agg[Path], - normalSourcePaths: Strict.Agg[Path], - generatedSourcePaths: Strict.Agg[Path], - compileOutputPath: Path, - generatedSourceOutputPath: Path, + resourcePaths: Strict.Agg[os.Path], + normalSourcePaths: Strict.Agg[os.Path], + generatedSourcePaths: Strict.Agg[os.Path], + compileOutputPath: os.Path, + generatedSourceOutputPath: os.Path, libNames: Strict.Agg[String], depNames: Strict.Agg[String], isTest: Boolean @@ -447,7 +446,7 @@ object GenIdeaImpl { </component> </module> } - def scalaCompilerTemplate(settings: Map[(Loose.Agg[Path], Seq[String]), Seq[JavaModule]]) = { + def scalaCompilerTemplate(settings: Map[(Loose.Agg[os.Path], Seq[String]), Seq[JavaModule]]) = { <project version="4"> <component name="ScalaCompilerConfiguration"> diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 111cfdb2..387011ec 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -1,8 +1,6 @@ package mill package scalalib - -import ammonite.ops._ import coursier.Repository import mill.define.Task import mill.define.TaskModule @@ -199,12 +197,12 @@ trait JavaModule extends mill.Module with TaskModule { outer => * All individual source files fed into the compiler */ def allSourceFiles = T{ - def isHiddenFile(path: Path) = path.segments.last.startsWith(".") + def isHiddenFile(path: os.Path) = path.last.startsWith(".") for { root <- allSources() - if exists(root.path) - path <- (if (root.path.isDir) ls.rec(root.path) else Seq(root.path)) - if path.isFile && ((path.ext == "scala" || path.ext == "java") && !isHiddenFile(path)) + if os.exists(root.path) + path <- (if (os.isDir(root.path)) os.walk(root.path) else Seq(root.path)) + if os.isFile(path) && ((path.ext == "scala" || path.ext == "java") && !isHiddenFile(path)) } yield PathRef(path) } @@ -293,7 +291,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => */ def jar = T{ createJar( - localClasspath().map(_.path).filter(exists), + localClasspath().map(_.path).filter(os.exists), mainClass() ) } @@ -306,13 +304,13 @@ trait JavaModule extends mill.Module with TaskModule { outer => val outDir = T.ctx().dest val javadocDir = outDir / 'javadoc - mkdir(javadocDir) + os.makeDir.all(javadocDir) val files = for{ ref <- allSources() - if exists(ref.path) - p <- (if (ref.path.isDir) ls.rec(ref.path) else Seq(ref.path)) - if p.isFile && (p.ext == "java") + if os.exists(ref.path) + p <- (if (os.isDir(ref.path)) os.walk(ref.path) else Seq(ref.path)) + if os.isFile(p) && (p.ext == "java") } yield p.toNIO.toString val options = Seq("-d", javadocDir.toNIO.toString) @@ -340,7 +338,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => * The source jar, containing only source code for publishing to Maven Central */ def sourceJar = T { - createJar((allSources() ++ resources()).map(_.path).filter(exists)) + createJar((allSources() ++ resources()).map(_.path).filter(os.exists)) } /** @@ -409,12 +407,12 @@ trait JavaModule extends mill.Module with TaskModule { outer => forkEnv(), args, workingDir = forkWorkingDir() - )) catch { case e: InteractiveShelloutException => + )) catch { case e: Exception => Result.Failure("subprocess failed") } } - private[this] def backgroundSetup(dest: Path) = { + private[this] def backgroundSetup(dest: os.Path) = { val token = java.util.UUID.randomUUID().toString val procId = dest / ".mill-background-process-id" val procTombstone = dest / ".mill-background-process-tombstone" @@ -432,9 +430,9 @@ trait JavaModule extends mill.Module with TaskModule { outer => // killed via some other means, and continue anyway. val start = System.currentTimeMillis() while({ - if (exists(procTombstone)) { + if (os.exists(procTombstone)) { Thread.sleep(10) - rm(procTombstone) + os.remove.all(procTombstone) true } else { Thread.sleep(10) @@ -442,8 +440,8 @@ trait JavaModule extends mill.Module with TaskModule { outer => } })() - write(procId, token) - write(procTombstone, token) + os.write(procId, token) + os.write(procTombstone, token) (procId, procTombstone, token) } @@ -468,7 +466,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => Seq(procId.toString, procTombstone.toString, token, finalMainClass()) ++ args, workingDir = forkWorkingDir(), background = true - )) catch { case e: InteractiveShelloutException => + )) catch { case e: Exception => Result.Failure("subprocess failed") } } @@ -486,7 +484,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => Seq(procId.toString, procTombstone.toString, token, mainClass) ++ args, workingDir = forkWorkingDir(), background = true - )) catch { case e: InteractiveShelloutException => + )) catch { case e: Exception => Result.Failure("subprocess failed") } } @@ -513,7 +511,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => forkEnv(), args, workingDir = forkWorkingDir() - )) catch { case e: InteractiveShelloutException => + )) catch { case e: Exception => Result.Failure("subprocess failed") } } @@ -524,7 +522,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => def artifactId: T[String] = artifactName() - def intellijModulePath: Path = millSourcePath + def intellijModulePath: os.Path = millSourcePath def forkWorkingDir = T{ ammonite.ops.pwd } diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 17eeba3e..80723637 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -7,7 +7,6 @@ import java.lang.reflect.Modifier import java.util.zip.ZipInputStream import javax.tools.ToolProvider -import ammonite.ops._ import ammonite.util.Util import coursier.{Cache, Dependency, Fetch, Repository, Resolution} import Dep.isDotty @@ -23,8 +22,8 @@ object CompilationResult { implicit val jsonFormatter: upickle.default.ReadWriter[CompilationResult] = upickle.default.macroRW } -// analysisFile is represented by Path, so we won't break caches after file changes -case class CompilationResult(analysisFile: Path, classes: PathRef) +// analysisFile is represented by os.Path, so we won't break caches after file changes +case class CompilationResult(analysisFile: os.Path, classes: PathRef) object Lib{ private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r @@ -40,7 +39,7 @@ object Lib{ } } - def grepJar(classPath: Agg[Path], name: String, version: String, sources: Boolean = false) = { + def grepJar(classPath: Agg[os.Path], name: String, version: String, sources: Boolean = false) = { val suffix = if (sources) "-sources" else "" val mavenStylePath = s"$name-$version$suffix.jar" val ivyStylePath = { @@ -111,22 +110,22 @@ object Lib{ ivy"$scalaOrganization:scala-library:$scalaVersion".forceVersion() ) - def listClassFiles(base: Path): Iterator[String] = { - if (base.isDir) ls.rec(base).toIterator.filter(_.ext == "class").map(_.relativeTo(base).toString) + def listClassFiles(base: os.Path): Iterator[String] = { + if (os.isDir(base)) os.walk(base).toIterator.filter(_.ext == "class").map(_.relativeTo(base).toString) else { val zip = new ZipInputStream(new FileInputStream(base.toIO)) Iterator.continually(zip.getNextEntry).takeWhile(_ != null).map(_.getName).filter(_.endsWith(".class")) } } - def discoverTests(cl: ClassLoader, framework: Framework, classpath: Agg[Path]) = { + def discoverTests(cl: ClassLoader, framework: Framework, classpath: Agg[os.Path]) = { val fingerprints = framework.fingerprints() val testClasses = classpath.flatMap { base => // Don't blow up if there are no classfiles representing // the tests to run Instead just don't run anything - if (!exists(base)) Nil + if (!os.exists(base)) Nil else listClassFiles(base).flatMap { path => val cls = cl.loadClass(path.stripSuffix(".class").replace('/', '.')) val publicConstructorCount = diff --git a/scalalib/src/mill/scalalib/MiscModule.scala b/scalalib/src/mill/scalalib/MiscModule.scala index 02a6ebf9..c6449d6e 100644 --- a/scalalib/src/mill/scalalib/MiscModule.scala +++ b/scalalib/src/mill/scalalib/MiscModule.scala @@ -1,13 +1,12 @@ package mill package scalalib -import ammonite.ops.{Path, RelPath} import mill.define.Cross.Resolver import mill.define.{Cross, Task} import mill.eval.{PathRef, Result} import mill.util.Loose.Agg object CrossModuleBase{ - def scalaVersionPaths(scalaVersion: String, f: String => Path) = { + def scalaVersionPaths(scalaVersion: String, f: String => os.Path) = { for(segments <- scalaVersion.split('.').inits.filter(_.nonEmpty)) yield PathRef(f(segments.mkString("."))) } diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala index 5c567452..a3d0856f 100644 --- a/scalalib/src/mill/scalalib/PublishModule.scala +++ b/scalalib/src/mill/scalalib/PublishModule.scala @@ -1,7 +1,6 @@ package mill package scalalib -import ammonite.ops._ import mill.define.{ExternalModule, Task} import mill.eval.PathRef import mill.scalalib.publish.{Artifact, SonatypePublisher} @@ -29,14 +28,14 @@ trait PublishModule extends JavaModule { outer => def pom = T { val pom = Pom(artifactMetadata(), publishXmlDeps(), artifactId(), pomSettings()) val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom" - write.over(pomPath, pom) + os.write.over(pomPath, pom) PathRef(pomPath) } def ivy = T { val ivy = Ivy(artifactMetadata(), publishXmlDeps()) val ivyPath = T.ctx().dest / "ivy.xml" - write.over(ivyPath, ivy) + os.write.over(ivyPath, ivy) PathRef(ivyPath) } @@ -103,7 +102,7 @@ object PublishModule extends ExternalModule { sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots", signed: Boolean = true) = T.command { - val x: Seq[(Seq[(Path, String)], Artifact)] = Task.sequence(publishArtifacts.value)().map{ + val x: Seq[(Seq[(os.Path, String)], Artifact)] = Task.sequence(publishArtifacts.value)().map{ case PublishModule.PublishData(a, s) => (s.map{case (p, f) => (p.path, f)}, a) } new SonatypePublisher( diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 3c058013..80caf6a9 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -1,7 +1,6 @@ package mill package scalalib -import ammonite.ops._ import coursier.Repository import mill.define.{Target, Task, TaskModule} import mill.eval.{PathRef, Result} @@ -171,7 +170,7 @@ trait ScalaModule extends JavaModule { outer => val outDir = T.ctx().dest val javadocDir = outDir / 'javadoc - mkdir(javadocDir) + os.makeDir.all(javadocDir) val files = allSourceFiles().map(_.path.toString) @@ -215,7 +214,7 @@ trait ScalaModule extends JavaModule { outer => "scala.tools.nsc.MainGenericRunner", classPath = runClasspath().map(_.path) ++ scalaCompilerClasspath().map(_.path), mainArgs = Seq("-usejavacp"), - workingDir = pwd + workingDir = os.pwd ) Result.Success() } @@ -246,7 +245,7 @@ trait ScalaModule extends JavaModule { outer => mainClass = "ammonite.Main", classPath = ammoniteReplClasspath().map(_.path), mainArgs = replOptions, - workingDir = pwd + workingDir = os.pwd ) Result.Success() } diff --git a/scalalib/src/mill/scalalib/TestRunner.scala b/scalalib/src/mill/scalalib/TestRunner.scala index 0b9c897f..42e65d63 100644 --- a/scalalib/src/mill/scalalib/TestRunner.scala +++ b/scalalib/src/mill/scalalib/TestRunner.scala @@ -1,5 +1,4 @@ package mill.scalalib -import ammonite.ops.Path import ammonite.util.Colors import mill.Agg import mill.modules.Jvm @@ -40,12 +39,12 @@ object TestRunner { System.in, debugEnabled = false ) - val home = Path(homeStr) + val home = os.Path(homeStr) } val result = runTests( frameworkInstances = TestRunner.frameworks(frameworks), - entireClasspath = Agg.from(classpath.map(Path(_))), - testClassfilePath = Agg(Path(testCp)), + entireClasspath = Agg.from(classpath.map(os.Path(_))), + testClassfilePath = Agg(os.Path(testCp)), args = arguments )(ctx) @@ -53,7 +52,7 @@ object TestRunner { // dirtied the thread-interrupted flag and forgot to clean up. Otherwise // that flag causes writing the results to disk to fail Thread.interrupted() - ammonite.ops.write(Path(outputPath), upickle.default.write(result)) + ammonite.ops.write(os.Path(outputPath), upickle.default.write(result)) }catch{case e: Throwable => println(e) e.printStackTrace() @@ -65,8 +64,8 @@ object TestRunner { } def runTests(frameworkInstances: ClassLoader => Seq[sbt.testing.Framework], - entireClasspath: Agg[Path], - testClassfilePath: Agg[Path], + entireClasspath: Agg[os.Path], + testClassfilePath: Agg[os.Path], args: Seq[String]) (implicit ctx: Ctx.Log with Ctx.Home): (String, Seq[mill.scalalib.TestRunner.Result]) = { //Leave the context class loader set and open so that shutdown hooks can access it diff --git a/scalalib/src/mill/scalalib/ZincWorkerApi.scala b/scalalib/src/mill/scalalib/ZincWorkerApi.scala index 8e95eb29..dbcaa6da 100644 --- a/scalalib/src/mill/scalalib/ZincWorkerApi.scala +++ b/scalalib/src/mill/scalalib/ZincWorkerApi.scala @@ -1,7 +1,5 @@ package mill.scalalib - -import ammonite.ops.Path import coursier.Cache import coursier.maven.MavenRepository import mill.Agg @@ -60,30 +58,30 @@ trait ZincWorkerModule extends mill.Module{ trait ZincWorkerApi { /** Compile a Java-only project */ def compileJava(upstreamCompileOutput: Seq[CompilationResult], - sources: Agg[Path], - compileClasspath: Agg[Path], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], javacOptions: Seq[String]) (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] /** Compile a mixed Scala/Java or Scala-only project */ def compileMixed(upstreamCompileOutput: Seq[CompilationResult], - sources: Agg[Path], - compileClasspath: Agg[Path], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, scalacOptions: Seq[String], - compilerBridgeSources: Path, - compilerClasspath: Agg[Path], - scalacPluginClasspath: Agg[Path]) + compilerBridgeSources: os.Path, + compilerClasspath: Agg[os.Path], + scalacPluginClasspath: Agg[os.Path]) (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] def discoverMainClasses(compilationResult: CompilationResult) (implicit ctx: mill.util.Ctx): Seq[String] def docJar(scalaVersion: String, - compilerBridgeSources: Path, - compilerClasspath: Agg[Path], - scalacPluginClasspath: Agg[Path], + compilerBridgeSources: os.Path, + compilerClasspath: Agg[os.Path], + scalacPluginClasspath: Agg[os.Path], args: Seq[String]) (implicit ctx: mill.util.Ctx): Boolean } diff --git a/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala b/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala index abe6e012..b1033688 100644 --- a/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala +++ b/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala @@ -1,6 +1,5 @@ package mill.scalalib.dependency.versions -import ammonite.ops.pwd import mill.define.{BaseModule, Task} import mill.eval.Evaluator import mill.scalalib.dependency.metadata.MetadataLoaderFactory @@ -13,7 +12,7 @@ private[dependency] object VersionsFinder { def findVersions(ctx: Log with Home, rootModule: BaseModule): Seq[ModuleDependenciesVersions] = { val evaluator = - new Evaluator(ctx.home, pwd / 'out, pwd / 'out, rootModule, ctx.log) + new Evaluator(ctx.home, os.pwd / 'out, os.pwd / 'out, rootModule, ctx.log) val javaModules = rootModule.millInternal.modules.collect { case javaModule: JavaModule => javaModule diff --git a/scalalib/src/mill/scalalib/publish/LocalPublisher.scala b/scalalib/src/mill/scalalib/publish/LocalPublisher.scala index a8a703fc..d9839831 100644 --- a/scalalib/src/mill/scalalib/publish/LocalPublisher.scala +++ b/scalalib/src/mill/scalalib/publish/LocalPublisher.scala @@ -1,16 +1,15 @@ package mill.scalalib.publish -import ammonite.ops._ object LocalPublisher { - private val root: Path = home / ".ivy2" / "local" + private val root: os.Path = os.home / ".ivy2" / "local" - def publish(jar: Path, - sourcesJar: Path, - docJar: Path, - pom: Path, - ivy: Path, + def publish(jar: os.Path, + sourcesJar: os.Path, + docJar: os.Path, + pom: os.Path, + ivy: os.Path, artifact: Artifact): Unit = { val releaseDir = root / artifact.group / artifact.id / artifact.version writeFiles( @@ -22,11 +21,11 @@ object LocalPublisher { ) } - private def writeFiles(fromTo: (Path, Path)*): Unit = { + private def writeFiles(fromTo: (os.Path, os.Path)*): Unit = { fromTo.foreach { case (from, to) => - mkdir(to / up) - cp.over(from, to) + os.makeDir.all(to / os.up) + os.copy.over(from, to) } } diff --git a/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala b/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala index 47ec8dbf..5e596618 100644 --- a/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala +++ b/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala @@ -3,7 +3,6 @@ package mill.scalalib.publish import java.math.BigInteger import java.security.MessageDigest -import ammonite.ops._ import mill.util.Logger import scalaj.http.HttpResponse @@ -17,10 +16,10 @@ class SonatypePublisher(uri: String, private val api = new SonatypeHttpApi(uri, credentials) - def publish(fileMapping: Seq[(Path, String)], artifact: Artifact, release: Boolean): Unit = { + def publish(fileMapping: Seq[(os.Path, String)], artifact: Artifact, release: Boolean): Unit = { publishAll(release, fileMapping -> artifact) } - def publishAll(release: Boolean, artifacts: (Seq[(Path, String)], Artifact)*): Unit = { + def publishAll(release: Boolean, artifacts: (Seq[(os.Path, String)], Artifact)*): Unit = { val mappings = for ((fileMapping0, artifact) <- artifacts) yield { val publishPath = Seq( @@ -36,7 +35,7 @@ class SonatypePublisher(uri: String, artifact -> (fileMapping ++ signedArtifacts).flatMap { case (file, name) => - val content = read.bytes(file) + val content = os.read.bytes(file) Seq( name -> content, @@ -136,16 +135,17 @@ class SonatypePublisher(uri: String, } // http://central.sonatype.org/pages/working-with-pgp-signatures.html#signing-a-file - private def poorMansSign(file: Path, maybePassphrase: Option[String]): Path = { + private def poorMansSign(file: os.Path, maybePassphrase: Option[String]): os.Path = { val fileName = file.toString - import ammonite.ops.ImplicitWd._ maybePassphrase match { case Some(passphrase) => - %("gpg", "--passphrase", passphrase, "--batch", "--yes", "-a", "-b", fileName) + os.proc("gpg", "--passphrase", passphrase, "--batch", "--yes", "-a", "-b", fileName) + .call(stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit) case None => - %("gpg", "--batch", "--yes", "-a", "-b", fileName) + os.proc("gpg", "--batch", "--yes", "-a", "-b", fileName) + .call(stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit) } - Path(fileName + ".asc") + os.Path(fileName + ".asc") } private def md5hex(bytes: Array[Byte]): Array[Byte] = diff --git a/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala b/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala index 74f64e28..6a81d975 100644 --- a/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala +++ b/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala @@ -1,6 +1,5 @@ package mill.scalalib.scalafmt -import ammonite.ops.{exists, ls, pwd} import mill._ import mill.define._ import mill.scalalib._ @@ -19,7 +18,7 @@ trait ScalafmtModule extends JavaModule { def scalafmtVersion: T[String] = "1.5.1" - def scalafmtConfig: Sources = T.sources(pwd / ".scalafmt.conf") + def scalafmtConfig: Sources = T.sources(os.pwd / ".scalafmt.conf") def scalafmtDeps: T[Agg[PathRef]] = T { Lib.resolveDependencies( @@ -31,8 +30,8 @@ trait ScalafmtModule extends JavaModule { protected def filesToFormat(sources: Seq[PathRef]) = { for { - pathRef <- sources if exists(pathRef.path) - file <- ls.rec(pathRef.path) if file.isFile && file.ext == "scala" + pathRef <- sources if os.exists(pathRef.path) + file <- os.walk(pathRef.path) if os.isFile(file) && file.ext == "scala" } yield PathRef(file) } diff --git a/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala b/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala index d9921e9d..41fad45b 100644 --- a/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala +++ b/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala @@ -1,6 +1,5 @@ package mill.scalalib.scalafmt -import ammonite.ops.{Path, exists} import mill._ import mill.define.{Discover, ExternalModule, Worker} import mill.modules.Jvm @@ -15,12 +14,12 @@ object ScalafmtWorkerModule extends ExternalModule { } private[scalafmt] class ScalafmtWorker { - private val reformatted: mutable.Map[Path, Int] = mutable.Map.empty + private val reformatted: mutable.Map[os.Path, Int] = mutable.Map.empty private var configSig: Int = 0 def reformat(input: Seq[PathRef], scalafmtConfig: PathRef, - scalafmtClasspath: Agg[Path])(implicit ctx: Ctx): Unit = { + scalafmtClasspath: Agg[os.Path])(implicit ctx: Ctx): Unit = { val toFormat = if (scalafmtConfig.sig != configSig) input else @@ -43,11 +42,11 @@ private[scalafmt] class ScalafmtWorker { private val cliFlags = Seq("--non-interactive", "--quiet") - private def reformatAction(toFormat: Seq[Path], - config: Path, - classpath: Agg[Path])(implicit ctx: Ctx) = { + private def reformatAction(toFormat: Seq[os.Path], + config: os.Path, + classpath: Agg[os.Path])(implicit ctx: Ctx) = { val configFlags = - if (exists(config)) Seq("--config", config.toString) else Seq.empty + if (os.exists(config)) Seq("--config", config.toString) else Seq.empty Jvm.subprocess( "org.scalafmt.cli.Cli", classpath, diff --git a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala index db70a325..d4a8cabd 100644 --- a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala +++ b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala @@ -1,6 +1,5 @@ package mill.scalalib -import ammonite.ops._ import coursier.Cache import mill._ import mill.util.{TestEvaluator, TestUtil} @@ -8,7 +7,7 @@ import utest._ object GenIdeaTests extends TestSuite { - val millSourcePath = pwd / 'target / 'workspace / "gen-idea" + val millSourcePath = os.pwd / 'target / 'workspace / "gen-idea" trait HelloWorldModule extends scalalib.ScalaModule { def scalaVersion = "2.12.4" @@ -31,7 +30,7 @@ object GenIdeaTests extends TestSuite { HelloWorld, ("JDK_1_8", "1.8 (1)"), fetchMillModules = false) for((relPath, xml) <- layout){ - write.over(millSourcePath/ "generated"/ relPath, pp.format(xml)) + os.write.over(millSourcePath/ "generated"/ relPath, pp.format(xml)) } Seq( @@ -49,7 +48,7 @@ object GenIdeaTests extends TestSuite { millSourcePath / "generated" / ".idea" / "misc.xml" ).foreach { case (resource, generated) => val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n") - val generatedString = normaliseLibraryPaths(read! generated) + val generatedString = normaliseLibraryPaths(os.read(generated)) assert(resourceString == generatedString) } diff --git a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala index 7e044475..ff0de5a6 100644 --- a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala @@ -2,8 +2,6 @@ package mill package scalalib -import ammonite.ops.{%, %%, cp, ls, mkdir, pwd, rm, up} -import ammonite.ops.ImplicitWd._ import mill.eval.Result import mill.util.{TestEvaluator, TestUtil} import utest._ @@ -27,14 +25,14 @@ object HelloJavaTests extends TestSuite { object test extends Tests with JUnitTests } } - val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-java" + val resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-java" def init()(implicit tp: TestPath) = { val eval = new TestEvaluator(HelloJava) - rm(HelloJava.millSourcePath) - rm(eval.outPath) - mkdir(HelloJava.millSourcePath / up) - cp(resourcePath, HelloJava.millSourcePath) + os.remove.all(HelloJava.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(HelloJava.millSourcePath / os.up) + os.copy(resourcePath, HelloJava.millSourcePath) eval } def tests: Tests = Tests { @@ -49,10 +47,10 @@ object HelloJavaTests extends TestSuite { res1 == res2, n1 != 0, n2 != 0, - ls.rec(res1.classes.path).exists(_.last == "Core.class"), - !ls.rec(res1.classes.path).exists(_.last == "Main.class"), - ls.rec(res3.classes.path).exists(_.last == "Main.class"), - !ls.rec(res3.classes.path).exists(_.last == "Core.class") + os.walk(res1.classes.path).exists(_.last == "Core.class"), + !os.walk(res1.classes.path).exists(_.last == "Main.class"), + os.walk(res3.classes.path).exists(_.last == "Main.class"), + !os.walk(res3.classes.path).exists(_.last == "Core.class") ) } 'docJar - { @@ -62,8 +60,8 @@ object HelloJavaTests extends TestSuite { val Right((ref2, _)) = eval.apply(HelloJava.app.docJar) assert( - %%("jar", "tf", ref1.path).out.lines.contains("hello/Core.html"), - %%("jar", "tf", ref2.path).out.lines.contains("hello/Main.html") + os.proc("jar", "tf", ref1.path).call().out.lines.contains("hello/Core.html"), + os.proc("jar", "tf", ref2.path).call().out.lines.contains("hello/Main.html") ) } 'test - { diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 1839e275..67c4b433 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -1,8 +1,8 @@ package mill.scalalib +import java.io.ByteArrayOutputStream import java.util.jar.JarFile -import ammonite.ops._ import mill._ import mill.define.Target import mill.eval.Result.Exception @@ -265,7 +265,7 @@ object HelloWorldTests extends TestSuite { } } - val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world" + val resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world" def jarMainClass(jar: JarFile): Option[String] = { import java.util.jar.Attributes._ @@ -279,10 +279,12 @@ object HelloWorldTests extends TestSuite { def readFileFromJar(jar: JarFile, name: String): String = { val is = jar.getInputStream(jar.getEntry(name)) - read(is) + val baos = new ByteArrayOutputStream() + os.Internals.transfer(is, baos) + new String(baos.toByteArray) } - def compileClassfiles = Seq[RelPath]( + def compileClassfiles = Seq[os.RelPath]( "Main.class", "Main$.class", "Main0.class", @@ -292,14 +294,14 @@ object HelloWorldTests extends TestSuite { "Person$.class" ) - def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: Path = resourcePath) + def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: os.Path = resourcePath) (t: TestEvaluator => T) (implicit tp: TestPath): T = { val eval = new TestEvaluator(m) - rm(m.millSourcePath) - rm(eval.outPath) - mkdir(m.millSourcePath / up) - cp(resourcePath, m.millSourcePath) + os.remove.all(m.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(m.millSourcePath / os.up) + os.copy(resourcePath, m.millSourcePath) t(eval) } @@ -371,29 +373,29 @@ object HelloWorldTests extends TestSuite { // make sure options are passed during ScalaDoc generation 'docJarWithTitle - workspaceTest( HelloWorldDocTitle, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldDocTitle.core.docJar) assert( evalCount > 0, - read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-title\">Hello World") + os.read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-title\">Hello World") ) } 'docJarWithVersion - workspaceTest( HelloWorldWithDocVersion, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world" ){ eval => // scaladoc generation fails because of "-Xfatal-warnings" flag val Left(Result.Failure("docJar generation failed", None)) = eval.apply(HelloWorldWithDocVersion.core.docJar) } 'docJarOnlyVersion - workspaceTest( HelloWorldOnlyDocVersion, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldOnlyDocVersion.core.docJar) assert( evalCount > 0, - read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-version\">1.2.3") + os.read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-version\">1.2.3") ) } } @@ -426,13 +428,13 @@ object HelloWorldTests extends TestSuite { val Right((result, evalCount)) = eval.apply(HelloWorld.core.compile) val analysisFile = result.analysisFile - val outputFiles = ls.rec(result.classes.path) + val outputFiles = os.walk(result.classes.path) val expectedClassfiles = compileClassfiles.map( eval.outPath / 'core / 'compile / 'dest / 'classes / _ ) assert( result.classes.path == eval.outPath / 'core / 'compile / 'dest / 'classes, - exists(analysisFile), + os.exists(analysisFile), outputFiles.nonEmpty, outputFiles.forall(expectedClassfiles.contains), evalCount > 0 @@ -447,13 +449,13 @@ object HelloWorldTests extends TestSuite { val Right((_, freshCount)) = eval.apply(HelloWorld.core.compile) assert(freshCount > 0) - write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "\n") + os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "\n") val Right((_, incCompileCount)) = eval.apply(HelloWorld.core.compile) assert(incCompileCount > 0, incCompileCount < freshCount) } 'failOnError - workspaceTest(HelloWorld){eval => - write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ") + os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ") val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.compile) @@ -464,13 +466,13 @@ object HelloWorldTests extends TestSuite { ) assert( - ls.rec(paths.dest / 'classes).isEmpty, - !exists(paths.meta) + os.walk(paths.dest / 'classes).isEmpty, + !os.exists(paths.meta) ) // Works when fixed - write.over( + os.write.over( HelloWorld.millSourcePath / 'core / 'src / "Main.scala", - read(HelloWorld.millSourcePath / 'core / 'src / "Main.scala").dropRight("val x: ".length) + os.read(HelloWorld.millSourcePath / 'core / 'src / "Main.scala").dropRight("val x: ".length) ) val Right((result, evalCount)) = eval.apply(HelloWorld.core.compile) @@ -489,8 +491,8 @@ object HelloWorldTests extends TestSuite { assert(evalCount > 0) assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } 'runCross - { @@ -506,8 +508,8 @@ object HelloWorldTests extends TestSuite { assert( - exists(runResult), - read(runResult) == expectedOut + os.exists(runResult), + os.read(runResult) == expectedOut ) } 'v210 - TestUtil.disableInJava9OrAbove(workspaceTest(CrossHelloWorld)(cross(_, "2.10.6", "2.10.6 rox"))) @@ -522,7 +524,7 @@ object HelloWorldTests extends TestSuite { val Left(Result.Failure("subprocess failed", _)) = eval.apply(HelloWorld.core.runMain("Invalid")) } 'notRunWhenCompileFailed - workspaceTest(HelloWorld){eval => - write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ") + os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ") val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.runMain("Main")) @@ -540,13 +542,13 @@ object HelloWorldTests extends TestSuite { assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } 'notRunWithoutMainClass - workspaceTest( HelloWorldWithoutMain, - pwd / 'scalalib / 'test / 'resources / "hello-world-no-main" + os.pwd / 'scalalib / 'test / 'resources / "hello-world-no-main" ){eval => val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.run()) } @@ -563,8 +565,8 @@ object HelloWorldTests extends TestSuite { assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } } @@ -580,8 +582,8 @@ object HelloWorldTests extends TestSuite { assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } 'runWithDefaultMain - workspaceTest(HelloWorldDefaultMain){eval => @@ -594,13 +596,13 @@ object HelloWorldTests extends TestSuite { assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } 'notRunWithoutMainClass - workspaceTest( HelloWorldWithoutMain, - pwd / 'scalalib / 'test / 'resources / "hello-world-no-main" + os.pwd / 'scalalib / 'test / 'resources / "hello-world-no-main" ){eval => val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.runLocal()) @@ -612,15 +614,15 @@ object HelloWorldTests extends TestSuite { val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.jar) assert( - exists(result.path), + os.exists(result.path), evalCount > 0 ) val jarFile = new JarFile(result.path.toIO) val entries = jarFile.entries().asScala.map(_.getName).toSet - val otherFiles = Seq[RelPath]( - "META-INF" / "MANIFEST.MF", + val otherFiles = Seq[os.RelPath]( + os.rel / "META-INF" / "MANIFEST.MF", "reference.conf" ) val expectedFiles = compileClassfiles ++ otherFiles @@ -639,7 +641,7 @@ object HelloWorldTests extends TestSuite { eval.apply(HelloWorld.core.compile) val logFile = outPath / 'core / 'compile / 'log - assert(exists(logFile)) + assert(os.exists(logFile)) } } @@ -647,7 +649,7 @@ object HelloWorldTests extends TestSuite { 'assembly - workspaceTest(HelloWorldWithMain){ eval => val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly) assert( - exists(result.path), + os.exists(result.path), evalCount > 0 ) val jarFile = new JarFile(result.path.toIO) @@ -687,7 +689,7 @@ object HelloWorldTests extends TestSuite { ) } - val helloWorldMultiResourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-multi" + val helloWorldMultiResourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-multi" def checkAppendMulti[M <: TestUtil.BaseModule]( module: M, @@ -734,7 +736,7 @@ object HelloWorldTests extends TestSuite { def checkExclude[M <: TestUtil.BaseModule](module: M, target: Target[PathRef], - resourcePath: Path = resourcePath + resourcePath: os.Path = resourcePath ) = workspaceTest(module, resourcePath) { eval => val Right((result, _)) = eval.apply(target) @@ -814,16 +816,16 @@ object HelloWorldTests extends TestSuite { val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly) assert( - exists(result.path), + os.exists(result.path), evalCount > 0 ) val runResult = eval.outPath / "hello-mill" - %%("java", "-jar", result.path, runResult)(wd = eval.outPath) + os.proc("java", "-jar", result.path, runResult).call(cwd = eval.outPath) assert( - exists(runResult), - read(runResult) == "hello rockjam, your age is: 25" + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" ) } } @@ -866,7 +868,7 @@ object HelloWorldTests extends TestSuite { // make sure macros are applied when compiling/running 'runMain - workspaceTest( HelloWorldMacros, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-macros" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-macros" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldMacros.core.runMain("Main")) assert(evalCount > 0) @@ -874,7 +876,7 @@ object HelloWorldTests extends TestSuite { // make sure macros are applied when compiling during scaladoc generation 'docJar - workspaceTest( HelloWorldMacros, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-macros" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-macros" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldMacros.core.docJar) assert(evalCount > 0) @@ -885,7 +887,7 @@ object HelloWorldTests extends TestSuite { // make sure flags are passed when compiling/running 'runMain - workspaceTest( HelloWorldFlags, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-flags" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-flags" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldFlags.core.runMain("Main")) assert(evalCount > 0) @@ -893,7 +895,7 @@ object HelloWorldTests extends TestSuite { // make sure flags are passed during ScalaDoc generation 'docJar - workspaceTest( HelloWorldFlags, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-flags" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-flags" ){ eval => val Right((_, evalCount)) = eval.apply(HelloWorldFlags.core.docJar) assert(evalCount > 0) @@ -902,7 +904,7 @@ object HelloWorldTests extends TestSuite { 'scalacheck - workspaceTest( HelloScalacheck, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-scalacheck" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-scalacheck" ){ eval => val Right((res, evalCount)) = eval.apply(HelloScalacheck.foo.test.test()) assert( @@ -918,7 +920,7 @@ object HelloWorldTests extends TestSuite { 'dotty - workspaceTest( HelloDotty, - resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-dotty" + resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-dotty" ){ eval => if (isJavaAtLeast("9")) { // Skip the test because Dotty does not support Java >= 9 yet diff --git a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala index 89d549ff..dcbdb769 100644 --- a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala +++ b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala @@ -1,6 +1,5 @@ package mill.scalalib.scalafmt -import ammonite.ops._ import mill.main.Tasks import mill.scalalib.ScalaModule import mill.util.{TestEvaluator, TestUtil} @@ -20,17 +19,17 @@ object ScalafmtTests extends TestSuite { } } - val resourcePath = pwd / 'scalalib / 'test / 'resources / 'scalafmt + val resourcePath = os.pwd / 'scalalib / 'test / 'resources / 'scalafmt def workspaceTest[T]( m: TestUtil.BaseModule, - resourcePath: Path = resourcePath)(t: TestEvaluator => T)( + resourcePath: os.Path = resourcePath)(t: TestEvaluator => T)( implicit tp: TestPath): T = { val eval = new TestEvaluator(m) - rm(m.millSourcePath) - rm(eval.outPath) - mkdir(m.millSourcePath / up) - cp(resourcePath, m.millSourcePath) + os.remove.all(m.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(m.millSourcePath / os.up) + os.copy(resourcePath, m.millSourcePath) t(eval) } @@ -68,7 +67,7 @@ object ScalafmtTests extends TestSuite { ) // reformat after change - write.over(cached("Main.scala").path, + os.write.over(cached("Main.scala").path, cached("Main.scala").content + "\n object Foo") val Right(_) = eval.apply(reformatCommand) @@ -89,16 +88,16 @@ object ScalafmtTests extends TestSuite { } } - case class FileInfo(content: String, modifyTime: Long, path: Path) + case class FileInfo(content: String, modifyTime: Long, path: os.Path) def getProjectFiles(m: ScalaModule, eval: TestEvaluator) = { val Right((sources, _)) = eval.apply(m.sources) val Right((resources, _)) = eval.apply(m.resources) - val sourcesFiles = sources.flatMap(p => ls.rec(p.path)) - val resourcesFiles = resources.flatMap(p => ls.rec(p.path)) + val sourcesFiles = sources.flatMap(p => os.walk(p.path)) + val resourcesFiles = resources.flatMap(p => os.walk(p.path)) (sourcesFiles ++ resourcesFiles).map { p => - p.name -> FileInfo(read(p), p.mtime.toMillis, p) + p.last -> FileInfo(os.read(p), os.mtime(p), p) }.toMap } diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index 78595b14..d494760e 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -3,7 +3,6 @@ package mill.scalalib.worker import java.io.File import java.util.Optional -import ammonite.ops.{Path, exists, ls, mkdir} import ammonite.util.Colors import mill.Agg import mill.eval.PathRef @@ -50,9 +49,9 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, @volatile var mixedCompilersCache = Option.empty[(Long, Compilers)] def docJar(scalaVersion: String, - compilerBridgeSources: Path, - compilerClasspath: Agg[Path], - scalacPluginClasspath: Agg[Path], + compilerBridgeSources: os.Path, + compilerClasspath: Agg[os.Path], + scalacPluginClasspath: Agg[os.Path], args: Seq[String]) (implicit ctx: mill.util.Ctx): Boolean = { val compilers: Compilers = prepareCompilers( @@ -69,16 +68,16 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, * TODO: Proper invalidation, see #389 */ def compileZincBridgeIfNeeded(scalaVersion: String, - sourcesJar: Path, - compilerJars: Array[File]): Path = { + sourcesJar: os.Path, + compilerJars: Array[File]): os.Path = { val workingDir = ctx0.dest / scalaVersion val compiledDest = workingDir / 'compiled - if (!exists(workingDir)) { + if (!os.exists(workingDir)) { ctx0.log.info("Compiling compiler interface...") - mkdir(workingDir) - mkdir(compiledDest) + os.makeDir.all(workingDir) + os.makeDir.all(compiledDest) val sourceFolder = mill.modules.Util.unpackZip(sourcesJar)(workingDir) val classloader = mill.util.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0) @@ -91,7 +90,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, val argsArray = Array[String]( "-d", compiledDest.toString, "-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(File.pathSeparator) - ) ++ ls.rec(sourceFolder.path).filter(_.ext == "scala").map(_.toString) + ) ++ os.walk(sourceFolder.path).filter(_.ext == "scala").map(_.toString) compilerMain.getMethod("process", classOf[Array[String]]) .invoke(null, argsArray) @@ -116,8 +115,8 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, } def compileJava(upstreamCompileOutput: Seq[CompilationResult], - sources: Agg[Path], - compileClasspath: Agg[Path], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], javacOptions: Seq[String]) (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { compileInternal( @@ -131,14 +130,14 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, } def compileMixed(upstreamCompileOutput: Seq[CompilationResult], - sources: Agg[Path], - compileClasspath: Agg[Path], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, scalacOptions: Seq[String], - compilerBridgeSources: Path, - compilerClasspath: Agg[Path], - scalacPluginClasspath: Agg[Path]) + compilerBridgeSources: os.Path, + compilerClasspath: Agg[os.Path], + scalacPluginClasspath: Agg[os.Path]) (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { val compilers: Compilers = prepareCompilers( scalaVersion, @@ -158,9 +157,9 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, } private def prepareCompilers(scalaVersion: String, - compilerBridgeSources: Path, - compilerClasspath: Agg[Path], - scalacPluginClasspath: Agg[Path]) + compilerBridgeSources: os.Path, + compilerClasspath: Agg[os.Path], + scalacPluginClasspath: Agg[os.Path]) (implicit ctx: mill.util.Ctx)= { val combinedCompilerClasspath = compilerClasspath ++ scalacPluginClasspath val combinedCompilerJars = combinedCompilerClasspath.toArray.map(_.toIO) @@ -170,11 +169,11 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, compilerBridgeSources, compilerClasspath.toArray.map(_.toIO) ) - val compilerBridgeSig = compilerBridge.mtime.toMillis + val compilerBridgeSig = os.mtime(compilerBridge) val compilersSig = compilerBridgeSig + - combinedCompilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum + combinedCompilerClasspath.map(p => p.toString().hashCode + os.mtime(p)).sum val compilers = mixedCompilersCache match { case Some((k, v)) if k == compilersSig => v @@ -205,13 +204,13 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, } private def compileInternal(upstreamCompileOutput: Seq[CompilationResult], - sources: Agg[Path], - compileClasspath: Agg[Path], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalacOptions: Seq[String], compilers: Compilers) (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { - mkdir(ctx.dest) + os.makeDir.all(ctx.dest) val logger = { val consoleAppender = MainAppender.defaultScreen(ConsoleOut.printStreamOut( |