Commits

James Dumay committed a46f4fa

BAM-8297 have option to disable windows encoding work around

Comments (0)

Files changed (2)

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

  * the process' IO requirements.
  */
 public class ExternalProcess implements Watchdog {
+    private boolean useWindowsEncodingWorkaround = true;
     private String[] cmdArray;
     private File workingDir;
     private Map<String, String> environment;
                 || (inputPump != null && inputPump.isRunning());
     }
 
+    public void setUseWindowsEncodingWorkaround(final boolean useWindowsEncodingWorkaround) {
+        this.useWindowsEncodingWorkaround = useWindowsEncodingWorkaround;
+    }
+
     /**
      * Get the process handler for this process execution
      *
         i18n[2] = "/C";
         i18n[3] = "call";
         i18n[extraArgs] = cmdArray[0];
-        for (int counter = 1; counter < cmdArray.length; counter++) {
-            String envName = "JENV_" + counter;
-            i18n[counter + extraArgs] = "%" + envName + "%";
-            newEnv.put(envName, quoteString(cmdArray[counter]));
+
+        if (useWindowsEncodingWorkaround)
+        {
+            for (int counter = 1; counter < cmdArray.length; counter++) {
+                String envName = "JENV_" + counter;
+                i18n[counter + extraArgs] = "%" + envName + "%";
+                newEnv.put(envName, quoteString(cmdArray[counter]));
+            }
         }
         cmdArray = i18n;
 

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

     private final Map<String, String> environment = new HashMap<String, String>();
     private File workingDir;
     private long timeout;
+    private boolean disableWindowsEncodingWorkaround;
 
     public ExternalProcessBuilder handlers(InputHandler input, OutputHandler output, OutputHandler error) {
         this.input = input;
         this.environment.putAll(environment);
         return this;
     }
+
+    public ExternalProcessBuilder disableWindowsEncodingWorkaround()
+    {
+        this.disableWindowsEncodingWorkaround = true;
+        return this;
+    }
     
     public ExternalProcess build() {
         ProcessHandler h = this.handler;
             process.setEnvironment(new HashMap<String, String>(environment));
         }
 
+        if (disableWindowsEncodingWorkaround)
+        {
+            process.setUseWindowsEncodingWorkaround(false);
+        }
+
         return process;
     }
 }