summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-11-05 03:00:04 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-11-05 21:14:58 +0800
commitbc9dc386625021fec517f2dbf0644ccafe1e32c2 (patch)
tree12db6817470708c7aa274aa231ef35eb79f2123a /main/src
parent8afe79afe33be68f59f89b8410984e508c3e8d08 (diff)
downloadmill-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 'main/src')
-rw-r--r--main/src/mill/MillMain.scala7
-rw-r--r--main/src/mill/main/MainModule.scala7
-rw-r--r--main/src/mill/main/MainRunner.scala9
-rw-r--r--main/src/mill/main/ReplApplyHandler.scala3
-rw-r--r--main/src/mill/main/RunScript.scala19
-rw-r--r--main/src/mill/main/VisualizeModule.scala5
-rw-r--r--main/src/mill/modules/Assembly.scala17
-rw-r--r--main/src/mill/modules/Jvm.scala131
-rw-r--r--main/src/mill/modules/Util.scala21
9 files changed, 104 insertions, 115 deletions
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(