diff --git a/clientserver/src/mill/clientserver/Client.java b/clientserver/src/mill/clientserver/Client.java index e2a92f7fb55..c4cbc265f51 100644 --- a/clientserver/src/mill/clientserver/Client.java +++ b/clientserver/src/mill/clientserver/Client.java @@ -25,7 +25,7 @@ static void initServer(String lockBase, boolean setJnaNoSys) throws IOException, } current = current.getParent(); } - if (!System.getProperty("java.specification.version").startsWith("1.")) { + if (ClientServer.isJava9OrAbove) { selfJars.addAll(Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator))); } ArrayList l = new java.util.ArrayList(); @@ -166,14 +166,15 @@ public ClientOutputPumper(InputStream src, OutputStream dest1, OutputStream dest this.dest2 = dest2; } - boolean running = true; public void run() { byte[] buffer = new byte[1024]; int state = 0; - try { - while(running){ - + boolean running = true; + boolean first = true; + while (running) { + try { int n = src.read(buffer); + first = false; if (n == -1) running = false; else { int i = 0; @@ -197,12 +198,21 @@ public void run() { dest1.flush(); dest2.flush(); } + } catch (IOException e) { + // Win32NamedPipeSocket input stream somehow doesn't return -1, + // instead it throws an IOException whose message contains "ReadFile()". + // However, if it throws an IOException before ever reading some bytes, + // it could not connect to the server, so exit. + if (ClientServer.isWindows && e.getMessage().contains("ReadFile()")) { + if (first) { + System.err.println("Failed to connect to server"); + System.exit(1); + } else running = false; + } else { + e.printStackTrace(); + System.exit(1); + } } - }catch(IOException e){ - // Win32NamedPipeSocket input stream somehow doesn't return -1, - // but throw IOException whose message contains "ReadFile()" with a ccode - if (ClientServer.isWindows && e.getMessage().contains("ReadFile()")) running = false; - else throw new RuntimeException(e); } } diff --git a/clientserver/src/mill/clientserver/ClientServer.java b/clientserver/src/mill/clientserver/ClientServer.java index 7af5845b607..e2e63dcffc0 100644 --- a/clientserver/src/mill/clientserver/ClientServer.java +++ b/clientserver/src/mill/clientserver/ClientServer.java @@ -5,8 +5,9 @@ import java.io.InputStream; import java.io.OutputStream; -class ClientServer { +public class ClientServer { public static boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + public static boolean isJava9OrAbove = !System.getProperty("java.specification.version").startsWith("1."); // Windows named pipe prefix (see https://github.com/sbt/ipcsocket/blob/v1.0.0/README.md) // Win32NamedPipeServerSocket automatically adds this as a prefix (if it is not already is prefixed), diff --git a/core/src/mill/util/ClassLoader.scala b/core/src/mill/util/ClassLoader.scala index 9f0a7ab3642..9678989e4b4 100644 --- a/core/src/mill/util/ClassLoader.scala +++ b/core/src/mill/util/ClassLoader.scala @@ -52,12 +52,7 @@ object ClassLoader { private def makeUrls(urls: Seq[URL])(implicit ctx: Ctx.Home): Seq[URL] = { if (ammonite.util.Util.java9OrAbove) { - - val rtFile = ctx.home / io.github.retronym.java9rtexport.Export.rtJarName - if (!exists(rtFile)) { - cp(Path(Export.rt()), rtFile) - } - urls :+ rtFile.toNIO.toUri.toURL + urls :+ Export.rtAt(ctx.home.toIO).toURI.toURL } else { urls } diff --git a/main/src/mill/Main.scala b/main/src/mill/Main.scala index 0844e485f13..e026dfe0ef9 100644 --- a/main/src/mill/Main.scala +++ b/main/src/mill/Main.scala @@ -5,6 +5,7 @@ import java.io.{InputStream, PrintStream} import ammonite.main.Cli._ import ammonite.ops._ import ammonite.util.Util +import io.github.retronym.java9rtexport.Export import mill.eval.Evaluator import mill.util.DummyInputStream @@ -118,6 +119,14 @@ object Main { stateCache ) + if (mill.clientserver.ClientServer.isJava9OrAbove) { + val rt = cliConfig.home / Export.rtJarName + if (!exists(rt)) { + runner.printInfo(s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ...") + Export.rtTo(rt.toIO, false) + } + } + if (repl){ runner.printInfo("Loading...") (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index fdc83cbf09c..dc39a4a8982 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -330,7 +330,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer => } def ammoniteReplClasspath = T{ - resolveDeps(T.task{Agg(ivy"com.lihaoyi:::ammonite:1.1.0-3-73d5734")})() + resolveDeps(T.task{Agg(ivy"com.lihaoyi:::ammonite:1.1.0-7-33b728c")})() } def repl() = T.command{ if (T.ctx().log.inStream == DummyInputStream){