diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-07 19:49:53 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-07 19:49:53 -0700 |
commit | 2d72abe64de8dbd98cabc688ce4bb57f733a1d12 (patch) | |
tree | 8077b61a6aabbec9675834f9cf9deb5711318b6d /scalalib/src | |
parent | 19021b773438e24da47f6d0e94e69e5f58625cac (diff) | |
download | mill-2d72abe64de8dbd98cabc688ce4bb57f733a1d12.tar.gz mill-2d72abe64de8dbd98cabc688ce4bb57f733a1d12.tar.bz2 mill-2d72abe64de8dbd98cabc688ce4bb57f733a1d12.zip |
migrate client module onto new JavaModule trait
Diffstat (limited to 'scalalib/src')
-rw-r--r-- | scalalib/src/mill/scalalib/JavaModule.scala | 3 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/Lib.scala | 25 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaModule.scala | 2 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaWorkerApi.scala | 5 |
4 files changed, 28 insertions, 7 deletions
diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index e2b461b5..f7dc48fa 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -17,7 +17,6 @@ import mill.util.Loose.Agg * Core configuration required to compile a single Scala compilation target */ trait JavaModule extends mill.Module with TaskModule { outer => - def scalaWorker: ScalaWorkerModule = mill.scalalib.ScalaWorkerModule def defaultCommandName() = "run" @@ -120,7 +119,7 @@ trait JavaModule extends mill.Module with TaskModule { outer => } def compile: T[CompilationResult] = T{ - scalaWorker.worker().compileJava( + Lib.compileJava( allSourceFiles().map(_.path.toIO).toArray, compileClasspath().map(_.path.toIO).toArray, javacOptions(), diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 147e275d..7b4b5bdb 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -1,6 +1,9 @@ package mill package scalalib +import java.io.File +import javax.tools.ToolProvider + import ammonite.ops._ import ammonite.util.Util import coursier.{Cache, Dependency, Fetch, Repository, Resolution} @@ -15,6 +18,28 @@ object CompilationResult { case class CompilationResult(analysisFile: Path, classes: PathRef) object Lib{ + def compileJava(sources: Array[java.io.File], + classpath: Array[java.io.File], + javaOpts: Seq[String], + upstreamCompileOutput: Seq[CompilationResult]) + (implicit ctx: mill.util.Ctx) = { + val javac = ToolProvider.getSystemJavaCompiler() + + rm(ctx.dest / 'classes) + mkdir(ctx.dest / 'classes) + val cpArgs = + if(classpath.isEmpty) Seq() + else Seq("-cp", classpath.mkString(File.pathSeparator)) + + val args = Seq("-d", ctx.dest / 'classes) ++ cpArgs ++ javaOpts ++ sources + + javac.run( + ctx.log.inStream, ctx.log.outputStream, ctx.log.errorStream, + args.map(_.toString):_* + ) + if (ls(ctx.dest / 'classes).isEmpty) mill.eval.Result.Failure("Compilation Failed") + else mill.eval.Result.Success(CompilationResult(ctx.dest / 'zinc, PathRef(ctx.dest / 'classes))) + } private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 5d71a1a9..816e2077 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -16,6 +16,8 @@ import mill.util.DummyInputStream * Core configuration required to compile a single Scala compilation target */ trait ScalaModule extends JavaModule { outer => + def scalaWorker: ScalaWorkerModule = mill.scalalib.ScalaWorkerModule + trait Tests extends TestModule{ def scalaVersion = outer.scalaVersion() override def repositories = outer.repositories diff --git a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala index 698edc10..f6500ae8 100644 --- a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala +++ b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala @@ -56,11 +56,6 @@ trait ScalaWorkerModule extends mill.Module{ } trait ScalaWorkerApi { - def compileJava(sources: Array[java.io.File], - classpath: Array[java.io.File], - javaOpts: Seq[String], - upstreamCompileOutput: Seq[CompilationResult]) - (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] def compileScala(scalaVersion: String, sources: Agg[Path], |