Commits

Thomas Bright committed cffb92b Merge

merge from default

Comments (0)

Files changed (5)

 96872fdfb7cb71ab51bbdaad10f803b28124f3c1 atlassian-processutils-1.5.5
 f4e4a5b2c7ab12175fcd741a2bf80751d6e01af4 atlassian-processutils-1.5.6
 60a172f84c5e6c6639e00a41b2779c146f6eb2fc atlassian-processutils-1.5.7
+97a10f8780d9a5b5d434295aa21c02cdf4a2e43d atlassian-processutils-1.5.8-rc1
 
     <groupId>com.atlassian.utils</groupId>
     <artifactId>atlassian-processutils</artifactId>
-    <version>1.5.8-SNAPSHOT</version>
+    <version>1.5.8-rc2-SNAPSHOT</version>
     <name>Atlassian Process Utils</name>
 
     <scm>
         <dependency>
             <groupId>org.jvnet.winp</groupId>
             <artifactId>winp</artifactId>
-            <version>1.15-atlassian-1</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>junit</groupId>
-                    <artifactId>junit</artifactId>
-                </exclusion>
-            </exclusions>	    
+            <version>1.17-atlassian1</version>
         </dependency>
         <dependency>
             <groupId>log4j</groupId>

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

      */
     public void cancel() {
         if (canceled.compareAndSet(false, true)) {
-            internalCancel(-1);
+            internalCancel(1);
         }
     }
 
     private void internalCancel(int exitCode) {
-        
         if (inputPump != null) {
             // we determine whether we're going to interrupt the inputPump *after* the process has already finished.
             // if that is the case, we don't treat the InterruptedException that we catch from the inputPump as an error
         }
 
         if (process != null) {
-            if (exitCode != 0 && isWindows()) {
+            if (isWindows() && exitCode != 0) {
                 try {
                     new WinProcess(process).killRecursively();
-                } catch (Throwable t2) {
-                    LOG.error("Failed to kill Windows process", t2);
+                } catch (Throwable t) {
+                    LOG.error("Failed to kill Windows process; falling back on Process.destroy()", t);
                     process.destroy();
                 }
 

src/test/java/com/atlassian/utils/process/ExternalProcessImplTest.java

                 try {
                     // this is for windows pause. Wait 1 second then press a key
                     input.write("key".getBytes());
+                    input.flush();
 
                     // sleep for a long time, the process should finish before the inputHandler finishes
                     // this simulates an inputHandler that simply copies data from some other stream into
         };
 
         //Ensure the timeout here is less than the timeout on the test
-        ExternalProcess process = builder.idleTimeout(TimeUnit.SECONDS.toMillis(15))
+        return builder.idleTimeout(TimeUnit.SECONDS.toMillis(15))
                 .handlers(inputHandler, new StringOutputHandler())
                 .build();
-        
-        return process;
     }
 
     @Test(timeout = 5 * 1000) // Test timeout in case execution doesn't stop as it should
         assertEquals(0, process.getHandler().getExitCode());
     }
 
+    @Test
+    public void testNativeWindowsKilling() {
+        if (isWindows()) {
+            ExternalProcess process = new ExternalProcessBuilder()
+                    .command(Arrays.asList("pause"))
+                    .handlers(new StringOutputHandler())
+                    .build();
+            process.start();
+            process.cancel();
+        }
+    }
+
     private boolean isWindows() {
         return System.getProperty("os.name").toLowerCase().contains("windows");
     }

src/test/java/com/atlassian/utils/process/ProcessBuilderEncodingTest.java

             assertEquals("ISO-8859-1 - incompatibility detected:", result.input, result.output);
         }
     }
-
-    @Test
-    public void testNativeWindowsKilling() {
-        if (isWindows()) {
-            ExternalProcess process = new ExternalProcessBuilder().command(Arrays.asList("pause")).handler(new StringProcessHandler()).build();
-            process.start();
-            process.cancel();
-        }
-    }
 }