commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r230452 [2/3] - in /jakarta/commons/sandbox/exec/trunk: ./ src/ src/bin/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/exec/ src/main/java/org/apache...
Date Fri, 05 Aug 2005 12:22:17 GMT
Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,51 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.io.IOException;
+
+/**
+ * Logs standard output and error of a subprocess to the log system of ant.
+ */
+public class LogStreamHandler extends PumpStreamHandler {
+
+    /**
+     * Creates log stream handler.
+     * 
+     * @param outlevel
+     *            the loglevel used to log standard output
+     * @param errlevel
+     *            the loglevel used to log standard error
+     */
+    public LogStreamHandler(final int outlevel, final int errlevel) {
+        super(new LogOutputStream(outlevel), new LogOutputStream(errlevel));
+    }
+
+    /**
+     * Stop the log stream handler.
+     */
+    public void stop() {
+        super.stop();
+        try {
+            getErr().close();
+            getOut().close();
+        } catch (IOException e) {
+            // ignore
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/LogStreamHandler.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,243 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.util.Locale;
+
+/**
+ * Condition that tests the OS type.
+ */
+public final class OS {
+    private static final String FAMILY_OS_400 = "os/400";
+
+    private static final String FAMILY_Z_OS = "z/os";
+
+    private static final String FAMILY_WIN9X = "win9x";
+
+    private static final String FAMILY_OPENVMS = "openvms";
+
+    private static final String FAMILY_UNIX = "unix";
+
+    private static final String FAMILY_TANDEM = "tandem";
+
+    private static final String FAMILY_MAC = "mac";
+
+    private static final String FAMILY_DOS = "dos";
+
+    private static final String FAMILY_NETWARE = "netware";
+
+    private static final String FAMILY_OS_2 = "os/2";
+
+    private static final String FAMILY_WINDOWS = "windows";
+
+    private static final String OS_NAME = System.getProperty("os.name")
+            .toLowerCase(Locale.US);
+
+    private static final String OS_ARCH = System.getProperty("os.arch")
+            .toLowerCase(Locale.US);
+
+    private static final String OS_VERSION = System.getProperty("os.version")
+            .toLowerCase(Locale.US);
+
+    private static final String PATH_SEP = System.getProperty("path.separator");
+
+    /**
+     * Default constructor
+     */
+    private OS() {
+    }
+
+    /**
+     * Determines if the OS on which Ant is executing matches the given OS
+     * family. * Possible values:<br />
+     * <ul>
+     * <li>dos</li>
+     * <li>mac</li>
+     * <li>netware</li>
+     * <li>os/2</li>
+     * <li>tandem</li>
+     * <li>unix</li>
+     * <li>windows</li>
+     * <li>win9x</li>
+     * <li>z/os</li>
+     * <li>os/400</li>
+     * </ul>
+     * 
+     * @param family
+     *            the family to check for
+     * @return true if the OS matches
+     */
+    private static boolean isFamily(final String family) {
+        return isOs(family, null, null, null);
+    }
+
+    public static boolean isFamilyDOS() {
+        return isFamily(FAMILY_DOS);
+    }
+
+    public static boolean isFamilyMac() {
+        return isFamily(FAMILY_MAC);
+    }
+
+    public static boolean isFamilyNetware() {
+        return isFamily(FAMILY_NETWARE);
+    }
+
+    public static boolean isFamilyOS2() {
+        return isFamily(FAMILY_OS_2);
+    }
+
+    public static boolean isFamilyTandem() {
+        return isFamily(FAMILY_TANDEM);
+    }
+
+    public static boolean isFamilyUnix() {
+        return isFamily(FAMILY_UNIX);
+    }
+
+    public static boolean isFamilyWindows() {
+        return isFamily(FAMILY_WINDOWS);
+    }
+
+    public static boolean isFamilyWin9x() {
+        return isFamily(FAMILY_WIN9X);
+    }
+
+    public static boolean isFamilyZOS() {
+        return isFamily(FAMILY_Z_OS);
+    }
+
+    public static boolean isFamilyOS400() {
+        return isFamily(FAMILY_OS_400);
+    }
+
+    public static boolean isFamilyOpenVms() {
+        return isFamily(FAMILY_OPENVMS);
+    }
+
+    /**
+     * Determines if the OS on which Ant is executing matches the given OS name.
+     * 
+     * @param name
+     *            the OS name to check for
+     * @return true if the OS matches
+     */
+    public static boolean isName(final String name) {
+        return isOs(null, name, null, null);
+    }
+
+    /**
+     * Determines if the OS on which Ant is executing matches the given OS
+     * architecture.
+     * 
+     * @param arch
+     *            the OS architecture to check for
+     * @return true if the OS matches
+     */
+    public static boolean isArch(final String arch) {
+        return isOs(null, null, arch, null);
+    }
+
+    /**
+     * Determines if the OS on which Ant is executing matches the given OS
+     * version.
+     * 
+     * @param version
+     *            the OS version to check for
+     * @return true if the OS matches
+     */
+    public static boolean isVersion(final String version) {
+        return isOs(null, null, null, version);
+    }
+
+    /**
+     * Determines if the OS on which Ant is executing matches the given OS
+     * family, name, architecture and version
+     * 
+     * @param family
+     *            The OS family
+     * @param name
+     *            The OS name
+     * @param arch
+     *            The OS architecture
+     * @param version
+     *            The OS version
+     * @return true if the OS matches
+     */
+    public static boolean isOs(final String family, final String name,
+            final String arch, final String version) {
+        boolean retValue = false;
+
+        if (family != null || name != null || arch != null || version != null) {
+
+            boolean isFamily = true;
+            boolean isName = true;
+            boolean isArch = true;
+            boolean isVersion = true;
+
+            if (family != null) {
+                if (family.equals(FAMILY_WINDOWS)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_WINDOWS) > -1;
+                } else if (family.equals(FAMILY_OS_2)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_OS_2) > -1;
+                } else if (family.equals(FAMILY_NETWARE)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_NETWARE) > -1;
+                } else if (family.equals(FAMILY_DOS)) {
+                    isFamily = PATH_SEP.equals(";")
+                            && !isFamily(FAMILY_NETWARE);
+                } else if (family.equals(FAMILY_MAC)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_MAC) > -1;
+                } else if (family.equals(FAMILY_TANDEM)) {
+                    isFamily = OS_NAME.indexOf("nonstop_kernel") > -1;
+                } else if (family.equals(FAMILY_UNIX)) {
+                    isFamily = PATH_SEP.equals(":")
+                            && !isFamily(FAMILY_OPENVMS)
+                            && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x"));
+                } else if (family.equals(FAMILY_WIN9X)) {
+                    isFamily = isFamily(FAMILY_WINDOWS)
+                            && (OS_NAME.indexOf("95") >= 0
+                                    || OS_NAME.indexOf("98") >= 0
+                                    || OS_NAME.indexOf("me") >= 0 || OS_NAME
+                                    .indexOf("ce") >= 0);
+                } else if (family.equals(FAMILY_Z_OS)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_Z_OS) > -1
+                            || OS_NAME.indexOf("os/390") > -1;
+                } else if (family.equals(FAMILY_OS_400)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_OS_400) > -1;
+                } else if (family.equals(FAMILY_OPENVMS)) {
+                    isFamily = OS_NAME.indexOf(FAMILY_OPENVMS) > -1;
+                } else {
+                    throw new IllegalArgumentException(
+                            "Don\'t know how to detect os family \"" + family
+                                    + "\"");
+                }
+            }
+            if (name != null) {
+                isName = name.equals(OS_NAME);
+            }
+            if (arch != null) {
+                isArch = arch.equals(OS_ARCH);
+            }
+            if (version != null) {
+                isVersion = version.equals(OS_VERSION);
+            }
+            retValue = isFamily && isName && isArch && isVersion;
+        }
+        return retValue;
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/OS.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,225 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Destroys all registered <code>Process</code>es when the VM exits.
+ */
+class ProcessDestroyer implements Runnable {
+
+    private Vector processes = new Vector();
+
+    // methods to register and unregister shutdown hooks
+    private Method addShutdownHookMethod;
+
+    private Method removeShutdownHookMethod;
+
+    private ProcessDestroyerImpl destroyProcessThread = null;
+
+    // whether or not this ProcessDestroyer has been registered as a
+    // shutdown hook
+    private boolean added = false;
+
+    // whether or not this ProcessDestroyer is currently running as
+    // shutdown hook
+    private boolean running = false;
+
+    private class ProcessDestroyerImpl extends Thread {
+        private boolean shouldDestroy = true;
+
+        public ProcessDestroyerImpl() {
+            super("ProcessDestroyer Shutdown Hook");
+        }
+
+        public void run() {
+            if (shouldDestroy) {
+                ProcessDestroyer.this.run();
+            }
+        }
+
+        public void setShouldDestroy(final boolean shouldDestroy) {
+            this.shouldDestroy = shouldDestroy;
+        }
+    }
+
+    /**
+     * Constructs a <code>ProcessDestroyer</code> and obtains
+     * <code>Runtime.addShutdownHook()</code> and
+     * <code>Runtime.removeShutdownHook()</code> through reflection. The
+     * ProcessDestroyer manages a list of processes to be destroyed when the VM
+     * exits. If a process is added when the list is empty, this
+     * <code>ProcessDestroyer</code> is registered as a shutdown hook. If
+     * removing a process results in an empty list, the
+     * <code>ProcessDestroyer</code> is removed as a shutdown hook.
+     */
+    public ProcessDestroyer() {
+        try {
+            // check to see if the shutdown hook methods exists
+            // (support pre-JDK 1.3 VMs)
+            Class[] paramTypes = {Thread.class};
+            addShutdownHookMethod = Runtime.class.getMethod("addShutdownHook",
+                    paramTypes);
+
+            removeShutdownHookMethod = Runtime.class.getMethod(
+                    "removeShutdownHook", paramTypes);
+            // wait to add shutdown hook as needed
+        } catch (NoSuchMethodException e) {
+            // it just won't be added as a shutdown hook... :(
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Registers this <code>ProcessDestroyer</code> as a shutdown hook, uses
+     * reflection to ensure pre-JDK 1.3 compatibility.
+     */
+    private void addShutdownHook() {
+        if (addShutdownHookMethod != null && !running) {
+            destroyProcessThread = new ProcessDestroyerImpl();
+            Object[] args = {destroyProcessThread};
+            try {
+                addShutdownHookMethod.invoke(Runtime.getRuntime(), args);
+                added = true;
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            } catch (InvocationTargetException e) {
+                Throwable t = e.getTargetException();
+                if (t != null && t.getClass() == IllegalStateException.class) {
+                    // shutdown already is in progress
+                    running = true;
+                } else {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    /**
+     * Removes this <code>ProcessDestroyer</code> as a shutdown hook, uses
+     * reflection to ensure pre-JDK 1.3 compatibility
+     */
+    private void removeShutdownHook() {
+        if (removeShutdownHookMethod != null && added && !running) {
+            Object[] args = {destroyProcessThread};
+            try {
+                Boolean removed = (Boolean) removeShutdownHookMethod.invoke(
+                        Runtime.getRuntime(), args);
+                if (!removed.booleanValue()) {
+                    System.err.println("Could not remove shutdown hook");
+                }
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            } catch (InvocationTargetException e) {
+                Throwable t = e.getTargetException();
+                if (t != null && t.getClass() == IllegalStateException.class) {
+                    // shutdown already is in progress
+                    running = true;
+                } else {
+                    e.printStackTrace();
+                }
+            }
+            /*
+             * start the hook thread, a unstarted thread may not be
+             * eligible for garbage collection
+             * Cf.:
+             * http://developer.java.sun.com/developer/
+             * bugParade/bugs/4533087.html
+             */ 
+
+            destroyProcessThread.setShouldDestroy(false);
+            destroyProcessThread.start();
+            // this should return quickly, since it basically is a NO-OP.
+            try {
+                destroyProcessThread.join(20000);
+            } catch (InterruptedException ie) {
+                // the thread didn't die in time
+                // it should not kill any processes unexpectedly
+            }
+            destroyProcessThread = null;
+            added = false;
+        }
+    }
+
+    /**
+     * Returns whether or not the ProcessDestroyer is registered as as shutdown
+     * hook
+     * 
+     * @return true if this is currently added as shutdown hook
+     */
+    public boolean isAddedAsShutdownHook() {
+        return added;
+    }
+
+    /**
+     * Returns <code>true</code> if the specified <code>Process</code> was
+     * successfully added to the list of processes to destroy upon VM exit.
+     * 
+     * @param process
+     *            the process to add
+     * @return <code>true</code> if the specified <code>Process</code> was
+     *         successfully added
+     */
+    public boolean add(final Process process) {
+        synchronized (processes) {
+            // if this list is empty, register the shutdown hook
+            if (processes.size() == 0) {
+                addShutdownHook();
+            }
+            processes.addElement(process);
+            return processes.contains(process);
+        }
+    }
+
+    /**
+     * Returns <code>true</code> if the specified <code>Process</code> was
+     * successfully removed from the list of processes to destroy upon VM exit.
+     * 
+     * @param process
+     *            the process to remove
+     * @return <code>true</code> if the specified <code>Process</code> was
+     *         successfully removed
+     */
+    public boolean remove(final Process process) {
+        synchronized (processes) {
+            boolean processRemoved = processes.removeElement(process);
+            if (processRemoved && processes.size() == 0) {
+                removeShutdownHook();
+            }
+            return processRemoved;
+        }
+    }
+
+    /**
+     * Invoked by the VM when it is exiting.
+     */
+    public void run() {
+        synchronized (processes) {
+            running = true;
+            Enumeration e = processes.elements();
+            while (e.hasMoreElements()) {
+                ((Process) e.nextElement()).destroy();
+            }
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,241 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Copies standard output and error of subprocesses to standard output and error
+ * of the parent process.
+ */
+public class PumpStreamHandler implements ExecuteStreamHandler {
+
+    private Thread outputThread;
+
+    private Thread errorThread;
+
+    private Thread inputThread;
+
+    private OutputStream out;
+
+    private OutputStream err;
+
+    private InputStream input;
+
+    /**
+     * Construct a new <CODE>PumpStreamHandler</CODE>.
+     * 
+     * @param out
+     *            the output <CODE>OutputStream</CODE>.
+     * @param err
+     *            the error <CODE>OutputStream</CODE>.
+     * @param input
+     *            the input <CODE>InputStream</CODE>.
+     */
+    public PumpStreamHandler(final OutputStream out, final OutputStream err,
+            final InputStream input) {
+        this.out = out;
+        this.err = err;
+        this.input = input;
+    }
+
+    /**
+     * Construct a new <CODE>PumpStreamHandler</CODE>.
+     * 
+     * @param out
+     *            the output <CODE>OutputStream</CODE>.
+     * @param err
+     *            the error <CODE>OutputStream</CODE>.
+     */
+    public PumpStreamHandler(final OutputStream out, final OutputStream err) {
+        this(out, err, null);
+    }
+
+    /**
+     * Construct a new <CODE>PumpStreamHandler</CODE>.
+     * 
+     * @param outAndErr
+     *            the output/error <CODE>OutputStream</CODE>.
+     */
+    public PumpStreamHandler(final OutputStream outAndErr) {
+        this(outAndErr, outAndErr);
+    }
+
+    /**
+     * Construct a new <CODE>PumpStreamHandler</CODE>.
+     */
+    public PumpStreamHandler() {
+        this(System.out, System.err);
+    }
+
+    /**
+     * Set the <CODE>InputStream</CODE> from which to read the standard output
+     * of the process.
+     * 
+     * @param is
+     *            the <CODE>InputStream</CODE>.
+     */
+    public void setProcessOutputStream(final InputStream is) {
+        createProcessOutputPump(is, out);
+    }
+
+    /**
+     * Set the <CODE>InputStream</CODE> from which to read the standard error
+     * of the process.
+     * 
+     * @param is
+     *            the <CODE>InputStream</CODE>.
+     */
+    public void setProcessErrorStream(final InputStream is) {
+        if (err != null) {
+            createProcessErrorPump(is, err);
+        }
+    }
+
+    /**
+     * Set the <CODE>OutputStream</CODE> by means of which input can be sent
+     * to the process.
+     * 
+     * @param os
+     *            the <CODE>OutputStream</CODE>.
+     */
+    public void setProcessInputStream(final OutputStream os) {
+        if (input != null) {
+            inputThread = createPump(input, os, true);
+        } else {
+            try {
+                os.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+    }
+
+    /**
+     * Start the <CODE>Thread</CODE>s.
+     */
+    public void start() {
+        outputThread.start();
+        errorThread.start();
+        if (inputThread != null) {
+            inputThread.start();
+        }
+    }
+
+    /**
+     * Stop pumping the streams.
+     */
+    public void stop() {
+        try {
+            outputThread.join();
+        } catch (InterruptedException e) {
+            // ignore
+        }
+        try {
+            errorThread.join();
+        } catch (InterruptedException e) {
+            // ignore
+        }
+
+        if (inputThread != null) {
+            try {
+                inputThread.join();
+            } catch (InterruptedException e) {
+                // ignore
+            }
+        }
+
+        try {
+            err.flush();
+        } catch (IOException e) {
+            // ignore
+        }
+        try {
+            out.flush();
+        } catch (IOException e) {
+            // ignore
+        }
+    }
+
+    /**
+     * Get the error stream.
+     * 
+     * @return <CODE>OutputStream</CODE>.
+     */
+    protected OutputStream getErr() {
+        return err;
+    }
+
+    /**
+     * Get the output stream.
+     * 
+     * @return <CODE>OutputStream</CODE>.
+     */
+    protected OutputStream getOut() {
+        return out;
+    }
+
+    /**
+     * Create the pump to handle process output.
+     * 
+     * @param is
+     *            the <CODE>InputStream</CODE>.
+     * @param os
+     *            the <CODE>OutputStream</CODE>.
+     */
+    protected void createProcessOutputPump(final InputStream is,
+            final OutputStream os) {
+        outputThread = createPump(is, os);
+    }
+
+    /**
+     * Create the pump to handle error output.
+     * 
+     * @param is
+     *            the <CODE>InputStream</CODE>.
+     * @param os
+     *            the <CODE>OutputStream</CODE>.
+     */
+    protected void createProcessErrorPump(final InputStream is,
+            final OutputStream os) {
+        errorThread = createPump(is, os);
+    }
+
+    /**
+     * Creates a stream pumper to copy the given input stream to the given
+     * output stream.
+     */
+    protected Thread createPump(final InputStream is, final OutputStream os) {
+        return createPump(is, os, false);
+    }
+
+    /**
+     * Creates a stream pumper to copy the given input stream to the given
+     * output stream.
+     */
+    protected Thread createPump(final InputStream is, final OutputStream os,
+            final boolean closeWhenExhausted) {
+        final Thread result = new Thread(new StreamPumper(is, os,
+                closeWhenExhausted));
+        result.setDaemon(true);
+        return result;
+    }
+
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,125 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Copies all data from an input stream to an output stream.
+ */
+public class StreamPumper implements Runnable {
+
+    // TODO: make SIZE an instance variable.
+    // TODO: add a status flag to note if an error occurred in run.
+
+    private static final int SIZE = 128;
+
+    private InputStream is;
+
+    private OutputStream os;
+
+    private boolean finished;
+
+    private boolean closeWhenExhausted;
+
+    /**
+     * Create a new stream pumper.
+     * 
+     * @param is
+     *            input stream to read data from
+     * @param os
+     *            output stream to write data to.
+     * @param closeWhenExhausted
+     *            if true, the output stream will be closed when the input is
+     *            exhausted.
+     */
+    public StreamPumper(final InputStream is, final OutputStream os,
+            final boolean closeWhenExhausted) {
+        this.is = is;
+        this.os = os;
+        this.closeWhenExhausted = closeWhenExhausted;
+    }
+
+    /**
+     * Create a new stream pumper.
+     * 
+     * @param is
+     *            input stream to read data from
+     * @param os
+     *            output stream to write data to.
+     */
+    public StreamPumper(final InputStream is, final OutputStream os) {
+        this(is, os, false);
+    }
+
+    /**
+     * Copies data from the input stream to the output stream. Terminates as
+     * soon as the input stream is closed or an error occurs.
+     */
+    public void run() {
+        synchronized (this) {
+            // Just in case this object is reused in the future
+            finished = false;
+        }
+
+        final byte[] buf = new byte[SIZE];
+
+        int length;
+        try {
+            while ((length = is.read(buf)) > 0) {
+                os.write(buf, 0, length);
+            }
+        } catch (Exception e) {
+            // ignore errors
+        } finally {
+            if (closeWhenExhausted) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            synchronized (this) {
+                finished = true;
+                notifyAll();
+            }
+        }
+    }
+
+    /**
+     * Tells whether the end of the stream has been reached.
+     * 
+     * @return true is the stream has been exhausted.
+     */
+    public synchronized boolean isFinished() {
+        return finished;
+    }
+
+    /**
+     * This method blocks until the stream pumper finishes.
+     * 
+     * @see #isFinished()
+     */
+    public synchronized void waitFor() throws InterruptedException {
+        while (!isFinished()) {
+            wait();
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/StreamPumper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,34 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+/**
+ * Interface for classes that want to be notified by Watchdog.
+ * 
+ * @see org.apache.commons.exec.Watchdog
+ */
+public interface TimeoutObserver {
+
+    /**
+     * Called when the watchdow times out.
+     * 
+     * @param w
+     *            the watchdog that timed out.
+     */
+    void timeoutOccured(Watchdog w);
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/TimeoutObserver.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,84 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Generalization of <code>ExecuteWatchdog</code>
+ * 
+ * @see org.apache.commons.exec.ExecuteWatchdog
+ */
+public class Watchdog implements Runnable {
+
+    private Vector observers = new Vector(1);
+
+    private long timeout = -1;
+
+    private boolean stopped = false;
+
+    public Watchdog(final long timeout) {
+        if (timeout < 1) {
+            throw new IllegalArgumentException("timeout lesser than 1.");
+        }
+        this.timeout = timeout;
+    }
+
+    public void addTimeoutObserver(final TimeoutObserver to) {
+        observers.addElement(to);
+    }
+
+    public void removeTimeoutObserver(final TimeoutObserver to) {
+        observers.removeElement(to);
+    }
+
+    protected final void fireTimeoutOccured() {
+        Enumeration e = observers.elements();
+        while (e.hasMoreElements()) {
+            ((TimeoutObserver) e.nextElement()).timeoutOccured(this);
+        }
+    }
+
+    public synchronized void start() {
+        stopped = false;
+        Thread t = new Thread(this, "WATCHDOG");
+        t.setDaemon(true);
+        t.start();
+    }
+
+    public synchronized void stop() {
+        stopped = true;
+        notifyAll();
+    }
+
+    public synchronized void run() {
+        final long until = System.currentTimeMillis() + timeout;
+        long now;
+        while (!stopped && until > (now = System.currentTimeMillis())) {
+            try {
+                wait(until - now);
+            } catch (InterruptedException e) {
+            }
+        }
+        if (!stopped) {
+            fireTimeoutOccured();
+        }
+    }
+
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Watchdog.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,244 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec.environment;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+import org.apache.commons.exec.Execute;
+import org.apache.commons.exec.OS;
+import org.apache.commons.exec.PumpStreamHandler;
+
+/**
+ * Wrapper for environment variables.
+ */
+public class Environment extends HashMap {
+
+    public static Environment createEnvironment() {
+        if (OS.isFamilyOpenVms()) {
+            return new OpenVmsEnvironment();
+        } else {
+            return new Environment();
+        }
+    }
+
+    public static Environment createEnvironment(String[] envVars) {
+        Environment env = createEnvironment();
+
+        if(envVars != null) {
+            for (int i = 0; i < envVars.length; i++) {
+                env.addVariable(EnvironmentVariable
+                        .createEnvironmentVariable(envVars[i]));
+            }
+        }
+        return env;
+    }
+
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3256443594801165364L;
+
+    /**
+     * a vector of type EnvirommentVariable
+     * 
+     * @see EnvironmentVariable
+     */
+
+    private static Environment procEnvironment;
+
+    /**
+     * constructor
+     */
+    protected Environment() {
+    }
+
+    /**
+     * add a variable. Validity checking is <i>not</i> performed at this point.
+     * Duplicates are not caught either.
+     * 
+     * @param var
+     *            new variable.
+     */
+    public void addVariable(final EnvironmentVariable var) {
+        put(var.getKey(), var);
+    }
+
+    public void addVariable(final String key, final String value) {
+        put(key, EnvironmentVariable.createEnvironmentVariable(key, value));
+    }
+
+    /**
+     * get the variable list as an array
+     * 
+     * @return array of key=value assignment strings
+     */
+    public String[] getVariables() {
+        if (size() == 0) {
+            return null;
+        }
+        String[] result = new String[size()];
+        int i = 0;
+        for (Iterator iter = entrySet().iterator(); iter.hasNext();) {
+            Map.Entry entry = (Map.Entry) iter.next();
+
+            result[i] = ((EnvironmentVariable) entry.getValue()).toString();
+            i++;
+        }
+        return result;
+    }
+
+    /**
+     * Find the list of environment variables for this process.
+     * 
+     * @return a vector containing the environment variables the vector elements
+     *         are strings formatted like variable = value
+     */
+    public static synchronized Environment getProcEnvironment() {
+        if (procEnvironment != null) {
+            return procEnvironment;
+        }
+
+        procEnvironment = new Environment();
+        try {
+            BufferedReader in = runProcEnvCommand();
+
+            String var = null;
+            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
+                    // contain embedded new lines).
+                    if (var == null) {
+                        var = lineSep + line;
+                    } else {
+                        var += lineSep + line;
+                    }
+                } else {
+                    // New env var...append the previous one if we have it.
+                    if (var != null) {
+                        procEnvironment.addVariable(EnvironmentVariable
+                                .createEnvironmentVariable(var));
+                    }
+                    var = line;
+                }
+            }
+            // Since we "look ahead" before adding, there's one last env var.
+            if (var != null) {
+                procEnvironment.addVariable(EnvironmentVariable
+                        .createEnvironmentVariable(var));
+            }
+        } catch (java.io.IOException exc) {
+            exc.printStackTrace();
+            // Just try to see how much we got
+        }
+        return procEnvironment;
+    }
+
+    /**
+     * @return
+     * @throws IOException
+     */
+    protected static BufferedReader runProcEnvCommand() throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        Execute exe = new Execute(new PumpStreamHandler(out));
+        exe.setCommandline(getProcEnvCommand());
+        // Make sure we do not recurse forever
+        exe.setNewEnvironment(true);
+        int retval = exe.execute();
+        if (retval != 0) {
+            // Just try to use what we got
+        }
+        BufferedReader in = new BufferedReader(new StringReader(toString(out)));
+        return in;
+    }
+
+    protected static CommandLine getProcEnvCommand() {
+        CommandLine commandLine = new CommandLineImpl();
+        if (OS.isFamilyOS2()) {
+            // OS/2 - use same mechanism as Windows 2000
+            commandLine.setExecutable("cmd");
+            commandLine.addArguments(new String[] {"/c", "set"});
+        } else if (OS.isFamilyWindows()) {
+            // Determine if we're running under XP/2000/NT or 98/95
+            if (OS.isFamilyWin9x()) {
+                commandLine.setExecutable("command.com");
+                // Windows 98/95
+            } else {
+                commandLine.setExecutable("cmd");
+                // Windows XP/2000/NT/2003
+            }
+            commandLine.addArguments(new String[] {"/c", "set"});
+        } else if (OS.isFamilyZOS() || OS.isFamilyUnix()) {
+            // On most systems one could use: /bin/sh -c env
+
+            // Some systems have /bin/env, others /usr/bin/env, just try
+            if (new File("/bin/env").canRead()) {
+                commandLine.setExecutable("/bin/env");
+            } else if (new File("/usr/bin/env").canRead()) {
+                commandLine.setExecutable("/usr/bin/env");
+            } else {
+                // rely on PATH
+                commandLine.setExecutable("env");
+            }
+        } else if (OS.isFamilyNetware() || OS.isFamilyOS400()) {
+            // rely on PATH
+            commandLine.setExecutable("env");
+        } else {
+            // MAC OS 9 and previous
+            // TODO: I have no idea how to get it, someone must fix it
+            commandLine = null;
+        }
+        return commandLine;
+    }
+
+    /**
+     * ByteArrayOutputStream#toString doesn't seem to work reliably on OS/390,
+     * at least not the way we use it in the execution context.
+     * 
+     * @param bos
+     *            the output stream that one wants to read
+     * @return the output stream as a string, read with special encodings in the
+     *         case of z/os and os/400
+     */
+    private static String toString(final ByteArrayOutputStream bos) {
+        if (OS.isFamilyZOS()) {
+            try {
+                return bos.toString("Cp1047");
+            } catch (java.io.UnsupportedEncodingException e) {
+                // noop default encoding used
+            }
+        } else if (OS.isFamilyOS400()) {
+            try {
+                return bos.toString("Cp500");
+            } catch (java.io.UnsupportedEncodingException e) {
+                // noop default encoding used
+            }
+        }
+        return bos.toString();
+    }
+
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,153 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec.environment;
+
+import java.io.File;
+
+
+/**
+ * representation of a single env value
+ */
+public final class EnvironmentVariable {
+
+    public static EnvironmentVariable createEnvironmentVariable(
+            final String keyAndValue) {
+        return new EnvironmentVariable(keyAndValue);
+    }
+
+    public static EnvironmentVariable createEnvironmentVariable(
+            final String key, final String value) {
+        return new EnvironmentVariable(key, value);
+    }
+
+    /**
+     * env key and value pair; everything gets expanded to a string during
+     * assignment
+     */
+    private String value;
+
+    private String key;
+
+    /**
+     * Constructor for variable
+     */
+    private EnvironmentVariable(final String key, final String value) {
+        if (key == null) {
+            throw new NullPointerException("key can not be null");
+        }
+        if (value == null) {
+            throw new NullPointerException("value can not be null");
+        }
+        this.key = key;
+        this.value = value;
+    }
+
+    private EnvironmentVariable(final String keyAndValue) {
+        int index = keyAndValue.indexOf('=');
+        if (index == -1) {
+            throw new IllegalArgumentException(
+                    "Environment variable for this platform "
+                            + "must contain an equals sign ('=')");
+        }
+
+        this.key = keyAndValue.substring(0, index);
+        this.value = keyAndValue.substring(index + 1);
+    }
+
+    /**
+     * set the key
+     * 
+     * @param key
+     *            string
+     */
+    public void setKey(final String key) {
+        this.key = key;
+    }
+
+    /**
+     * set the value
+     * 
+     * @param value
+     *            string value
+     */
+    public void setValue(final String value) {
+        this.value = value;
+    }
+
+    /**
+     * key accessor
+     * 
+     * @return key
+     */
+    public String getKey() {
+        return this.key;
+    }
+
+    /**
+     * value accessor
+     * 
+     * @return value
+     */
+    public String getValue() {
+        return this.value;
+    }
+
+    /**
+     * stringify path and assign to the value. The value will contain all path
+     * elements separated by the appropriate separator
+     * 
+     * @param path
+     *            path
+     */
+    /*
+     * public void setPath(Path path) { this.value = path.toString(); }
+     */
+
+    /**
+     * get the absolute path of a file and assign it to the value
+     * 
+     * @param file
+     *            file to use as the value
+     */
+    public void setFile(final File file) {
+        this.value = file.getAbsolutePath();
+    }
+
+    /**
+     * get the assigment string This is not ready for insertion into a property
+     * file without following the escaping rules of the properties class.
+     * 
+     * @return a string of the form key=value.
+     *             if key or value are unassigned
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer(key.trim());
+        sb.append("=").append(value.trim());
+        return sb.toString();
+    }
+
+    public boolean equals(final Object o) {
+        if (!(o instanceof EnvironmentVariable)) {
+            return false;
+        }
+
+        EnvironmentVariable envVar = (EnvironmentVariable) o;
+
+        return key.equals(envVar.key) && value.equals(envVar.value);
+    }
+}
\ No newline at end of file

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,114 @@
+/* 
+ * Copyright 2005  The Apache Software Foundation
+ *
+ *  Licensed 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.commons.exec.environment;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+
+public class OpenVmsEnvironment extends Environment {
+
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3762535598665117752L;
+
+    protected OpenVmsEnvironment() {
+
+    }
+
+    public static synchronized Environment getProcEnvironment() {
+        Environment procEnvironment = getProcEnvironment();
+
+        if (procEnvironment == null) {
+            procEnvironment = new Environment();
+            try {
+                BufferedReader in = runProcEnvCommand();
+
+                procEnvironment = addVMSLogicals(procEnvironment, in);
+                return procEnvironment;
+            } catch (java.io.IOException exc) {
+                exc.printStackTrace();
+                // Just try to see how much we got
+            }
+        }
+
+        return procEnvironment;
+    }
+
+    protected static CommandLine getProcEnvCommand() {
+        CommandLine commandLine = new CommandLineImpl();
+        commandLine.setExecutable("show");
+        commandLine.addArgument("logical");
+        return commandLine;
+    }
+
+    /**
+     * This method is VMS specific and used by getProcEnvironment(). Parses VMS
+     * logicals from <code>in</code> and adds them to <code>environment</code>.
+     * <code>in</code> is expected to be the output of "SHOW LOGICAL". The
+     * method takes care of parsing the output correctly as well as making sure
+     * that a logical defined in multiple tables only gets added from the
+     * highest order table. Logicals with multiple equivalence names are mapped
+     * to a variable with multiple values separated by a comma (,).
+     */
+    private static Environment addVMSLogicals(final Environment environment,
+            final BufferedReader in) throws IOException {
+        HashMap logicals = new HashMap();
+        String logName = null, logValue = null, newLogName;
+        String line = null;
+        while ((line = in.readLine()) != null) {
+            // parse the VMS logicals into required format ("VAR=VAL[,VAL2]")
+            if (line.startsWith("\t=")) {
+                // further equivalence name of previous logical
+                if (logName != null) {
+                    logValue += "," + line.substring(4, line.length() - 1);
+                }
+            } else if (line.startsWith("  \"")) {
+                // new logical?
+                if (logName != null) {
+                    logicals.put(logName, logValue);
+                }
+                int eqIndex = line.indexOf('=');
+                newLogName = line.substring(3, eqIndex - 2);
+                if (logicals.containsKey(newLogName)) {
+                    // already got this logical from a higher order table
+                    logName = null;
+                } else {
+                    logName = newLogName;
+                    logValue = line.substring(eqIndex + 3, line.length() - 1);
+                }
+            }
+        }
+        // Since we "look ahead" before adding, there's one last env var.
+        if (logName != null) {
+            logicals.put(logName, logValue);
+        }
+
+        for (Iterator i = logicals.keySet().iterator(); i.hasNext();) {
+            String logical = (String) i.next();
+            environment.addVariable(logical, (String) logicals.get(logical));
+        }
+        return environment;
+    }
+
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,43 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.environment.Environment;
+
+public interface CommandLauncher {
+
+    /**
+     * Launches the given command in a new process.
+     * 
+     * @param cmd
+     *            The command to execute
+     * @param env
+     *            The environment for the new process. If null, the environment
+     *            of the current process is used.
+     * @throws IOException
+     *             if attempting to run a command in a specific directory
+     */
+    Process exec(final CommandLine cmd, final Environment env)
+            throws IOException;
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory.
+     * 
+     * @param cmd
+     *            The command to execute
+     * @param env
+     *            The environment for the new process. If null, the environment
+     *            of the current process is used.
+     * @param workingDir
+     *            The directory to start the command in. If null, the current
+     *            directory is used
+     * @throws IOException
+     *             if trying to change directory
+     */
+    Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException;
+
+}
\ No newline at end of file

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,87 @@
+package org.apache.commons.exec.launcher;
+
+import org.apache.commons.exec.OS;
+
+/**
+ * Builds a command launcher for the OS and JVM we are running under.
+ */
+
+public final class CommandLauncherFactory {
+
+    private CommandLauncherFactory() {
+
+    }
+
+    /**
+     * 
+     */
+    public static CommandLauncher createVMLauncher() {
+        // Try using a JDK 1.3 launcher
+        CommandLauncher launcher = null;
+        try {
+            if (OS.isFamilyOpenVms()) {
+                launcher = new VmsCommandLauncher();
+            } else if (!OS.isFamilyOS2()) {
+                launcher = new Java13CommandLauncher();
+            }
+        } catch (NoSuchMethodException exc) {
+            // Ignore and keep trying
+        }
+
+        return launcher;
+    }
+
+    public static CommandLauncher createShellLauncher() {
+        CommandLauncher launcher = null;
+
+        if (OS.isFamilyMac() && !OS.isFamilyUnix()) {
+            // Mac
+            launcher = new MacCommandLauncher(new CommandLauncherImpl());
+        } else if (OS.isFamilyOS2()) {
+            // OS/2
+            launcher = new OS2CommandLauncher(new CommandLauncherImpl());
+        } else if (OS.isFamilyWindows()) {
+            // Windows. Need to determine which JDK we're running in
+
+            CommandLauncher baseLauncher;
+            if (System.getProperty("java.version").startsWith("1.1")) {
+                // JDK 1.1
+                baseLauncher = new Java11CommandLauncher();
+            } else {
+                // JDK 1.2
+                baseLauncher = new CommandLauncherImpl();
+            }
+
+            if (!OS.isFamilyWin9x()) {
+                // Windows XP/2000/NT
+                launcher = new WinNTCommandLauncher(baseLauncher);
+            } else {
+                // Windows 98/95 - need to use an auxiliary script
+                launcher = new ScriptCommandLauncher("bin/antRun.bat",
+                        baseLauncher);
+            }
+        } else if (OS.isFamilyNetware()) {
+            // NetWare. Need to determine which JDK we're running in
+            CommandLauncher baseLauncher;
+            if (System.getProperty("java.version").startsWith("1.1")) {
+                // JDK 1.1
+                baseLauncher = new Java11CommandLauncher();
+            } else {
+                // JDK 1.2
+                baseLauncher = new CommandLauncherImpl();
+            }
+
+            launcher = new PerlScriptCommandLauncher("bin/antRun.pl",
+                    baseLauncher);
+        } else if (OS.isFamilyOpenVms()) {
+            // the vmLauncher already uses the shell
+            launcher = createVMLauncher();
+        } else {
+            // Generic
+            launcher = new ScriptCommandLauncher("bin/antRun",
+                    new CommandLauncherImpl());
+        }
+
+        return launcher;
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,46 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher for a particular JVM/OS platform. This class is a general
+ * purpose command launcher which can only launch commands in the current
+ * working directory.
+ */
+public class CommandLauncherImpl implements CommandLauncher {
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.commons.exec.launcher.CommandLauncherIn#exec(java.lang.String[],
+     *      java.lang.String[])
+     */
+    public Process exec(final CommandLine cmd, final Environment env)
+            throws IOException {
+        String[] envVar = null;
+        if(env != null) {
+            envVar = env.getVariables();
+        }
+        
+        return Runtime.getRuntime().exec(cmd.getCommandline(),
+                envVar);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.commons.exec.launcher.CommandLauncherIn#exec(java.lang.String[],
+     *      java.lang.String[], java.io.File)
+     */
+    public Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException {
+        if (workingDir == null) {
+            return exec(cmd, env);
+        }
+        throw new IOException("Cannot execute a process in different "
+                + "directory under this JVM");
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,38 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher that proxies another command launcher. Sub-classes
+ * override exec(args, env, workdir)
+ */
+public abstract class CommandLauncherProxy extends CommandLauncherImpl {
+
+    public CommandLauncherProxy(final CommandLauncher launcher) {
+        myLauncher = launcher;
+    }
+
+    private CommandLauncher myLauncher;
+
+    /**
+     * Launches the given command in a new process. Delegates this method to the
+     * proxied launcher
+     * 
+     * @param project
+     *            the ant project
+     * @param cmd
+     *            the command line to execute as an array of strings
+     * @param env
+     *            the environment to set as an array of strings
+     * @throws IOException
+     *             forwarded from the exec method of the command launcher
+     */
+    public Process exec(final CommandLine cmd, final Environment env)
+            throws IOException {
+        return myLauncher.exec(cmd, env);
+    }
+
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,47 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+import org.apache.commons.exec.environment.Environment;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A command launcher for JDK/JRE 1.1 under Windows. Fixes quoting problems in
+ * Runtime.exec(). Can only launch commands in the current working directory
+ */
+public class Java11CommandLauncher extends CommandLauncherImpl {
+
+    private static final Log LOG = LogFactory
+            .getLog(Java11CommandLauncher.class);
+
+    /**
+     * Launches the given command in a new process. Needs to quote arguments
+     * 
+     * @param cmd
+     *            the command line to execute as an array of strings
+     * @param env
+     *            the environment to set as an array of strings
+     * @throws IOException
+     *             probably forwarded from Runtime#exec
+     */
+    public Process exec(final CommandLine cmd, final Environment env)
+            throws IOException {
+        // Need to quote arguments with spaces, and to escape
+        // quote characters
+        CommandLine newCmd = new CommandLineImpl();
+        newCmd.setExecutable(
+                CommandLineImpl.quoteArgument(cmd.getExecutable()));
+
+        String[] args = cmd.getArguments();
+        for (int i = 0; i < args.length; i++) {
+            newCmd.addArgument(CommandLineImpl.quoteArgument(args[i]));
+        }
+        LOG.debug("Execute:Java11CommandLauncher: " + newCmd);
+
+        return Runtime.getRuntime().exec(newCmd.getCommandline(),
+                env.getVariables());
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,66 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.commons.exec.ExecuteException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A command launcher for JDK/JRE 1.3 (and higher). Uses the built-in
+ * Runtime.exec() command
+ */
+public class Java13CommandLauncher extends CommandLauncherImpl {
+    private static Log log = LogFactory.getLog(Java13CommandLauncher.class);
+
+    public Java13CommandLauncher() throws NoSuchMethodException {
+        // Locate method Runtime.exec(String[] cmdarray,
+        // String[] envp, File dir)
+        myExecWithCWD = Runtime.class.getMethod("exec", new Class[] {
+                String[].class, String[].class, File.class});
+    }
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory
+     * 
+     * @param project
+     *            the ant project
+     * @param cmd
+     *            the command line to execute as an array of strings
+     * @param env
+     *            the environment to set as an array of strings
+     * @param workingDir
+     *            the working directory where the command should run
+     * @throws IOException
+     *             probably forwarded from Runtime#exec
+     */
+    public Process exec(final String[] cmd, final String[] env,
+            final File workingDir) throws IOException {
+        try {
+            log.debug("Execute:Java13CommandLauncher: " + cmd);
+
+            Object[] arguments = {cmd, env, workingDir};
+            return (Process) myExecWithCWD.invoke(Runtime.getRuntime(),
+                    arguments);
+        } catch (InvocationTargetException exc) {
+            Throwable realexc = exc.getTargetException();
+            if (realexc instanceof ThreadDeath) {
+                throw (ThreadDeath) realexc;
+            } else if (realexc instanceof IOException) {
+                throw (IOException) realexc;
+            } else {
+                throw new ExecuteException("Unable to execute command",
+                        realexc);
+            }
+        } catch (Exception exc) {
+            // IllegalAccess, IllegalArgument, ClassCast
+            throw new ExecuteException("Unable to execute command", exc);
+        }
+    }
+
+    private Method myExecWithCWD;
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,46 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher for Mac that uses a dodgy mechanism to change working
+ * directory before launching commands.
+ */
+public class MacCommandLauncher extends CommandLauncherProxy {
+    public MacCommandLauncher(final CommandLauncher launcher) {
+        super(launcher);
+    }
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory.
+     * 
+     * @param cmd
+     *            the command line to execute as an array of strings
+     * @param env
+     *            the environment to set as an array of strings
+     * @param workingDir
+     *            working directory where the command should run
+     * @throws IOException
+     *             forwarded from the exec method of the command launcher
+     */
+    public Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException {
+        if (workingDir == null) {
+            return exec(cmd, env);
+        }
+
+        String oldUserDir = System.getProperty("user.dir");
+
+        System.getProperties().put("user.dir", workingDir.getAbsolutePath());
+        try {
+            return exec(cmd, env);
+        } finally {
+            System.getProperties().put("user.dir", oldUserDir);
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,60 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher for OS/2 that uses 'cmd.exe' when launching commands in
+ * directories other than the current working directory.
+ * <p>
+ * Unlike Windows NT and friends, OS/2's cd doesn't support the /d switch to
+ * change drives and directories in one go.
+ * </p>
+ */
+public class OS2CommandLauncher extends CommandLauncherProxy {
+
+    public OS2CommandLauncher(final CommandLauncher launcher) {
+        super(launcher);
+    }
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory.
+     * 
+     * @param project
+     *            the ant project
+     * @param cmd
+     *            the command line to execute as an array of strings
+     * @param env
+     *            the environment to set as an array of strings
+     * @param workingDir
+     *            working directory where the command should run
+     * @throws IOException
+     *             forwarded from the exec method of the command launcher
+     */
+    public Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException {
+        if (workingDir == null) {
+            return exec(cmd, env);
+        }
+
+        final String cmdDir = workingDir.getAbsolutePath();
+
+        CommandLine newCmd = new CommandLineImpl();
+        newCmd.setExecutable("cmd");
+        newCmd.addArgument("/c");
+        // TODO calculate root by walking
+        newCmd.addArgument(cmdDir.substring(0, 2));
+        newCmd.addArgument("&&");
+        newCmd.addArgument("cd");
+        newCmd.addArgument(cmdDir.substring(2));
+        newCmd.addArgument("&&");
+        newCmd.addArguments(cmd.getCommandline());
+
+        return exec(newCmd, env);
+    }
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,50 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher that uses an auxiliary perl script to launch commands in
+ * directories other than the current working directory.
+ */
+public class PerlScriptCommandLauncher extends CommandLauncherProxy {
+    public PerlScriptCommandLauncher(final String script,
+            final CommandLauncher launcher) {
+        super(launcher);
+        this.script = script;
+    }
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory
+     */
+    public Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException {
+
+        if (workingDir == null) {
+            return exec(cmd, env);
+        }
+
+        // Locate the auxiliary script
+        String scriptDir = System.getProperty("org.apache.commons.exec.home", "");
+        File scriptFile = new File(scriptDir + File.separator + script);
+        if (scriptFile.exists()) {
+            throw new IOException("Cannot locate auxiliary script at " +
+                    scriptFile.getAbsolutePath());
+        }
+
+        CommandLine newCmd = new CommandLineImpl();
+        newCmd.setExecutable("perl");
+        newCmd.addArgument(scriptFile.getPath());
+        newCmd.addArgument(workingDir.getAbsolutePath());
+        newCmd.addArguments(cmd.getCommandline());
+        
+        return exec(newCmd, env);
+    }
+
+    private String script;
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java?rev=230452&view=auto
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java (added)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java Fri Aug  5 05:21:46 2005
@@ -0,0 +1,49 @@
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.CommandLineImpl;
+import org.apache.commons.exec.environment.Environment;
+
+/**
+ * A command launcher that uses an auxiliary script to launch commands in
+ * directories other than the current working directory.
+ */
+public class ScriptCommandLauncher extends CommandLauncherProxy {
+    public ScriptCommandLauncher(final String script,
+            final CommandLauncher launcher) {
+        super(launcher);
+        this.script = script;
+    }
+
+    /**
+     * Launches the given command in a new process, in the given working
+     * directory.
+     */
+    public Process exec(final CommandLine cmd, final Environment env,
+            final File workingDir) throws IOException {
+        if (workingDir == null) {
+            return exec(cmd, env);
+        }
+
+        // Locate the auxiliary script
+        String scriptDir = System.getProperty("org.apache.commons.exec.home", "");
+        File scriptFile = new File(scriptDir + File.separator + script);
+        if (scriptFile.exists()) {
+            throw new IOException("Cannot locate auxiliary script at " +
+                    scriptFile.getAbsolutePath());
+        }
+        
+        // Build the command
+        CommandLine newCmd = new CommandLineImpl();
+        newCmd.setExecutable(scriptFile.getPath());
+        newCmd.addArgument(workingDir.getAbsolutePath());
+        newCmd.addArguments(cmd.getCommandline());
+
+        return exec(newCmd, env);
+    }
+
+    private String script;
+}

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message