diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-07 07:24:47 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-07 09:04:55 -0700 |
commit | 3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f (patch) | |
tree | a39394ea100eca1bafb551c793075e475a26ddd3 /scalaworker | |
parent | 953321ead7b278912529ef34b50e403d1e533c05 (diff) | |
download | mill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.tar.gz mill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.tar.bz2 mill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.zip |
First unit tests for `JavaModule`
Diffstat (limited to 'scalaworker')
-rw-r--r-- | scalaworker/src/mill/scalaworker/ScalaWorker.scala | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/scalaworker/src/mill/scalaworker/ScalaWorker.scala b/scalaworker/src/mill/scalaworker/ScalaWorker.scala index 0411af92..8351f6e8 100644 --- a/scalaworker/src/mill/scalaworker/ScalaWorker.scala +++ b/scalaworker/src/mill/scalaworker/ScalaWorker.scala @@ -5,6 +5,7 @@ import java.lang.annotation.Annotation import java.net.URLClassLoader import java.util.Optional import java.util.zip.ZipInputStream +import javax.tools.ToolProvider import ammonite.ops.{Path, exists, ls, mkdir, rm, up} import ammonite.util.Colors @@ -18,9 +19,14 @@ import mill.scalalib.Lib.grepJar import mill.scalalib.TestRunner.Result import mill.util.{Ctx, PrintLogger} import sbt.internal.inc._ +import sbt.internal.inc.classfile.Analyze +import sbt.internal.inc.classpath.ClasspathUtilities +import sbt.internal.inc.javac.JavaCompiler import sbt.internal.util.{ConsoleOut, MainAppender} +import sbt.io.PathFinder import sbt.testing._ -import sbt.util.LogExchange +import sbt.util.{InterfaceUtil, LogExchange} +import xsbti.AnalysisCallback import scala.collection.mutable @@ -131,6 +137,29 @@ class ScalaWorker(ctx0: mill.util.Ctx, .getOrElse(Seq.empty[String]) } + 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))) + } + def compileScala(scalaVersion: String, sources: Agg[Path], compilerBridgeSources: Path, |