ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r949761 - in /ant/sandbox/usertests: ./ env/ env/src/ env/src/main/ env/src/main/org/ env/src/main/org/apache/ env/src/main/org/apache/ant/ env/src/main/org/apache/ant/usertests/ env/src/main/org/apache/ant/usertests/env/
Date Mon, 31 May 2010 14:59:32 GMT
Author: bodewig
Date: Mon May 31 14:59:31 2010
New Revision: 949761

URL: http://svn.apache.org/viewvc?rev=949761&view=rev
Log:
CLI app that compares old and new style of reading environment variables

Added:
    ant/sandbox/usertests/env/
    ant/sandbox/usertests/env/NOTICE
    ant/sandbox/usertests/env/build.xml   (with props)
    ant/sandbox/usertests/env/src/
    ant/sandbox/usertests/env/src/main/
    ant/sandbox/usertests/env/src/main/org/
    ant/sandbox/usertests/env/src/main/org/apache/
    ant/sandbox/usertests/env/src/main/org/apache/ant/
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Execute.java
      - copied, changed from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/ExecuteStreamHandler.java
      - copied, changed from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java   (with props)
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Os.java
      - copied, changed from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Os.java
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/PumpStreamHandler.java
      - copied, changed from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
    ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/StreamPumper.java
      - copied, changed from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
Modified:
    ant/sandbox/usertests/   (props changed)

Propchange: ant/sandbox/usertests/
------------------------------------------------------------------------------
--- svn:externals (added)
+++ svn:externals Mon May 31 14:59:31 2010
@@ -0,0 +1 @@
+common http://svn.apache.org/repos/asf/ant/antlibs/common/trunk

Added: ant/sandbox/usertests/env/NOTICE
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/NOTICE?rev=949761&view=auto
==============================================================================
--- ant/sandbox/usertests/env/NOTICE (added)
+++ ant/sandbox/usertests/env/NOTICE Mon May 31 14:59:31 2010
@@ -0,0 +1,5 @@
+   Copyright 2010 The Apache Software Foundation
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+

Added: ant/sandbox/usertests/env/build.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/build.xml?rev=949761&view=auto
==============================================================================
--- ant/sandbox/usertests/env/build.xml (added)
+++ ant/sandbox/usertests/env/build.xml Mon May 31 14:59:31 2010
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project default="compile" name="usertests.env">
+
+  <property file="build.properties"/>
+  <property name="javac.-source" value="5"/>
+  <property name="javac.-target" value="5"/>
+  <import file="../common/build.xml"/>
+
+  <!-- override to add main class -->
+  <target name="antlib" depends="compile, check-for-NOTICE">
+    <copy todir="${build.classes}">
+      <fileset dir="src/main" includes="**/*.xml,**/*.properties"/>
+    </copy>
+    <jar destfile="${jarname}">
+      <manifest>
+        <attribute name="Main-Class" value="org.apache.ant.usertests.env.Main"/>
+      </manifest>
+      <fileset dir="${build.classes}"/>
+      <metainf file="NOTICE"/>
+      <metainf file="${common.basedir}/LICENSE"/>
+    </jar>
+  </target>
+
+</project>

