ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r948853 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
Date Thu, 27 May 2010 14:46:15 GMT
Author: jglick
Date: Thu May 27 14:46:15 2010
New Revision: 948853

URL: http://svn.apache.org/viewvc?rev=948853&view=rev
Log:
Use System.getenv where available. Faster and more reliable than /usr/bin/env and its ilk.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java?rev=948853&r1=948852&r2=948853&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java Thu May 27 14:46:15
2010
@@ -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));



Mime
View raw message