Commits

Michael Heemskerk committed f2bb9d0

CRUC-4793: Refactored the various LineOutputHandlers to no longer use UTF-8 as the default.

Instead, you need to explicitely set the encoding that should be used for parsing the output of external process calls.

The following defaults have been introduced:
* Git: always use UTF-8
* Hg: use the setting specified in the HGENCODING environment variable, if set. If not, use UTF-8. Furthermore the HGENCODING variable will now be set to this value when calls to hg are made from FishEye
* ClearCase: Always use the jvms default encoding.

  • Participants
  • Parent commits 9746cbb

Comments (0)

Files changed (2)

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

 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.Priority;
     private OutputHandler error;
     private List<ProcessMonitor> monitors = new ArrayList<ProcessMonitor>();
     private List<String> command;
+    private Map<String, String> environment = new HashMap<String, String>();
     private File workingDir;
     private long timeout;
 
         return this;
     }
 
+    public ExternalProcessBuilder env(String variable, String value) {
+        environment.put(variable, value);
+        return this;
+    }
+    
+    public ExternalProcessBuilder env(Map<String, String> environment) {
+        environment.putAll(environment);
+        return this;
+    }
+    
     public ExternalProcess build() {
         ProcessHandler h = this.handler;
         if (this.handler == null) {
                 process.addMonitor(monitor);
             }
         }
+        if (!environment.isEmpty()) {
+            String[] env = new String[environment.size()];
+            int index = 0;
+            for (Entry<String, String> entry : environment.entrySet()) {
+                env[index++] = entry.getKey() + "=" + entry.getValue();
+            }
+            process.setEnvironment(env);
+        }
 
         return process;
     }

processutils/src/main/java/com/atlassian/utils/process/LineOutputHandler.java

     private final String encoding;
 
     protected LineOutputHandler() {
-        this("UTF-8");
+        this(null); // if not encoding is defined, use the default encoding from the admin
     }
 
     protected LineOutputHandler(String encoding) {
         this.encoding = encoding;
     }
 
+    public String getEncoding() {
+        return encoding;
+    }
+    
     public void process(InputStream output) throws ProcessException {
         BufferedReader reader = null;
         int counter = 0;