diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-21 23:35:52 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-21 23:35:52 -0800 |
commit | 4a0658da074bc7b7df0c5bdff90e2c6bb1977b15 (patch) | |
tree | 59d077d40a7e96b419161f5b10cb17d326a51f9f /core/src | |
parent | 3e80ade3249bc83b564d7b5bd31853c8affd555d (diff) | |
download | mill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.tar.gz mill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.tar.bz2 mill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.zip |
- Make `forkTest` and `forkRun` the default, renaming `test` and `run` to `testLocal` and `runLocal`
- Support passing `forkEnv` parameters to `test` and `run`, necessary to get Ammonite working
- Standardize signatures of `Jvm.interactiveSubprocess`/`Jvm.subprocess`
- `Jvm.inprocess` is now `Jvm.runLocal`
- Swap `TestModule.testLocal` over to using `Jvm.runLocal`, for consistency with everything else
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/mill/define/Module.scala | 3 | ||||
-rw-r--r-- | core/src/mill/main/Resolve.scala | 2 | ||||
-rw-r--r-- | core/src/mill/modules/Jvm.scala | 37 |
3 files changed, 27 insertions, 15 deletions
diff --git a/core/src/mill/define/Module.scala b/core/src/mill/define/Module.scala index 1be75e1d..222bb7ec 100644 --- a/core/src/mill/define/Module.scala +++ b/core/src/mill/define/Module.scala @@ -76,12 +76,13 @@ object Module{ // another top-level concrete `object`. This is fine for now, since Mill's Ammonite // script/REPL runner always wraps user code in a wrapper object/trait def reflectNestedObjects[T: ClassTag] = { - reflect[T] ++ + (reflect[T] ++ outer .getClass .getClasses .filter(implicitly[ClassTag[T]].runtimeClass isAssignableFrom _) .flatMap(c => c.getFields.find(_.getName == "MODULE$").map(_.get(c).asInstanceOf[T])) + ).distinct } } } diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala index d836a1a1..b01391d0 100644 --- a/core/src/mill/main/Resolve.scala +++ b/core/src/mill/main/Resolve.scala @@ -46,7 +46,7 @@ object Resolve { val command = invokeCommand(obj, last).headOption - command orElse target orElse runDefault.headOption.flatten match{ + command orElse target orElse runDefault.flatten.headOption match{ case None => Left("Cannot resolve task " + Segments((Segment.Label(last) :: revSelectorsSoFar).reverse:_*).render ) diff --git a/core/src/mill/modules/Jvm.scala b/core/src/mill/modules/Jvm.scala index fdd928d7..7f2ca4dd 100644 --- a/core/src/mill/modules/Jvm.scala +++ b/core/src/mill/modules/Jvm.scala @@ -33,17 +33,26 @@ object Jvm { def interactiveSubprocess(mainClass: String, classPath: Agg[Path], - options: Seq[String] = Seq.empty): Unit = { + jvmArgs: Seq[String] = Seq.empty, + envArgs: Map[String, String] = Map.empty, + mainArgs: Seq[String] = Seq.empty, + workingDir: Path = null): Unit = { import ammonite.ops.ImplicitWd._ - %("java", "-cp", classPath.mkString(":"), mainClass, options) + val commandArgs = + Vector("java") ++ + jvmArgs ++ + Vector("-cp", classPath.mkString(":"), mainClass) ++ + mainArgs + + %.copy(envArgs = envArgs)(commandArgs)(workingDir) } - def inprocess(mainClass: String, - classPath: Agg[Path], - options: Seq[String] = Seq.empty) - (implicit ctx: Ctx): Unit = { + def runLocal(mainClass: String, + classPath: Agg[Path], + mainArgs: Seq[String] = Seq.empty) + (implicit ctx: Ctx): Unit = { inprocess(classPath, classLoaderOverrideSbtTesting = false, cl => { - getMainMethod(mainClass, cl).invoke(null, options.toArray) + getMainMethod(mainClass, cl).invoke(null, mainArgs.toArray) }) } @@ -95,27 +104,29 @@ object Jvm { def subprocess(mainClass: String, classPath: Agg[Path], - jvmOptions: Seq[String] = Seq.empty, - options: Seq[String] = Seq.empty, + jvmArgs: Seq[String] = Seq.empty, + envArgs: Map[String, String] = Map.empty, + mainArgs: Seq[String] = Seq.empty, workingDir: Path = null) (implicit ctx: Ctx) = { val commandArgs = Vector("java") ++ - jvmOptions ++ + jvmArgs ++ Vector("-cp", classPath.mkString(":"), mainClass) ++ - options + mainArgs val workingDir1 = Option(workingDir).getOrElse(ctx.dest) mkdir(workingDir1) - val proc = + val builder = new java.lang.ProcessBuilder() .directory(workingDir1.toIO) .command(commandArgs:_*) .redirectOutput(ProcessBuilder.Redirect.PIPE) .redirectError(ProcessBuilder.Redirect.PIPE) - .start() + for((k, v) <- envArgs) builder.environment().put(k, v) + val proc = builder.start() val stdout = proc.getInputStream val stderr = proc.getErrorStream val sources = Seq( |