diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-06 20:53:29 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-06 20:54:04 -0800 |
commit | 7239d6bd64ec0d025686f5f97aaaf94b7ab43951 (patch) | |
tree | ada5a410d1ee7d658d98e3b57e4188d013109451 /core/src/main | |
parent | 7a1b339b08a7e6b99da7d98b1856d534c207c99e (diff) | |
download | mill-7239d6bd64ec0d025686f5f97aaaf94b7ab43951.tar.gz mill-7239d6bd64ec0d025686f5f97aaaf94b7ab43951.tar.bz2 mill-7239d6bd64ec0d025686f5f97aaaf94b7ab43951.zip |
Explicitly pass built compiler-bridge jar locations from the build system into Mill as JVM properties.
This makes the dependency between the compiler-bridge jar and the Mill executable explicit, allowing us to swap out the locations compiler-bridge jars (which end up in different places, depending on whether you're building with SBT or Mill) or eventually making them load from Maven Central in a "release" Mill executable
Since Mill (and uTest) both do not support SBT-style test arguments, we need to use `forkTest` instead of `test` to run the Mill tests passing the compiler-jar locations as JVM props. This necessitated some fixes to make `forkTest` behave properly
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/scala/mill/modules/Jvm.scala | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala index 43382b8d..ddc8b427 100644 --- a/core/src/main/scala/mill/modules/Jvm.scala +++ b/core/src/main/scala/mill/modules/Jvm.scala @@ -1,6 +1,7 @@ package mill.modules import java.io.FileOutputStream +import java.net.URLClassLoader import java.nio.file.attribute.PosixFilePermission import java.util.jar.{JarEntry, JarFile, JarOutputStream} @@ -14,16 +15,35 @@ import scala.collection.mutable object Jvm { - + def gatherClassloaderJars(): Seq[Path] = { + val allJars = collection.mutable.Buffer.empty[Path] + var currentClassloader = Thread.currentThread().getContextClassLoader + while(currentClassloader != null){ + currentClassloader match{ + case u: URLClassLoader => allJars.appendAll(u.getURLs.map(x => Path(x.getFile))) + case _ => + } + currentClassloader = currentClassloader.getParent + } + allJars + } def subprocess(mainClass: String, classPath: Seq[Path], + jvmOptions: Seq[String] = Seq.empty, options: Seq[String] = Seq.empty, workingDir: Path = ammonite.ops.pwd) (implicit ctx: Ctx) = { + + val commandArgs = + Vector("java") ++ + jvmOptions ++ + Vector("-cp", classPath.mkString(":"), mainClass) ++ + options + val proc = new java.lang.ProcessBuilder() .directory(workingDir.toIO) - .command(Vector("java", "-cp", classPath.mkString(":"), mainClass) ++ options:_*) + .command(commandArgs:_*) .redirectOutput(ProcessBuilder.Redirect.PIPE) .redirectError(ProcessBuilder.Redirect.PIPE) .start() |