Propchange: ant/sandbox/usertests/env/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Execute.java (from
r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Execute.java?p2=ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Execute.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java&r1=948685&r2=949761&rev=949761&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java (original)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Execute.java Mon May 31
14:59:31 2010
@@ -16,29 +16,24 @@
  *
  */
 
-package org.apache.tools.ant.taskdefs;
+package org.apache.ant.usertests.env;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileWriter;
+import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.StringReader;
+import java.io.Writer;
+import java.text.DecimalFormat;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Random;
 import java.util.Vector;
 
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.MagicNames;
-import org.apache.tools.ant.Project;
-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.StringUtils;
-
 /**
  * Runs an external program.
  *
@@ -47,6 +42,9 @@ import org.apache.tools.ant.util.StringU
  */
 public class Execute {
 
+    private static Random rand = new Random(System.currentTimeMillis()
+            + Runtime.getRuntime().freeMemory());
+
     private static final int ONE_SECOND = 1000;
 
     /** Invalid exit code.
@@ -54,15 +52,12 @@ public class Execute {
      */
     public static final int INVALID = Integer.MAX_VALUE;
 
-    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
-
     private String[] cmdl = null;
     private String[] env = null;
     private int exitValue = INVALID;
     private ExecuteStreamHandler streamHandler;
-    private ExecuteWatchdog watchdog;
     private File workingDirectory = null;
-    private Project project = null;
+    private Object project = null;
     private boolean newEnvironment = false;
 
     /** Controls whether the VM is used to launch commands, where possible. */
@@ -73,9 +68,6 @@ public class Execute {
     private static CommandLauncher shellLauncher = null;
     private static Vector procEnvironment = null;
 
-    /** Used to destroy processes when the VM exits. */
-    private static ProcessDestroyer processDestroyer = new ProcessDestroyer();
-
     /** Used for replacing env variables */
     private static boolean environmentCaseInSensitive = false;
 
@@ -130,22 +122,6 @@ public class Execute {
     }
 
     /**
-     * Set whether or not you want the process to be spawned.
-     * Default is not spawned.
-     *
-     * @param spawn if true you do not want Ant
-     *              to wait for the end of the process.
-     *              Has no influence in here, the calling task contains
-     *              and acts accordingly
-     *
-     * @since Ant 1.6
-     * @deprecated
-     */
-    public void setSpawn(boolean spawn) {
-        // Method did not do anything to begin with
-    }
-
-    /**
      * Find the list of environment variables for this process.
      *
      * @return a vector containing the environment variables.
@@ -174,7 +150,7 @@ public class Execute {
                 return procEnvironment;
             }
             String var = null;
-            String line, lineSep = StringUtils.LINE_SEP;
+            String line, lineSep = System.getProperty("line.separator");
             while ((line = in.readLine()) != null) {
                 if (line.indexOf('=') == -1) {
                     // Chunk part of previous env var (UNIX env vars can
@@ -277,35 +253,13 @@ public class Execute {
     }
 
     /**
-     * Creates a new execute object using <code>PumpStreamHandler</code> for
-     * stream handling.
-     */
-    public Execute() {
-        this(new PumpStreamHandler(), null);
-    }
-
-    /**
      * Creates a new execute object.
      *
      * @param streamHandler the stream handler used to handle the input and
      *        output streams of the subprocess.
      */
     public Execute(ExecuteStreamHandler streamHandler) {
-        this(streamHandler, null);
-    }
-
-    /**
-     * Creates a new execute object.
-     *
-     * @param streamHandler the stream handler used to handle the input and
-     *        output streams of the subprocess.
-     * @param watchdog a watchdog for the subprocess or <code>null</code> to
-     *        to disable a timeout for the subprocess.
-     */
-    public Execute(ExecuteStreamHandler streamHandler,
-                   ExecuteWatchdog watchdog) {
         setStreamHandler(streamHandler);
-        this.watchdog = watchdog;
         //By default, use the shell launcher for VMS
         //
         if (Os.isFamily("openvms")) {
@@ -360,68 +314,6 @@ public class Execute {
     }
 
     /**
-     * Sets the environment variables for the subprocess to launch.
-     *
-     * @param env array of Strings, each element of which has
-     * an environment variable settings in format <em>key=value</em>.
-     */
-    public void setEnvironment(String[] env) {
-        this.env = env;
-    }
-
-    /**
-     * Sets the working directory of the process to execute.
-     *
-     * <p>This is emulated using the antRun scripts unless the OS is
-     * Windows NT in which case a cmd.exe is spawned,
-     * or MRJ and setting user.dir works, or JDK 1.3 and there is
-     * official support in java.lang.Runtime.
-     *
-     * @param wd the working directory of the process.
-     */
-    public void setWorkingDirectory(File wd) {
-        workingDirectory =
-            (wd == null || wd.getAbsolutePath().equals(antWorkingDirectory))
-            ? null : wd;
-    }
-
-    /**
-     * Return the working directory.
-     * @return the directory as a File.
-     * @since Ant 1.7
-     */
-    public File getWorkingDirectory() {
-        return workingDirectory == null ? new File(antWorkingDirectory)
-                                        : workingDirectory;
-    }
-
-    /**
-     * Set the name of the antRun script using the project's value.
-     *
-     * @param project the current project.
-     *
-     * @throws BuildException not clear when it is going to throw an exception, but
-     * it is the method's signature.
-     */
-    public void setAntRun(Project project) throws BuildException {
-        this.project = project;
-    }
-
-    /**
-     * Launch this execution through the VM, where possible, rather than through
-     * the OS's shell. In some cases and operating systems using the shell will
-     * allow the shell to perform additional processing such as associating an
-     * executable with a script, etc.
-     *
-     * @param useVMLauncher true if exec should launch through the VM,
-     *                   false if the shell should be used to launch the
-     *                   command.
-     */
-    public void setVMLauncher(boolean useVMLauncher) {
-        this.useVMLauncher = useVMLauncher;
-    }
-
-    /**
      * Creates a process that runs a command.
      *
      * @param project the Project, only used for logging purposes, may be null.
@@ -434,11 +326,11 @@ public class Execute {
      *
      * @since Ant 1.5
      */
-    public static Process launch(Project project, String[] command,
+    public static Process launch(Object project, String[] command,
                                  String[] env, File dir, boolean useVM)
         throws IOException {
         if (dir != null && !dir.exists()) {
-            throw new BuildException(dir + " doesn't exist.");
+            throw new RuntimeException(dir + " doesn't exist.");
         }
         CommandLauncher launcher
             = ((useVM && vmLauncher != null) ? vmLauncher : shellLauncher);
@@ -454,7 +346,7 @@ public class Execute {
      */
     public int execute() throws IOException {
         if (workingDirectory != null && !workingDirectory.exists()) {
-            throw new BuildException(workingDirectory + " doesn't exist.");
+            throw new RuntimeException(workingDirectory + " doesn't exist.");
         }
         final Process process = launch(project, getCommandline(),
                                        getEnvironment(), workingDirectory,
@@ -470,77 +362,20 @@ public class Execute {
         streamHandler.start();
 
         try {
-            // add the process to the list of those to destroy if the VM exits
-            //
-            processDestroyer.add(process);
-
-            if (watchdog != null) {
-                watchdog.start(process);
-            }
             waitFor(process);
 
-            if (watchdog != null) {
-                watchdog.stop();
-            }
             streamHandler.stop();
             closeStreams(process);
 
-            if (watchdog != null) {
-                watchdog.checkException();
-            }
             return getExitValue();
         } catch (ThreadDeath t) {
             // #31928: forcibly kill it before continuing.
             process.destroy();
             throw t;
-        } finally {
-            // remove the process to the list of those to destroy if
-            // the VM exits
-            //
-            processDestroyer.remove(process);
         }
     }
 
     /**
-     * Starts a process defined by the command line.
-     * Ant will not wait for this process, nor log its output.
-     *
-     * @throws java.io.IOException The exception is thrown, if launching
-     *            of the subprocess failed.
-     * @since Ant 1.6
-     */
-    public void spawn() throws IOException {
-        if (workingDirectory != null && !workingDirectory.exists()) {
-            throw new BuildException(workingDirectory + " doesn't exist.");
-        }
-        final Process process = launch(project, getCommandline(),
-                                       getEnvironment(), workingDirectory,
-                                       useVMLauncher);
-        if (Os.isFamily("windows")) {
-            try {
-                Thread.sleep(ONE_SECOND);
-            } catch (InterruptedException e) {
-                project.log("interruption in the sleep after having spawned a"
-                            + " process", Project.MSG_VERBOSE);
-            }
-        }
-        OutputStream dummyOut = new OutputStream() {
-            public void write(int b) throws IOException {
-                // Method intended to swallow whatever comes at it
-            }
-        };
-
-        ExecuteStreamHandler handler = new PumpStreamHandler(dummyOut);
-        handler.setProcessErrorStream(process.getErrorStream());
-        handler.setProcessOutputStream(process.getInputStream());
-        handler.start();
-        process.getOutputStream().close();
-
-        project.log("spawned process " + process.toString(),
-                    Project.MSG_VERBOSE);
-    }
-
-    /**
      * Wait for a given process.
      *
      * @param process the process one wants to wait for.
@@ -610,7 +445,7 @@ public class Execute {
      * @since Ant 1.5
      */
     public boolean killedProcess() {
-        return watchdog != null && watchdog.killedProcess();
+        return false;
     }
 
     /**
@@ -657,42 +492,43 @@ public class Execute {
     }
 
     /**
-     * A utility method that runs an external command.  Writes the output and
-     * error streams of the command to the project log.
-     *
-     * @param task      The task that the command is part of.  Used for logging
-     * @param cmdline   The command to execute.
-     *
-     * @throws BuildException if the command does not exit successfully.
+     * Close the streams belonging to the given Process.
+     * @param process   the <code>Process</code>.
      */
-    public static void runCommand(Task task, String[] cmdline)
-        throws BuildException {
-        try {
-            task.log(Commandline.describeCommand(cmdline),
-                     Project.MSG_VERBOSE);
-            Execute exe = new Execute(
-                new LogStreamHandler(task, Project.MSG_INFO, Project.MSG_ERR));
-            exe.setAntRun(task.getProject());
-            exe.setCommandline(cmdline);
-            int retval = exe.execute();
-            if (isFailure(retval)) {
-                throw new BuildException(cmdline[0]
-                    + " failed with return code " + retval, task.getLocation());
+    public static void closeStreams(Process process) {
+        close(process.getInputStream());
+        close(process.getOutputStream());
+        close(process.getErrorStream());
+    }
+
+    public static void close(OutputStream device) {
+        if (null != device) {
+            try {
+                device.close();
+            } catch (IOException e) {
+                //ignore
             }
-        } catch (java.io.IOException exc) {
-            throw new BuildException("Could not launch " + cmdline[0] + ": "
-                + exc, task.getLocation());
         }
     }
 
-    /**
-     * Close the streams belonging to the given Process.
-     * @param process   the <code>Process</code>.
-     */
-    public static void closeStreams(Process process) {
-        FileUtils.close(process.getInputStream());
-        FileUtils.close(process.getOutputStream());
-        FileUtils.close(process.getErrorStream());
+    public static void close(InputStream device) {
+        if (null != device) {
+            try {
+                device.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
+    }
+
+    public static void close(Writer device) {
+        if (null != device) {
+            try {
+                device.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
     }
 
     /**
@@ -764,12 +600,8 @@ public class Execute {
          * @throws IOException if attempting to run a command in a
          * specific directory.
          */
-        public Process exec(Project project, String[] cmd, String[] env)
+        public Process exec(Object project, String[] cmd, String[] env)
              throws IOException {
-            if (project != null) {
-                project.log("Execute:CommandLauncher: "
-                    + Commandline.describeCommand(cmd), Project.MSG_DEBUG);
-            }
             return Runtime.getRuntime().exec(cmd, env);
         }
 
@@ -786,7 +618,7 @@ public class Execute {
          * @return the created Process.
          * @throws IOException  if trying to change directory.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             if (workingDir == null) {
                 return exec(project, cmd, env);
@@ -817,19 +649,15 @@ public class Execute {
          * @return the created Process.
          * @throws IOException probably forwarded from Runtime#exec.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             try {
-                if (project != null) {
-                    project.log("Execute:Java13CommandLauncher: "
-                        + Commandline.describeCommand(cmd), Project.MSG_DEBUG);
-                }
                 return Runtime.getRuntime().exec(cmd, env, workingDir);
             } catch (IOException ioex) {
                 throw ioex;
             } catch (Exception exc) {
                 // IllegalAccess, IllegalArgument, ClassCast
-                throw new BuildException("Unable to execute command", exc);
+                throw new RuntimeException("Unable to execute command", exc);
             }
         }
     }
@@ -856,7 +684,7 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env)
+        public Process exec(Object project, String[] cmd, String[] env)
             throws IOException {
             return myLauncher.exec(project, cmd, env);
         }
@@ -886,15 +714,11 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             File commandDir = workingDir;
             if (workingDir == null) {
-                if (project != null) {
-                    commandDir = project.getBaseDir();
-                } else {
                     return exec(project, cmd, env);
-                }
             }
             // Use cmd.exe to change to the specified drive and
             // directory before running the command
@@ -937,15 +761,11 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             File commandDir = workingDir;
             if (workingDir == null) {
-                if (project != null) {
-                    commandDir = project.getBaseDir();
-                } else {
                     return exec(project, cmd, env);
-                }
             }
             // Use cmd.exe to change to the specified directory before running
             // the command
@@ -985,7 +805,7 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             if (workingDir == null) {
                 return exec(project, cmd, env);
@@ -1020,36 +840,13 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
-            if (project == null) {
                 if (workingDir == null) {
                     return exec(project, cmd, env);
                 }
                 throw new IOException("Cannot locate antRun script: "
                     + "No project provided");
-            }
-            // Locate the auxiliary script
-            String antHome = project.getProperty(MagicNames.ANT_HOME);
-            if (antHome == null) {
-                throw new IOException("Cannot locate antRun script: "
-                    + "Property '" + MagicNames.ANT_HOME + "' not found");
-            }
-            String antRun =
-                FILE_UTILS.resolveFile(project.getBaseDir(),
-                        antHome + File.separator + myScript).toString();
-
-            // Build the command
-            File commandDir = workingDir;
-            if (workingDir == null) {
-                commandDir = project.getBaseDir();
-            }
-            String[] newcmd = new String[cmd.length + 2];
-            newcmd[0] = antRun;
-            newcmd[1] = commandDir.getAbsolutePath();
-            System.arraycopy(cmd, 0, newcmd, 2, cmd.length);
-
-            return exec(project, newcmd, env);
         }
 
         private String myScript;
@@ -1079,39 +876,13 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
-            if (project == null) {
                 if (workingDir == null) {
                     return exec(project, cmd, env);
                 }
                 throw new IOException("Cannot locate antRun script: "
                     + "No project provided");
-            }
-            // Locate the auxiliary script
-            String antHome = project.getProperty(MagicNames.ANT_HOME);
-            if (antHome == null) {
-                throw new IOException("Cannot locate antRun script: "
-                    + "Property '" + MagicNames.ANT_HOME + "' not found");
-            }
-            String antRun =
-                FILE_UTILS.resolveFile(project.getBaseDir(),
-                        antHome + File.separator + myScript).toString();
-
-            // Build the command
-            File commandDir = workingDir;
-            if (workingDir == null) {
-                commandDir = project.getBaseDir();
-            }
-            // CheckStyle:MagicNumber OFF
-            String[] newcmd = new String[cmd.length + 3];
-            newcmd[0] = "perl";
-            newcmd[1] = antRun;
-            newcmd[2] = commandDir.getAbsolutePath();
-            System.arraycopy(cmd, 0, newcmd, 3, cmd.length);
-            // CheckStyle:MagicNumber ON
-
-            return exec(project, newcmd, env);
         }
     }
 
@@ -1135,7 +906,7 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env)
+        public Process exec(Object project, String[] cmd, String[] env)
             throws IOException {
             File cmdFile = createCommandFile(cmd, env);
             Process p
@@ -1157,7 +928,7 @@ public class Execute {
          * @throws IOException forwarded from the exec method of the
          * command launcher.
          */
-        public Process exec(Project project, String[] cmd, String[] env,
+        public Process exec(Object project, String[] cmd, String[] env,
                             File workingDir) throws IOException {
             File cmdFile = createCommandFile(cmd, env);
             Process p = super.exec(project, new String[] {cmdFile.getPath()},
@@ -1176,7 +947,7 @@ public class Execute {
          */
         private File createCommandFile(String[] cmd, String[] env)
             throws IOException {
-            File script = FILE_UTILS.createTempFile("ANT", ".COM", null, true, true);
+            File script = createTempFile("ANT", ".COM", null, true, true);
             BufferedWriter out = null;
             try {
                 out = new BufferedWriter(new FileWriter(script));
@@ -1203,7 +974,7 @@ public class Execute {
                     out.write(cmd[i]);
                 }
             } finally {
-                FileUtils.close(out);
+                close(out);
             }
             return script;
         }
@@ -1216,10 +987,40 @@ public class Execute {
                     } catch (InterruptedException e) {
                         //ignore
                     }
-                    FileUtils.delete(f);
+                    f.delete();
                 }
             }
             .start();
         }
+
+        public File createTempFile(String prefix, String suffix, File parentDir,
+                                   boolean deleteOnExit, boolean createFile) {
+            File result = null;
+            String parent = (parentDir == null)
+                ? System.getProperty("java.io.tmpdir")
+                : parentDir.getPath();
+            
+            if (createFile) {
+                try {
+                    result = File.createTempFile(prefix, suffix, new File(parent));
+                } catch (IOException e) {
+                    throw new RuntimeException("Could not create tempfile in "
+                                             + parent, e);
+                }
+            } else {
+                DecimalFormat fmt = new DecimalFormat("#####");
+                synchronized (rand) {
+                    do {
+                        result = new File(parent, prefix
+                                          + fmt.format(rand.nextInt(Integer.MAX_VALUE)) +
suffix);
+                    } while (result.exists());
+                }
+            }
+            
+            if (deleteOnExit) {
+                result.deleteOnExit();
+            }
+            return result;
+        }
     }
 }

Copied: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/ExecuteStreamHandler.java
(from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/ExecuteStreamHandler.java?p2=ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/ExecuteStreamHandler.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java&r1=948685&r2=949761&rev=949761&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java (original)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/ExecuteStreamHandler.java
Mon May 31 14:59:31 2010
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.tools.ant.taskdefs;
+package org.apache.ant.usertests.env;
 
 import java.io.IOException;
 import java.io.InputStream;

Added: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java?rev=949761&view=auto
==============================================================================
--- ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java (added)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java Mon May 31 14:59:31
2010
@@ -0,0 +1,90 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ant.usertests.env;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+
+public class Main {
+
+    public static void main(String[] args) {
+        System.out.println("Detected OS_NAME: " + Os.OS_NAME);
+        System.out.println("Detected OS_ARCH: " + Os.OS_ARCH);
+        System.out.println("Detected OS_VERSION: " + Os.OS_VERSION);
+
+        final boolean verbose = args.length > 0 && args[0].equals("-v");
+        Vector oldStyle = Execute.getProcEnvironment();
+        Collections.sort(oldStyle);
+        if (verbose) {
+            System.out.println("");
+            System.out.println("Ant 1.8.1 way:");
+            System.out.println("==============");
+            for (Object s : oldStyle) {
+                System.out.println(s);
+            }
+        }
+        Vector newStyle = newStyle();
+        Collections.sort(newStyle);
+        if (verbose) {
+            System.out.println("");
+            System.out.println("Ant 1.8.2 way:");
+            System.out.println("==============");
+            for (Object s : oldStyle) {
+                System.out.println(s);
+            }
+        }
+
+        System.out.println("");
+
+        int os = oldStyle.size(), ns = newStyle.size();
+        boolean differences = os != ns;
+        for (int oi = 0, ni = 0; oi < os && ni < ns; ) {
+            String oldLine = (String) oldStyle.get(oi);
+            String newLine = (String) newStyle.get(ni);
+            if (oldLine.equals(newLine)) {
+                oi++;
+                ni++;
+            } else if (oldLine.compareTo(newLine) <= 0) {
+                System.out.println("Only in 1.8.1: " + oldLine);
+                oi++;
+            } else {
+                System.out.println("Only in 1.8.2: " + newLine);
+                ni++;
+            }
+        }
+
+        if (!differences) {
+            System.out.println("Both methods returned the same"
+                               + " environment information");
+        }
+    }
+
+    private static Vector newStyle() {
+        Vector procEnvironment = new Vector();
+        Map<String,String> env = System.getenv();
+        Iterator<Map.Entry<String, String>> it = env.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry<String, String> entry = it.next();
+            procEnvironment.add(entry.getKey() + "=" + entry.getValue());
+        }
+        return procEnvironment;
+    }
+}
\ No newline at end of file

Propchange: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Os.java (from r948685,
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Os.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Os.java?p2=ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Os.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Os.java&r1=948685&r2=949761&rev=949761&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Os.java (original)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/Os.java Mon May 31 14:59:31
2010
@@ -16,25 +16,23 @@
  *
  */
 
-package org.apache.tools.ant.taskdefs.condition;
+package org.apache.ant.usertests.env;
 
 import java.util.Locale;
 
-import org.apache.tools.ant.BuildException;
-
 /**
  * Condition that tests the OS type.
  *
  * @since Ant 1.4
  */
-public class Os implements Condition {
-    private static final String OS_NAME =
+public class Os {
+    static final String OS_NAME =
         System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
-    private static final String OS_ARCH =
+    static final String OS_ARCH =
         System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
-    private static final String OS_VERSION =
+    static final String OS_VERSION =
         System.getProperty("os.version").toLowerCase(Locale.ENGLISH);
-    private static final String PATH_SEP =
+    static final String PATH_SEP =
         System.getProperty("path.separator");
 
     /**
@@ -176,10 +174,9 @@ public class Os implements Condition {
      * Determines if the OS on which Ant is executing matches the type of
      * that set in setFamily.
      * @return true if the os matches.
-     * @throws BuildException if there is an error.
      * @see Os#setFamily(String)
      */
-    public boolean eval() throws BuildException {
+    public boolean eval() {
         return isOs(family, name, arch, version);
     }
 
@@ -300,7 +297,7 @@ public class Os implements Condition {
                 } else if (family.equals(FAMILY_VMS)) {
                     isFamily = OS_NAME.indexOf(FAMILY_VMS) > -1;
                 } else {
-                    throw new BuildException(
+                    throw new RuntimeException(
                         "Don\'t know how to detect os family \""
                         + family + "\"");
                 }

Copied: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/PumpStreamHandler.java
(from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/PumpStreamHandler.java?p2=ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/PumpStreamHandler.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java&r1=948685&r2=949761&rev=949761&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java (original)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/PumpStreamHandler.java
Mon May 31 14:59:31 2010
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.tools.ant.taskdefs;
+package org.apache.ant.usertests.env;
 
 import java.io.IOException;
 import java.io.InputStream;

Copied: ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/StreamPumper.java
(from r948685, ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/StreamPumper.java?p2=ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/StreamPumper.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java&r1=948685&r2=949761&rev=949761&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java (original)
+++ ant/sandbox/usertests/env/src/main/org/apache/ant/usertests/env/StreamPumper.java Mon
May 31 14:59:31 2010
@@ -15,12 +15,11 @@
  *  limitations under the License.
  *
  */
-package org.apache.tools.ant.taskdefs;
+package org.apache.ant.usertests.env;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Copies all data from an input stream to an output stream.
@@ -147,7 +146,7 @@ public class StreamPumper implements Run
             }
         } finally {
             if (closeWhenExhausted) {
-                FileUtils.close(os);
+                Execute.close(os);
             }
             finished = true;
             synchronized (this) {



Mime
View raw message