You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by de...@apache.org on 2007/01/06 16:42:24 UTC

svn commit: r493490 - in /jakarta/commons/sandbox/exec/trunk: ./ src/main/java/org/apache/commons/exec/environment/ src/site/apt/

Author: dennisl
Date: Sat Jan  6 07:42:23 2007
New Revision: 493490

URL: http://svn.apache.org/viewvc?view=rev&rev=493490
Log:
Set EOL-style to native.

Modified:
    jakarta/commons/sandbox/exec/trunk/STATUS   (props changed)
    jakarta/commons/sandbox/exec/trunk/build.properties.sample   (props changed)
    jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java   (contents, props changed)
    jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java   (contents, props changed)
    jakarta/commons/sandbox/exec/trunk/src/site/apt/index.apt   (props changed)

Propchange: jakarta/commons/sandbox/exec/trunk/STATUS
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/exec/trunk/build.properties.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java?view=diff&rev=493490&r1=493489&r2=493490
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java Sat Jan  6 07:42:23 2007
@@ -1,189 +1,189 @@
-/* 
- * 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.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.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecutor;
-import org.apache.commons.exec.Executor;
-import org.apache.commons.exec.OS;
-import org.apache.commons.exec.PumpStreamHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class DefaultProcessingEnvironment {
-
-	private static Log LOG = LogFactory.getLog(DefaultProcessingEnvironment.class);
-	
-    /**
-     * TODO move this and other final static / constants into a constants class ?
-     */
-    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
-	
-	protected Map procEnvironment;
-	
-    /**
-     * 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
-     * @throws IOException
-     */
-    public synchronized Map getProcEnvironment() throws IOException {
-        if (procEnvironment == null) {
-            try {
-                Method getenvs = System.class.getMethod( "getenv", null );
-                Map env = (Map) getenvs.invoke( null, null );
-                procEnvironment = new HashMap( env );
-            } catch ( NoSuchMethodException e ) {
-                // ok, just not on JDK 1.5
-            } catch ( IllegalAccessException e ) {
-                LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
-            } catch ( InvocationTargetException e ) {
-                LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
-            }
-        }
-
-        if(procEnvironment == null) {
-            procEnvironment = new HashMap();
-            BufferedReader in = runProcEnvCommand();
-
-            String var = null;
-            String line;
-            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 = LINE_SEPARATOR + line;
-                    } else {
-                        var += LINE_SEPARATOR + line;
-                    }
-                } else {
-                    // New env var...append the previous one if we have it.
-                    if (var != null) {
-                    	EnvironmentUtil.addVariableToEnvironment(procEnvironment, var);
-                    }
-                    var = line;
-                }
-            }
-            // Since we "look ahead" before adding, there's one last env var.
-            if (var != null) {
-            	EnvironmentUtil.addVariableToEnvironment(procEnvironment, var);
-            }
-        }
-        return procEnvironment;
-    }
-
-    /**
-     * @return
-     * @throws IOException
-     */
-    protected BufferedReader runProcEnvCommand() throws IOException {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        Executor exe = new DefaultExecutor();
-        exe.setStreamHandler(new PumpStreamHandler(out));
-
-        int retval = exe.execute(getProcEnvCommand(), new HashMap());
-        if (retval != 0) {
-            // Just try to use what we got
-        }
-        return new BufferedReader(new StringReader(toString(out)));
-    }
-
-    protected CommandLine getProcEnvCommand() {
-        String executable;
-        String[] arguments = null;
-        if (OS.isFamilyOS2()) {
-            // OS/2 - use same mechanism as Windows 2000
-            executable = "cmd";
-            
-            arguments = new String[] {"/c", "set"};
-        } else if (OS.isFamilyWindows()) {
-            // Determine if we're running under XP/2000/NT or 98/95
-            if (OS.isFamilyWin9x()) {
-                executable = "command.com";
-                // Windows 98/95
-            } else {
-                executable = "cmd";
-                // Windows XP/2000/NT/2003
-            }
-            arguments = 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()) {
-                executable = "/bin/env";
-            } else if (new File("/usr/bin/env").canRead()) {
-                executable = "/usr/bin/env";
-            } else {
-                // rely on PATH
-                executable = "env";
-            }
-        } else if (OS.isFamilyNetware() || OS.isFamilyOS400()) {
-            // rely on PATH
-            executable = "env";
-        } else {
-            // MAC OS 9 and previous
-            // TODO: I have no idea how to get it, someone must fix it
-            executable = null;
-        }
-        CommandLine commandLine = null;
-        if(executable != null) {
-            commandLine = new CommandLine(executable);
-            commandLine.addArguments(arguments);
-        }
-        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 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();
-    }
-}
+/* 
+ * 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.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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.DefaultExecutor;
+import org.apache.commons.exec.Executor;
+import org.apache.commons.exec.OS;
+import org.apache.commons.exec.PumpStreamHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class DefaultProcessingEnvironment {
+
+	private static Log LOG = LogFactory.getLog(DefaultProcessingEnvironment.class);
+	
+    /**
+     * TODO move this and other final static / constants into a constants class ?
+     */
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+	
+	protected Map procEnvironment;
+	
+    /**
+     * 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
+     * @throws IOException
+     */
+    public synchronized Map getProcEnvironment() throws IOException {
+        if (procEnvironment == null) {
+            try {
+                Method getenvs = System.class.getMethod( "getenv", null );
+                Map env = (Map) getenvs.invoke( null, null );
+                procEnvironment = new HashMap( env );
+            } catch ( NoSuchMethodException e ) {
+                // ok, just not on JDK 1.5
+            } catch ( IllegalAccessException e ) {
+                LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
+            } catch ( InvocationTargetException e ) {
+                LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
+            }
+        }
+
+        if(procEnvironment == null) {
+            procEnvironment = new HashMap();
+            BufferedReader in = runProcEnvCommand();
+
+            String var = null;
+            String line;
+            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 = LINE_SEPARATOR + line;
+                    } else {
+                        var += LINE_SEPARATOR + line;
+                    }
+                } else {
+                    // New env var...append the previous one if we have it.
+                    if (var != null) {
+                    	EnvironmentUtil.addVariableToEnvironment(procEnvironment, var);
+                    }
+                    var = line;
+                }
+            }
+            // Since we "look ahead" before adding, there's one last env var.
+            if (var != null) {
+            	EnvironmentUtil.addVariableToEnvironment(procEnvironment, var);
+            }
+        }
+        return procEnvironment;
+    }
+
+    /**
+     * @return
+     * @throws IOException
+     */
+    protected BufferedReader runProcEnvCommand() throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        Executor exe = new DefaultExecutor();
+        exe.setStreamHandler(new PumpStreamHandler(out));
+
+        int retval = exe.execute(getProcEnvCommand(), new HashMap());
+        if (retval != 0) {
+            // Just try to use what we got
+        }
+        return new BufferedReader(new StringReader(toString(out)));
+    }
+
+    protected CommandLine getProcEnvCommand() {
+        String executable;
+        String[] arguments = null;
+        if (OS.isFamilyOS2()) {
+            // OS/2 - use same mechanism as Windows 2000
+            executable = "cmd";
+            
+            arguments = new String[] {"/c", "set"};
+        } else if (OS.isFamilyWindows()) {
+            // Determine if we're running under XP/2000/NT or 98/95
+            if (OS.isFamilyWin9x()) {
+                executable = "command.com";
+                // Windows 98/95
+            } else {
+                executable = "cmd";
+                // Windows XP/2000/NT/2003
+            }
+            arguments = 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()) {
+                executable = "/bin/env";
+            } else if (new File("/usr/bin/env").canRead()) {
+                executable = "/usr/bin/env";
+            } else {
+                // rely on PATH
+                executable = "env";
+            }
+        } else if (OS.isFamilyNetware() || OS.isFamilyOS400()) {
+            // rely on PATH
+            executable = "env";
+        } else {
+            // MAC OS 9 and previous
+            // TODO: I have no idea how to get it, someone must fix it
+            executable = null;
+        }
+        CommandLine commandLine = null;
+        if(executable != null) {
+            commandLine = new CommandLine(executable);
+            commandLine.addArguments(arguments);
+        }
+        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 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/DefaultProcessingEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java?view=diff&rev=493490&r1=493489&r2=493490
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java Sat Jan  6 07:42:23 2007
@@ -1,98 +1,98 @@
-/* 
- * 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.commons.exec.environment;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.exec.CommandLine;
-
-public class OpenVmsProcessingEnvironment extends DefaultProcessingEnvironment {
-
-    public synchronized Map getProcEnvironment() throws IOException {
-        if (procEnvironment == null) {
-            procEnvironment = new HashMap();
-
-            BufferedReader in = runProcEnvCommand();
-
-            procEnvironment = addVMSLogicals(procEnvironment, in);
-            return procEnvironment;
-        }
-
-        return procEnvironment;
-    }
-
-    protected CommandLine getProcEnvCommand() {
-        CommandLine commandLine = new CommandLine("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 Map addVMSLogicals(final Map 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.put(logical, logicals.get(logical));
-        }
-        return environment;
-    }
-
-}
+/* 
+ * 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.commons.exec.environment;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.exec.CommandLine;
+
+public class OpenVmsProcessingEnvironment extends DefaultProcessingEnvironment {
+
+    public synchronized Map getProcEnvironment() throws IOException {
+        if (procEnvironment == null) {
+            procEnvironment = new HashMap();
+
+            BufferedReader in = runProcEnvCommand();
+
+            procEnvironment = addVMSLogicals(procEnvironment, in);
+            return procEnvironment;
+        }
+
+        return procEnvironment;
+    }
+
+    protected CommandLine getProcEnvCommand() {
+        CommandLine commandLine = new CommandLine("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 Map addVMSLogicals(final Map 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.put(logical, logicals.get(logical));
+        }
+        return environment;
+    }
+
+}

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

Propchange: jakarta/commons/sandbox/exec/trunk/src/site/apt/index.apt
------------------------------------------------------------------------------
    svn:eol-style = native



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