@@ -35,6 +35,26 @@ public class SnippetRunner {
35
35
36
36
private static final int SIGTERM_EXIT_CODE = 143 ;
37
37
38
+ private static final boolean WINDOWS ;
39
+ private static final boolean MACOS ;
40
+
41
+ static {
42
+ final String osName = System .getProperty ("os.name" );
43
+
44
+ boolean windows = false ;
45
+ boolean macOS = false ;
46
+
47
+ String lowerOSName = osName .toLowerCase ().trim ();
48
+ if (lowerOSName .startsWith ("windows" )) {
49
+ windows = true ;
50
+ } else if (lowerOSName .startsWith ("mac" ) || lowerOSName .indexOf ("darwin" ) >= 0 ) {
51
+ macOS = true ;
52
+ }
53
+
54
+ WINDOWS = windows ;
55
+ MACOS = macOS ;
56
+ }
57
+
38
58
/**
39
59
* Harness for running one or more of the code snippets.
40
60
*
@@ -321,7 +341,8 @@ private static void executeSnippet(String snippet,
321
341
System .out .println ("Runner destroying " + snippet + " process..." );
322
342
// NOTE: using process.destroy() does not trigger the registered
323
343
// shutdown hooks in the snippet sub-process for some reason
324
- Process killer = runtime .exec ("kill " + process .pid ());
344
+ Process killer = runtime .exec (
345
+ ((WINDOWS ) ? "taskkill /F /PID " : "kill " ) + process .pid ());
325
346
Thread killerr = startOutputThread (killer .getErrorStream (), System .err );
326
347
Thread killout = startOutputThread (killer .getInputStream (), System .out );
327
348
killer .waitFor (); // wait for the kill process to complete
@@ -377,27 +398,15 @@ private static void printUsage(SortedMap<String, SortedSet<String>> snippetMap)
377
398
378
399
private static String getJarPath () throws RuntimeException {
379
400
try {
380
- final String osName = System .getProperty ("os.name" );
381
-
382
- boolean windows = false ;
383
- boolean macOS = false ;
384
-
385
- String lowerOSName = osName .toLowerCase ().trim ();
386
- if (lowerOSName .startsWith ("windows" )) {
387
- windows = true ;
388
- } else if (lowerOSName .startsWith ("mac" ) || lowerOSName .indexOf ("darwin" ) >= 0 ) {
389
- macOS = true ;
390
- }
391
-
392
401
String resourceName = SnippetRunner .class .getSimpleName () + ".class" ;
393
402
String url = SnippetRunner .class .getResource (resourceName ).toString ();
394
403
String jarPath = url .replaceAll ("jar:file:(.*\\ .jar)\\ !/.*\\ .class" , "$1" );
395
404
396
- if (windows && jarPath .startsWith ("/" )) {
405
+ if (WINDOWS && jarPath .startsWith ("/" )) {
397
406
jarPath = jarPath .replaceAll ("[/]+([^/].*)" , "$1" );
398
407
}
399
408
400
- if (windows && jarPath .startsWith ("/" )) {
409
+ if (WINDOWS && jarPath .startsWith ("/" )) {
401
410
jarPath = jarPath .substring (1 );
402
411
}
403
412
return jarPath ;
0 commit comments