mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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
This commit is contained in:
parent
329010d29e
commit
8b251e546a
@ -76,6 +76,9 @@ public class RunProcess {
|
||||
}
|
||||
|
||||
private boolean inheritIO(ProcessBuilder builder) {
|
||||
if (isInheritIOBroken()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
INHERIT_IO_METHOD.invoke(builder);
|
||||
return true;
|
||||
@ -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) {
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
process.getInputStream()));
|
||||
@ -96,6 +125,7 @@ public class RunProcess {
|
||||
while (line != null) {
|
||||
System.out.println(line);
|
||||
line = reader.readLine();
|
||||
System.out.flush();
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
@ -160,8 +160,9 @@ public class RunMojo extends AbstractMojo {
|
||||
StringBuilder classpath = new StringBuilder();
|
||||
for (URL ele : getClassPathUrls()) {
|
||||
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(classpath.toString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user