16
16
17
17
package org .springframework .boot .loader .tools ;
18
18
19
- import java .io .BufferedReader ;
20
19
import java .io .File ;
21
20
import java .io .IOException ;
22
- import java .io .InputStreamReader ;
23
- import java .lang .reflect .Method ;
24
21
import java .util .Arrays ;
25
22
import java .util .Collection ;
26
- import java .util .Locale ;
27
-
28
- import org .springframework .util .ReflectionUtils ;
29
23
30
24
/**
31
25
* Utility used to run a process.
38
32
*/
39
33
public class RunProcess {
40
34
41
- private static final Method INHERIT_IO_METHOD = ReflectionUtils
42
- .findMethod (ProcessBuilder .class , "inheritIO" );
43
-
44
35
private static final long JUST_ENDED_LIMIT = 500 ;
45
36
46
37
private File workingDirectory ;
@@ -81,13 +72,10 @@ protected int run(boolean waitForProcess, Collection<String> args)
81
72
builder .directory (this .workingDirectory );
82
73
builder .command ().addAll (args );
83
74
builder .redirectErrorStream (true );
84
- boolean inheritedIO = inheritIO (builder );
75
+ builder . inheritIO ();
85
76
try {
86
77
Process process = builder .start ();
87
78
this .process = process ;
88
- if (!inheritedIO ) {
89
- redirectOutput (process );
90
- }
91
79
SignalUtils .attachSignalHandler (this ::handleSigInt );
92
80
if (waitForProcess ) {
93
81
try {
@@ -108,61 +96,6 @@ protected int run(boolean waitForProcess, Collection<String> args)
108
96
}
109
97
}
110
98
111
- private boolean inheritIO (ProcessBuilder builder ) {
112
- if (isInheritIOBroken ()) {
113
- return false ;
114
- }
115
- try {
116
- INHERIT_IO_METHOD .invoke (builder );
117
- return true ;
118
- }
119
- catch (Exception ex ) {
120
- return false ;
121
- }
122
- }
123
-
124
- // There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130)
125
- // that means we need to avoid inheritIO
126
- private static boolean isInheritIOBroken () {
127
- if (!System .getProperty ("os.name" , "none" ).toLowerCase (Locale .ENGLISH )
128
- .contains ("windows" )) {
129
- return false ;
130
- }
131
- String runtime = System .getProperty ("java.runtime.version" );
132
- if (!runtime .startsWith ("1.7" )) {
133
- return false ;
134
- }
135
- String [] tokens = runtime .split ("_" );
136
- if (tokens .length < 2 ) {
137
- return true ; // No idea actually, shouldn't happen
138
- }
139
- try {
140
- Integer build = Integer .valueOf (tokens [1 ].split ("[^0-9]" )[0 ]);
141
- if (build < 60 ) {
142
- return true ;
143
- }
144
- }
145
- catch (Exception ex ) {
146
- return true ;
147
- }
148
- return false ;
149
- }
150
-
151
- private void redirectOutput (Process process ) {
152
- new Thread (() -> {
153
- try (BufferedReader reader = new BufferedReader (
154
- new InputStreamReader (process .getInputStream ()))) {
155
- reader .lines ().forEach ((line ) -> {
156
- System .out .println (line );
157
- System .out .flush ();
158
- });
159
- }
160
- catch (Exception ex ) {
161
- // Ignore
162
- }
163
- }).start ();
164
- }
165
-
166
99
/**
167
100
* Return the running process.
168
101
* @return the process or {@code null}
0 commit comments