Browse Source

Use System.getenv where available. Faster and more reliable than /usr/bin/env and its ilk.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@948853 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 15 years ago
parent
commit
35bcdc15f7
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      src/main/org/apache/tools/ant/taskdefs/Execute.java

+ 15
- 0
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import org.apache.tools.ant.BuildException;
@@ -37,6 +38,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;

/**
@@ -156,6 +158,19 @@ public class Execute {
return procEnvironment;
}
procEnvironment = new Vector();
if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) {
try {
Map/*<String,String>*/ env = (Map) System.class.getMethod("getenv", new Class[0]).invoke(null, new Object[0]);
Iterator it = env.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
procEnvironment.add(entry.getKey() + "=" + entry.getValue());
}
return procEnvironment;
} catch (Exception x) {
x.printStackTrace();
}
}
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Execute exe = new Execute(new PumpStreamHandler(out));


Loading…
Cancel
Save