@ -16,16 +16,10 @@
package org.springframework.boot.loader.tools ;
import java.io.BufferedReader ;
import java.io.File ;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.lang.reflect.Method ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Locale ;
import org.springframework.util.ReflectionUtils ;
/ * *
* Utility used to run a process .
@ -38,9 +32,6 @@ import org.springframework.util.ReflectionUtils;
* /
public class RunProcess {
private static final Method INHERIT_IO_METHOD = ReflectionUtils
. findMethod ( ProcessBuilder . class , "inheritIO" ) ;
private static final long JUST_ENDED_LIMIT = 500 ;
private File workingDirectory ;
@ -81,13 +72,10 @@ public class RunProcess {
builder . directory ( this . workingDirectory ) ;
builder . command ( ) . addAll ( args ) ;
builder . redirectErrorStream ( true ) ;
boolean inheritedIO = inheritIO ( builder ) ;
builder . inheritIO ( ) ;
try {
Process process = builder . start ( ) ;
this . process = process ;
if ( ! inheritedIO ) {
redirectOutput ( process ) ;
}
SignalUtils . attachSignalHandler ( this : : handleSigInt ) ;
if ( waitForProcess ) {
try {
@ -108,61 +96,6 @@ public class RunProcess {
}
}
private boolean inheritIO ( ProcessBuilder builder ) {
if ( isInheritIOBroken ( ) ) {
return false ;
}
try {
INHERIT_IO_METHOD . invoke ( builder ) ;
return true ;
}
catch ( Exception ex ) {
return false ;
}
}
// 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 ( Locale . ENGLISH )
. 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 ex ) {
return true ;
}
return false ;
}
private void redirectOutput ( Process process ) {
new Thread ( ( ) - > {
try ( BufferedReader reader = new BufferedReader (
new InputStreamReader ( process . getInputStream ( ) ) ) ) {
reader . lines ( ) . forEach ( ( line ) - > {
System . out . println ( line ) ;
System . out . flush ( ) ;
} ) ;
}
catch ( Exception ex ) {
// Ignore
}
} ) . start ( ) ;
}
/ * *
* Return the running process .
* @return the process or { @code null }