Skip to content

Commit

Permalink
Move rt cache init after CLI parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
robby-phd committed Mar 28, 2018
1 parent 7c15de0 commit 20a197d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 50 deletions.
3 changes: 1 addition & 2 deletions clientserver/src/mill/clientserver/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> l = new java.util.ArrayList<String>();
Expand Down Expand Up @@ -54,7 +54,6 @@ public static void main(String[] args) throws Exception{
if (setJnaNoSys) {
System.setProperty("jna.nosys", "true");
}
if (ClientServer.isJava9OrAbove) ClientServer.initRt(args);
int index = 0;
while (index < 5) {
index += 1;
Expand Down
38 changes: 0 additions & 38 deletions clientserver/src/mill/clientserver/ClientServer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package mill.clientserver;


import io.github.retronym.java9rtexport.Export;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -18,41 +15,6 @@ public class ClientServer {
// https://github.com/sbt/ipcsocket/blob/v1.0.0/src/main/java/org/scalasbt/ipcsocket/Win32NamedPipeServerSocket.java#L36
public static String WIN32_PIPE_PREFIX = "\\\\.\\pipe\\";

public static void initRt(String[] args) throws IOException {
// Ideally, rtJarName should be using ammonite.runtime.Classpath.rtJarName
// however, that one is written in Scala which pulls in lots of deps
// This can be easily changed on the Ammonite side
String javaVersion = System.getProperty("java.version");
String rtJarName = "rt-" + javaVersion + ".jar";

String home = String.join(File.separator,
new String[] { System.getProperty("user.home"), ".mill", "ammonite" });;

// Ideally, this should use ammonite.main.CLI, but that one is also in Scala
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-h":
case "--home":
i++;
if (i < args.length) {
home = args[i];
}
break;
default:
break;
}
}

File rtFile = new File(home + File.separator + rtJarName);
if (!rtFile.exists()) {
// No logger just yet, so info is printed using System.out directly
System.out.println("Copying Java " + javaVersion + " runtime jar to " + home + " ...");
System.out.flush();
rtFile.getParentFile().mkdirs();
java.nio.file.Files.copy(Export.export().toPath(), rtFile.toPath());
}
}

public static String[] parseArgs(InputStream argStream) throws IOException {

int argsLength = argStream.read();
Expand Down
7 changes: 1 addition & 6 deletions core/src/mill/util/ClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions main/src/mill/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,9 +32,6 @@ object Main {
case Array(s, _*) if s == "-i" || s == "--interactive" => args.tail
case _ => args
}
// This is unnecessary but done to be consistent with client/server mode
if (mill.clientserver.ClientServer.isJava9OrAbove)
mill.clientserver.ClientServer.initRt(as)
val (result, _) = main0(
as,
None,
Expand Down Expand Up @@ -95,6 +93,9 @@ object Main {
stderr.println("Build repl needs to be run with the -i/--interactive flag")
(false, stateCache)
}else{
// Init rt cache here
if (mill.clientserver.ClientServer.isJava9OrAbove)
Export.rtAt(cliConfig.home.toIO, true)
val tqs = "\"\"\""
val config =
if(!repl) cliConfig
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 20a197d

Please sign in to comment.