Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows client/server improvements #262

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 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 @@ -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;
Expand All @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion clientserver/src/mill/clientserver/ClientServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
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
9 changes: 9 additions & 0 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 Down Expand Up @@ -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)
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