summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sc17
-rw-r--r--core/src/mill/util/ClassLoader.scala68
-rw-r--r--main/src/mill/modules/Jvm.scala17
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala2
-rw-r--r--scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4-sources.jar.xml2
-rw-r--r--scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml2
-rw-r--r--scalalib/test/resources/hello-world/core/src/Main.scala9
-rw-r--r--scalalib/test/src/mill/scalalib/GenIdeaTests.scala5
-rw-r--r--scalaworker/src/mill/scalaworker/ScalaWorker.scala2
9 files changed, 79 insertions, 45 deletions
diff --git a/build.sc b/build.sc
index a5d898e3..e40b8511 100755
--- a/build.sc
+++ b/build.sc
@@ -19,22 +19,15 @@ trait MillPublishModule extends PublishModule{
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/mill",
- licenses = Seq(
- License("MIT license", "http://www.opensource.org/licenses/mit-license.php")
- ),
- // TODO 0.1.4
- // licenses = Seq(License.MIT),
- scm = SCM(
- "git://github.com/lihaoyi/mill.git",
- "scm:git://github.com/lihaoyi/mill.git"
- ),
- // TODO 0.1.4:
- // versionControl = VersionControl.github("lihaoyi", "mill")
-
+ licenses = Seq(License.MIT),
+ versionControl = VersionControl.github("lihaoyi", "mill"),
developers = Seq(
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
)
)
+
+ def javacOptions = Seq("-source", "1.8", "-target", "1.8")
+
}
object moduledefs extends MillPublishModule{
def ivyDeps = Agg(
diff --git a/core/src/mill/util/ClassLoader.scala b/core/src/mill/util/ClassLoader.scala
index b53150c2..d650aceb 100644
--- a/core/src/mill/util/ClassLoader.scala
+++ b/core/src/mill/util/ClassLoader.scala
@@ -2,25 +2,63 @@ package mill.util
import java.net.{URL, URLClassLoader}
+import ammonite.ops._
import io.github.retronym.java9rtexport.Export
object ClassLoader {
+
+ def create(urls: Seq[URL], parent: java.lang.ClassLoader)(
+ implicit ctx: Ctx.Home): URLClassLoader = {
+ new URLClassLoader(
+ makeUrls(urls).toArray,
+ refinePlatformParent(parent)
+ )
+ }
+
def create(urls: Seq[URL],
- parent: java.lang.ClassLoader)
- (implicit ctx: Ctx.Home): URLClassLoader = {
- val cl = new URLClassLoader(urls.toArray, parent)
- if (!ammonite.util.Util.java9OrAbove) return cl
- try {
- cl.loadClass("javax.script.ScriptEngineManager")
- cl
- } catch {
- case _: ClassNotFoundException =>
- val path = ctx.home
- val rtFile = new java.io.File(path.toIO, s"rt-${System.getProperty("java.version")}.jar")
- if (!rtFile.exists) {
- java.nio.file.Files.copy(Export.export().toPath, rtFile.toPath)
- }
- new URLClassLoader((urls ++ Some(rtFile.toURI.toURL)).toArray, parent)
+ parent: java.lang.ClassLoader,
+ customFindClass: String => Option[Class[_]])(
+ implicit ctx: Ctx.Home): URLClassLoader = {
+ new URLClassLoader(
+ makeUrls(urls).toArray,
+ refinePlatformParent(parent)
+ ) {
+ override def findClass(name: String): Class[_] = {
+ customFindClass(name).getOrElse(super.findClass(name))
+ }
+ }
+ }
+
+ /**
+ * Return `ClassLoader.getPlatformClassLoader` for java 9 and above, if parent class loader is null,
+ * otherwise return same parent class loader.
+ * More details: https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E
+ *
+ * `ClassLoader.getPlatformClassLoader` call is implemented via runtime reflection, cause otherwise
+ * mill could be compiled only with jdk 9 or above. We don't want to introduce this restriction now.
+ */
+ private def refinePlatformParent(parent: java.lang.ClassLoader): ClassLoader = {
+ if (ammonite.util.Util.java9OrAbove) {
+ if (parent == null)
+ classOf[ClassLoader]
+ .getMethod("getPlatformClassLoader")
+ .invoke(null)
+ .asInstanceOf[ClassLoader]
+ else parent
+ } else {
+ parent
+ }
+ }
+
+ private def makeUrls(urls: Seq[URL])(implicit ctx: Ctx.Home): Seq[URL] = {
+ if (ammonite.util.Util.java9OrAbove) {
+ val rtFile = ctx.home / s"rt-${System.getProperty("java.version")}.jar"
+ if (!exists(rtFile)) {
+ cp(Path(Export.export()), rtFile)
+ }
+ urls :+ rtFile.toNIO.toUri.toURL
+ } else {
+ urls
}
}
}
diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala
index 9c63d108..92469988 100644
--- a/main/src/mill/modules/Jvm.scala
+++ b/main/src/mill/modules/Jvm.scala
@@ -103,19 +103,16 @@ object Jvm {
classLoaderOverrideSbtTesting: Boolean,
body: ClassLoader => T)
(implicit ctx: Ctx.Home): T = {
+ val urls = classPath.map(_.toIO.toURI.toURL)
val cl = if (classLoaderOverrideSbtTesting) {
val outerClassLoader = getClass.getClassLoader
- new URLClassLoader(classPath.map(_.toIO.toURI.toURL).toArray, mill.util.ClassLoader.create(Seq(), null)){
- override def findClass(name: String) = {
- if (name.startsWith("sbt.testing.")){
- outerClassLoader.loadClass(name)
- }else{
- super.findClass(name)
- }
- }
- }
+ mill.util.ClassLoader.create(urls.toVector, null, customFindClass = { name =>
+ if (name.startsWith("sbt.testing."))
+ Some(outerClassLoader.loadClass(name))
+ else None
+ })
} else {
- mill.util.ClassLoader.create(classPath.map(_.toIO.toURI.toURL).toVector, null)
+ mill.util.ClassLoader.create(urls.toVector, null)
}
val oldCl = Thread.currentThread().getContextClassLoader
Thread.currentThread().setContextClassLoader(cl)
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 0a72f4c8..a2ca2214 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -235,7 +235,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
if (files.nonEmpty) subprocess(
"scala.tools.nsc.ScalaDoc",
- scalaCompilerClasspath().map(_.path) ++ runClasspath().filter(_.path.ext != "pom").map(_.path),
+ scalaCompilerClasspath().map(_.path) ++ compileClasspath().filter(_.path.ext != "pom").map(_.path),
mainArgs = (files ++ options).toSeq
)
diff --git a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4-sources.jar.xml b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4-sources.jar.xml
index 77b85e64..e8af8eb1 100644
--- a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4-sources.jar.xml
+++ b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4-sources.jar.xml
@@ -1,7 +1,7 @@
<component name="libraryTable">
<library name="scala-library-2.12.4-sources.jar" type="Scala">
<CLASSES>
- <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4-sources.jar!/"/>
+ <root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4-sources.jar!/"/>
</CLASSES>
</library>
</component>
diff --git a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
index 27d4e19f..d45f3206 100644
--- a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
+++ b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
@@ -1,7 +1,7 @@
<component name="libraryTable">
<library name="scala-library-2.12.4.jar" type="Scala">
<CLASSES>
- <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar!/"/>
+ <root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar!/"/>
</CLASSES>
</library>
</component>
diff --git a/scalalib/test/resources/hello-world/core/src/Main.scala b/scalalib/test/resources/hello-world/core/src/Main.scala
index 32706d44..d86f4da8 100644
--- a/scalalib/test/resources/hello-world/core/src/Main.scala
+++ b/scalalib/test/resources/hello-world/core/src/Main.scala
@@ -1,5 +1,8 @@
import scala.collection._
import java.nio.file.{Files, Paths}
+import java.sql.Date
+import java.time.LocalDate
+import javax.swing.JButton
import Main.{args, greeting}
object Main0{
@@ -10,7 +13,11 @@ object Main0{
}
}
object Main extends App {
-
+ // testing correct loading of java standard modules in java 9
+ // https://github.com/lihaoyi/mill/issues/251
+ new JButton("hello from javax")
+ val now = Date.valueOf(LocalDate.now())
+ println(s"Today is the date: ${now}")
val person = Person.fromString("rockjam:25")
val greeting = s"hello ${person.name}, your age is: ${person.age}"
println(greeting)
diff --git a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
index 0ce9533f..0f776802 100644
--- a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
+++ b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
@@ -1,8 +1,8 @@
package mill.scalalib
import ammonite.ops._
+import coursier.Cache
import mill._
-import mill.define.Discover
import mill.util.{TestEvaluator, TestUtil}
import utest._
@@ -54,8 +54,7 @@ object GenIdeaTests extends TestSuite {
}
- private val libPathRegex = """([\w/]+)/.coursier""".r
private def normaliseLibraryPaths(in: String): String = {
- libPathRegex.replaceAllIn(in, "COURSIER_HOME")
+ in.replaceAll(Cache.default.toPath.toAbsolutePath.toString, "COURSIER_HOME")
}
}
diff --git a/scalaworker/src/mill/scalaworker/ScalaWorker.scala b/scalaworker/src/mill/scalaworker/ScalaWorker.scala
index f26c98b3..0411af92 100644
--- a/scalaworker/src/mill/scalaworker/ScalaWorker.scala
+++ b/scalaworker/src/mill/scalaworker/ScalaWorker.scala
@@ -297,7 +297,7 @@ class ScalaWorker(ctx0: mill.util.Ctx,
})
)
}
- runner.done()
+ ctx.log.outputStream.println(runner.done())
}
val results = for(e <- events) yield {