From 6bf5ecd7226c0b9ad3e8fcdb609b550ee960f45a Mon Sep 17 00:00:00 2001 From: Minghao Liu Date: Fri, 8 Mar 2019 17:45:17 +0800 Subject: [PATCH] Update ZincWorkerImpl.scala --- scalalib/worker/src/ZincWorkerImpl.scala | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scalalib/worker/src/ZincWorkerImpl.scala b/scalalib/worker/src/ZincWorkerImpl.scala index a6360d8f111..a127e96e4bc 100644 --- a/scalalib/worker/src/ZincWorkerImpl.scala +++ b/scalalib/worker/src/ZincWorkerImpl.scala @@ -85,17 +85,30 @@ class ZincWorkerImpl(compilerBridge: Either[ val sourceFolder = mill.api.IO.unpackZip(srcJars(scalaVersion, scalaOrganization))(workingDir) val classloader = mill.api.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0) - val compilerMain = classloader.loadClass( - if (isDotty(scalaVersion)) "dotty.tools.dotc.Main" - else "scala.tools.nsc.Main" - ) + + val sources = os.walk(sourceFolder.path).filter(a => a.ext == "scala" || a.ext == "java") + val argsArray = Array[String]( "-d", compiledDest.toString, "-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(File.pathSeparator) - ) ++ os.walk(sourceFolder.path).filter(_.ext == "scala").map(_.toString) + ) ++ sources.map(_.toString) + + val allScala = sources.forall(_.ext == "scala") + val allJava = sources.forall(_.ext == "java") + if (allJava) { + import scala.sys.process._ + (Seq("javac") ++ argsArray).! + } else if (allScala) { + val compilerMain = classloader.loadClass( + if (isDotty(scalaVersion)) "dotty.tools.dotc.Main" + else "scala.tools.nsc.Main" + ) + compilerMain.getMethod("process", classOf[Array[String]]) + .invoke(null, argsArray) + } else { + throw new IllegalArgumentException("Currently not implemented case.") + } - compilerMain.getMethod("process", classOf[Array[String]]) - .invoke(null, argsArray) } compiledDest }