Commit 8b251e54 authored by Dave Syer's avatar Dave Syer

Monkey with process forking for Windoze

There were several problems to fix. 1) a bug in the
JDK (1.7 up to 7_60):

https://bugs.openjdk.java.net/browse/JDK-8023130

which we can work around by detecting buggy VMs and not trying
to use inheritIO. 2) File<->URL conversion is platform dependent
and we shouldn't make any assumptions. The problem in this case
was that file URLs contain a ":" so they can 't be added to a
path in UNIX, but on Windows you need the absolute path with the
colon. Solution: use Files on the classpath for spring-boot:run.

Hopefully also fixes gh-767
parent 329010d2
...@@ -76,6 +76,9 @@ public class RunProcess { ...@@ -76,6 +76,9 @@ public class RunProcess {
} }
private boolean inheritIO(ProcessBuilder builder) { private boolean inheritIO(ProcessBuilder builder) {
if (isInheritIOBroken()) {
return false;
}
try { try {
INHERIT_IO_METHOD.invoke(builder); INHERIT_IO_METHOD.invoke(builder);
return true; return true;
...@@ -85,6 +88,32 @@ public class RunProcess { ...@@ -85,6 +88,32 @@ public class RunProcess {
} }
} }
// There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130)
// that means we need to avoid inheritIO
private static boolean isInheritIOBroken() {
if (!System.getProperty("os.name", "none").toLowerCase().contains("windows")) {
return false;
}
String runtime = System.getProperty("java.runtime.version");
if (!runtime.startsWith("1.7")) {
return false;
}
String[] tokens = runtime.split("_");
if (tokens.length < 2) {
return true; // No idea actually, shouldn't happen
}
try {
Integer build = Integer.valueOf(tokens[1].split("[^0-9]")[0]);
if (build < 60) {
return true;
}
}
catch (Exception e) {
return true;
}
return false;
}
private void redirectOutput(Process process) { private void redirectOutput(Process process) {
final BufferedReader reader = new BufferedReader(new InputStreamReader( final BufferedReader reader = new BufferedReader(new InputStreamReader(
process.getInputStream())); process.getInputStream()));
...@@ -96,6 +125,7 @@ public class RunProcess { ...@@ -96,6 +125,7 @@ public class RunProcess {
while (line != null) { while (line != null) {
System.out.println(line); System.out.println(line);
line = reader.readLine(); line = reader.readLine();
System.out.flush();
} }
reader.close(); reader.close();
} }
......
...@@ -160,8 +160,9 @@ public class RunMojo extends AbstractMojo { ...@@ -160,8 +160,9 @@ public class RunMojo extends AbstractMojo {
StringBuilder classpath = new StringBuilder(); StringBuilder classpath = new StringBuilder();
for (URL ele : getClassPathUrls()) { for (URL ele : getClassPathUrls()) {
classpath = classpath.append((classpath.length() > 0 ? File.pathSeparator classpath = classpath.append((classpath.length() > 0 ? File.pathSeparator
: "") + ele); : "") + new File(ele.toURI()));
} }
getLog().debug("Classpath for forked process: " + classpath);
args.add("-cp"); args.add("-cp");
args.add(classpath.toString()); args.add(classpath.toString());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment