James Dumay avatar James Dumay committed 92e3480

BAM-811 Use native API calls on Windows to kill process and recursively, its children.

Comments (0)

Files changed (2)

 
   <dependencies>
     <dependency>
+      <groupId>org.jvnet.winp</groupId>
+      <artifactId>winp</artifactId>
+      <version>1.9</version>
+    </dependency>
+
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.15</version>

src/main/java/com/atlassian/utils/process/ExternalProcess.java

 import java.util.concurrent.TimeUnit;
 
 import org.apache.log4j.Logger;
+import org.jvnet.winp.WinProcess;
 
 /**
  * This class manages the execution of an external process, using separate threads to process
  * the process' IO requirements.
  */
 public class ExternalProcess implements Watchdog {
+    private static final String OS_NAME = System.getProperty("os.name");
+    
     private boolean useWindowsEncodingWorkaround = false;
     private List<String> command;
     private File workingDir;
     }
     
     private boolean isWindows() {
-    	return System.getProperty("os.name").toLowerCase().contains("windows");
+    	return OS_NAME.toLowerCase().contains("windows");
     }
     
     private String quoteString(String value) {
         if (errorPump != null) {
             errorPump.cancel();
         }
-        process.destroy();
+
+        if (OS_NAME.startsWith("Windows"))
+        {
+            final WinProcess winProcess = new WinProcess(process);
+            winProcess.killRecursively();
+        }
+        else
+        {
+            process.destroy();
+        }
     }
 
     public void setTimeout(long timeout) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.