Commits

Marcin Gardias committed 6081cbb Merge

merge with mg_shipit powershell support

Comments (0)

Files changed (6)

 60a172f84c5e6c6639e00a41b2779c146f6eb2fc atlassian-processutils-1.5.7
 97a10f8780d9a5b5d434295aa21c02cdf4a2e43d atlassian-processutils-1.5.8-rc1
 5822d10a3b41f407b7356bfcb4f501a6c0b2a69c atlassian-processutils-1.5.8
+bcc7f27364d39c353fcfea42f55026eaa74fc487 atlassian-processutils-1.5.8-bamboo1
 f8e34816f4e1960217a3646aeccb642f033fbb00 atlassian-processutils-1.5.9
+
+e54e5674e9626102e04a3ac9df648e4c54674841 atlassian-processutils-1.5.9-bamboo1
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>com.atlassian.pom</groupId>
-        <artifactId>atlassian-public-pom</artifactId>
-        <version>29.2</version>
-    </parent>
-
-    <groupId>com.atlassian.utils</groupId>
-    <artifactId>atlassian-processutils</artifactId>
-    <version>1.5.10-SNAPSHOT</version>
-    <name>Atlassian Process Utils</name>
-
-    <scm>
-        <connection>scm:hg:ssh://hg@bitbucket.org/atlassian/atlassian-processutils</connection>
-        <developerConnection>scm:hg:ssh://hg@bitbucket.org/atlassian/atlassian-processutils</developerConnection>
-        <url>https://bitbucket.org/atlassian/atlassian-processutils/overview</url>
-    </scm>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.jvnet.winp</groupId>
-            <artifactId>winp</artifactId>
-            <version>1.17-atlassian1</version>
-        </dependency>
-        <dependency>
-            <groupId>log4j</groupId>
-            <artifactId>log4j</artifactId>
-            <version>1.2.15</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>com.sun.jdmk</groupId>
-                    <artifactId>jmxtools</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>com.sun.jmx</groupId>
-                    <artifactId>jmxri</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>javax.jms</groupId>
-                    <artifactId>jms</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>javax.mail</groupId>
-                    <artifactId>mail</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>javax.activation</groupId>
-                    <artifactId>activation</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.10</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-all</artifactId>
-            <version>1.9.5</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.atlassian.pom</groupId>
+        <artifactId>atlassian-public-pom</artifactId>
+        <version>29.2</version>
+    </parent>
+
+    <groupId>com.atlassian.utils</groupId>
+    <artifactId>atlassian-processutils</artifactId>
+    <version>1.5.10-SNAPSHOT</version>
+    <name>Atlassian Process Utils</name>
+
+    <scm>
+        <connection>scm:hg:ssh://hg@bitbucket.org/atlassian/atlassian-processutils</connection>
+        <developerConnection>scm:hg:ssh://hg@bitbucket.org/atlassian/atlassian-processutils</developerConnection>
+        <url>https://bitbucket.org/atlassian/atlassian-processutils/overview</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.jvnet.winp</groupId>
+            <artifactId>winp</artifactId>
+            <version>1.17-atlassian1</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.15</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.jdmk</groupId>
+                    <artifactId>jmxtools</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jmx</groupId>
+                    <artifactId>jmxri</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.jms</groupId>
+                    <artifactId>jms</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.mail</groupId>
+                    <artifactId>mail</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.activation</groupId>
+                    <artifactId>activation</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.10</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.9.5</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

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

         if (settings.hasIdleTimeout()) {
             process.setIdleTimeout(settings.getIdleTimeout());
         }
+        process.setRunWithPowershell(settings.isRunWithPowershell());
     }
 }

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

         
         return this;
     }
+
+    /**
+     * Use powershell instead of cmd.exe to run windows processes. Has no effect if {@link #suppressSpecialWindowsBehaviour()} is used
+     */
+    public ExternalProcessBuilder runWithPowershell()
+    {
+        settings.setRunWithPowershell(true);
+        return this;
+    }
 }

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

     private File workingDir;
     private boolean useWindowsEncodingWorkaround;
 
+    private boolean runWithPowershell;
+
     /**
      * Process an external command.
      *
         this.useWindowsEncodingWorkaround = useWindowsEncodingWorkaround;
     }
 
+    public void setRunWithPowershell(final boolean runWithPowershell)
+    {
+        this.runWithPowershell = runWithPowershell;
+    }
+
     private boolean areOutputPumpsRunning() {
         return (outputPump != null && outputPump.isRunning()) || (errorPump != null && errorPump.isRunning());
     }
      */
     private Process createWinProcess(List<String> command, Map<String, String> environment, File workingDir)
             throws IOException {
-        List<String> newCommand = new ArrayList<String>(command.size() + 3);
-        newCommand.add("cmd");
-        newCommand.add("/A"); // use ANSI encoding
-        newCommand.add("/C");
+        List<String> newCommand = new ArrayList<String>(command.size() + 4);
+
+        if (runWithPowershell)
+        {
+            newCommand.add("powershell");
+            newCommand.add("-Command");
+        }
+        else
+        {
+            newCommand.add("cmd");
+            newCommand.add("/A"); // use ANSI encoding
+            newCommand.add("/C");
+            newCommand.add("call");
+        }
 
         if (useWindowsEncodingWorkaround) {
             newCommand.add(command.get(0));
                 protected void doTask() {
                     try {
                         handler.provideInput(process.getOutputStream());
+                        if (runWithPowershell)
+                        {
+                            process.getOutputStream().close();
+                        }
                     } catch (Throwable t) {
                         // The StdInHandler IO pump is intentionally interrupted when the process terminates, the output and the
                         // error pumps have finished and the StdInHandler does not finish by itself. In this case we do not
                 }
             };
         }
+        else if (runWithPowershell)
+        {
+            try
+            {
+                process.getOutputStream().close();
+            }
+            catch (IOException ioe)
+            {
+                //hmm....
+            }
+        }
 
         errorPump = new LatchedRunnable("StdErrHandler " + process) {
 

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

     private boolean useWindowsEncodingWorkaround;
     private File workingDirectory;
 
+    private boolean runWithPowershell;
+
     public ExternalProcessSettings() {
         environment = new HashMap<String, String>();
         monitors = new ArrayList<ProcessMonitor>();
             throw new IllegalStateException("A ProcessHandler is required");
         }
     }
+
+    public boolean isRunWithPowershell()
+    {
+        return runWithPowershell;
+    }
+
+    public void setRunWithPowershell(final boolean runWithPowershell)
+    {
+        this.runWithPowershell = runWithPowershell;
+    }
 }