@@ -84,13 +84,19 @@ private static String getProcessOutput(InputStream stream ) throws IOException {
84
84
private static void validateNodeJSVersion (){
85
85
Runtime rt = Runtime .getRuntime ();
86
86
String result = null ;
87
+ Process p = null ;
87
88
try {
88
- Process p = rt .exec (NODE_COMMAND_PREFIX + " node -v" );
89
+ p = rt .exec (NODE_COMMAND_PREFIX + " node -v" );
89
90
p .waitFor ();
90
91
result = getProcessOutput (p .getInputStream ());
91
92
} catch (Exception e ) {
92
93
throw new InvalidNodeJSInstance ("Node.js is not installed" , e );
93
94
}
95
+ finally {
96
+ if (p != null )
97
+ p .destroy ();
98
+ }
99
+
94
100
String versionNum = result .replace ("v" ,"" );
95
101
String [] tokens = versionNum .split ("\\ ." );
96
102
if (Integer .parseInt (tokens [0 ]) < REQUIRED_MAJOR_NODE_JS ||
@@ -102,13 +108,18 @@ private static void validateNodeJSVersion(){
102
108
private static File findNodeInCurrentFileSystem (){
103
109
Runtime rt = Runtime .getRuntime ();
104
110
String instancePath ;
111
+ Process p = null ;
105
112
try {
106
- Process p = rt .exec (returnCommandThatSearchesForDefaultNode ());
113
+ p = rt .exec (returnCommandThatSearchesForDefaultNode ());
107
114
p .waitFor ();
108
115
instancePath = getProcessOutput (p .getInputStream ());
109
116
} catch (Exception e ) {
110
117
throw new RuntimeException (e );
111
118
}
119
+ finally {
120
+ if (p != null )
121
+ p .destroy ();
122
+ }
112
123
113
124
File result ;
114
125
if (StringUtils .isBlank (instancePath ) || !(result = new File (instancePath + File .separator + NODE_MODULES_FOLDER +
@@ -154,17 +165,21 @@ protected File findDefaultExecutable() {
154
165
} catch (IOException e ) {
155
166
throw new RuntimeException (e );
156
167
}
157
- OutputStream outputStream = p .getOutputStream ();
158
- PrintStream out = new PrintStream (outputStream ) ;
159
- out .println ("console.log(process.execPath);" ) ;
160
- out .close ();
161
168
162
169
try {
170
+ OutputStream outputStream = p .getOutputStream ();
171
+ PrintStream out = new PrintStream (outputStream ) ;
172
+ out .println ("console.log(process.execPath);" ) ;
173
+ out .close ();
174
+
163
175
return new File (getProcessOutput (p .getInputStream ()));
164
176
}
165
177
catch (Throwable t ){
166
178
throw new RuntimeException (t );
167
179
}
180
+ finally {
181
+ p .destroy ();
182
+ }
168
183
}
169
184
170
185
/**
0 commit comments