Author: ngn Date: Sat Jan 28 15:15:24 2006 New Revision: 373258 URL: http://svn.apache.org/viewcvs?rev=373258&view=rev Log: Patch replacing Enviroment class with Map (in line with Java 1.5) as suggested by Jerome Lacoste and myself (bugzilla 37951)
Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtil.java - copied, changed from r356574, jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java (with props) jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java - copied, changed from r356574, jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentTest.java Removed: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentVariable.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsEnvironment.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentTest.java Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java Sat Jan 28 15:15:24 2006 @@ -21,8 +21,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; -import org.apache.commons.exec.environment.Environment; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -203,7 +204,7 @@ execute(cl, null, new LogOutputStream(1), new LogOutputStream(2)); } - public void execute(final CommandLine cl, final Environment env) + public void execute(final CommandLine cl, final Map env) throws IOException { execute(cl, env, new LogOutputStream(1), new LogOutputStream(2)); } @@ -214,14 +215,14 @@ } - public void execute(final CommandLine cmdl, final Environment env, + public void execute(final CommandLine cmdl, final Map env, final OutputStream out, final OutputStream error) throws IOException { File savedDir = dir; // possibly altered in prepareExec - Environment environment; + Map environment; if (env == null) { - environment = Environment.createEnvironment(); + environment = new HashMap(); } else { environment = env; } @@ -237,14 +238,14 @@ } } - public void execute(final CommandLine cmdl, final Environment env, + public void execute(final CommandLine cmdl, final Map env, final InputStream in, final OutputStream out, final OutputStream error) throws ExecuteException { File savedDir = dir; // possibly altered in prepareExec - Environment environment; + Map environment; if (env == null) { - environment = Environment.createEnvironment(); + environment = new HashMap(); } else { environment = env; } @@ -303,13 +304,13 @@ * @throws ExecuteException * under unknown circumstances. */ - protected Execute prepareExec(final Environment env, + protected Execute prepareExec(final Map env, final OutputStream out, final OutputStream error) throws ExecuteException { return prepareExec(env, null, out, error); } - protected Execute prepareExec(final Environment env, final InputStream in, + protected Execute prepareExec(final Map env, final InputStream in, final OutputStream out, final OutputStream error) throws ExecuteException { // default directory to the current directory @@ -324,7 +325,7 @@ exe.setWorkingDirectory(dir); exe.setNewEnvironment(newEnvironment); - exe.setEnvironment(env.getVariables()); + exe.setEnvironment(env); return exe; } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java Sat Jan 28 15:15:24 2006 @@ -21,8 +21,10 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; -import org.apache.commons.exec.environment.Environment; +import org.apache.commons.exec.environment.EnvironmentUtil; import org.apache.commons.exec.launcher.CommandLauncher; import org.apache.commons.exec.launcher.CommandLauncherFactory; import org.apache.commons.logging.Log; @@ -40,7 +42,7 @@ private CommandLine cmdl = null; - private Environment environment = null; + private Map environment = null; private int exitValue = INVALID; @@ -161,7 +163,7 @@ * @throws IOException If the environment can not be * retrived. */ - public Environment getEnvironment() throws IOException { + public Map getEnvironment() throws IOException { if (environment == null || newEnvironment) { return environment; } @@ -171,21 +173,10 @@ /** * Sets the environment variables for the subprocess to launch. * - * @param envVars - * array of Strings, each element of which has an environment - * variable settings in format <em>key=value</em> - */ - public void setEnvironment(final String[] envVars) { - this.environment = Environment.createEnvironment(envVars); - } - - /** - * Sets the environment variables for the subprocess to launch. - * * @param env * environment to set */ - public void setEnvironment(final Environment env) { + public void setEnvironment(final Map env) { this.environment = env; } @@ -220,7 +211,7 @@ * @throws IOException * forwarded from the particular launcher used */ - public static Process launch(final CommandLine command, final Environment env, final File dir) + public static Process launch(final CommandLine command, final Map env, final File dir) throws IOException { CommandLauncher launcher = vmLauncher; @@ -397,7 +388,7 @@ * @return the patched environment * @throws IOException if the procssing environment can not be retrived */ - private Environment patchEnvironment() throws IOException { + private Map patchEnvironment() throws IOException { // On OpenVMS Runtime#exec() doesn't support the environment array, // so we only return the new values which then will be set in // the generated DCL script, inheriting the parent process environment @@ -405,8 +396,8 @@ return environment; } - Environment procEnv = Environment.getProcEnvironment(); - Environment osEnv = (Environment) procEnv.clone(); + Map procEnv = EnvironmentUtil.getProcEnvironment(); + Map osEnv = new HashMap(procEnv); osEnv.putAll(environment); Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java?rev=373258&view=auto ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java (added) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java Sat Jan 28 15:15:24 2006 @@ -0,0 +1,183 @@ +/* + * Copyright 2006 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.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.CommandLineImpl; +import org.apache.commons.exec.Execute; +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(); + 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 + } + return new BufferedReader(new StringReader(toString(out))); + } + + protected 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 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(); + } +} Copied: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtil.java (from r356574, 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/EnvironmentUtil.java?p2=jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtil.java&p1=jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java&r1=356574&r2=373258&rev=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/EnvironmentUtil.java Sat Jan 28 15:15:24 2006 @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2006 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. @@ -17,175 +17,32 @@ 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.Method; -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; -import org.apache.commons.exec.Execute; +import java.util.Iterator; +import java.util.Map; + import org.apache.commons.exec.OS; -import org.apache.commons.exec.PumpStreamHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Wrapper for environment variables. */ -public class Environment implements Cloneable { - - private static Log LOG = LogFactory.getLog(Environment.class); - - /** - * TODO move this and other final static / constants into a constants class ? - */ - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - private Map environment = new HashMap(); +public class EnvironmentUtil { - // ---------------------------------------------------------------------- - // Static factory methods - // ---------------------------------------------------------------------- - - public static Environment createEnvironment() { + private static DefaultProcessingEnvironment procEnvironment; + + static { if (OS.isFamilyOpenVms()) { - return new OpenVmsEnvironment(); + procEnvironment = new OpenVmsProcessingEnvironment(); } 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])); - } + procEnvironment = new DefaultProcessingEnvironment(); } - return env; - } - - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 3256443594801165364L; - - private static Environment procEnvironment; - + } + /** - * Default constructor, creates an empty environment - */ - protected Environment() { - } - - /** - * Creates an environment from a @link Map of @link String - * keys and values. - * - * @param env A map containg the environment variable name - * as @link String key and the variable value as @link String - * value + * Disable constructor */ - protected Environment(Map env) { - Set entries = env.entrySet(); - for (Iterator iter = entries.iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - addVariable((String) entry.getKey(), - (String) entry.getValue()); - } - } + private EnvironmentUtil() { - /** - * 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) { - environment.put(var.getKey(), var); - } - - /** - * add a variable. Validity checking is <i>not</i> performed at this point. - * Duplicates are not caught either. - * - * @param key - * new key. - * @param value - * new value. - * @throws NullPointerException if </CODE>key</CODE> or <CODE>value</CODE> is <CODE>null</CODE>. - */ - public void addVariable(final String key, final String value) { - environment.put(key, EnvironmentVariable.createEnvironmentVariable(key, value)); - } - - public void putAll(Map map) { - environment.putAll( map ); - } - - public void putAll(Environment environment) { - this.environment.putAll( environment.environment ); - } - - public Set keySet() { - return new HashSet( environment.keySet() ); - } - - public Set entrySet() { - return new HashSet( environment.entrySet() ); - } - - public Object get( String key ) - { - return environment.get( key ); - } - - public int size() - { - return environment.size(); - } - - public void clear() - { - environment.clear(); - } - - public boolean containsKey(String key) - { - return environment.containsKey( key ); - } - - public boolean containsValue(Object value) - { - return environment.containsValue(value); - } - - /** - * Retrieve a variable using its key. - * - * @param key - * the key. - */ - public EnvironmentVariable getVariable(final String key) { - return (EnvironmentVariable) environment.get(key); - } - - /** - * Retrieve a variable's value using its key. - * - * @param key - * the key. - */ - public String getVariableValue(final String key) { - return ((EnvironmentVariable) environment.get(key)).getValue(); } /** @@ -193,7 +50,7 @@ * * @return array of key=value assignment strings */ - public String[] getVariables() { + public static String[] toStrings(Map environment) { if (environment.size() == 0) { return null; } @@ -202,12 +59,27 @@ for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); - result[i] = entry.getValue().toString(); + result[i] = entry.getKey().toString() + "=" + entry.getValue().toString(); i++; } return result; } + private static String[] parseEnvironmentVariable(final String keyAndValue) { + int index = keyAndValue.indexOf('='); + if (index == -1) { + throw new IllegalArgumentException( + "Environment variable for this platform " + + "must contain an equals sign ('=')"); + } + + String[] result = new String[2]; + result[0] = keyAndValue.substring(0, index); + result[1] = keyAndValue.substring(index + 1); + + return result; + } + /** * Find the list of environment variables for this process. * @@ -215,151 +87,13 @@ * are strings formatted like variable = value * @throws IOException */ - public static synchronized Environment getProcEnvironment() throws IOException { - if (procEnvironment == null) { - try { - Method getenvs = System.class.getMethod( "getenv", null ); - Map env = (Map) getenvs.invoke( null, null ); - procEnvironment = new Environment( 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 Environment(); - 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) { - 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)); - } - } - return procEnvironment; + public static synchronized Map getProcEnvironment() throws IOException { + return procEnvironment.getProcEnvironment(); } - /** - * @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 - } - return new BufferedReader(new StringReader(toString(out))); - } - - 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(); - } - - // ---------------------------------------------------------------------- - // Object Overrides - // ---------------------------------------------------------------------- - - public Object clone() { - Environment copy = null; - - try { - copy = (Environment) super.clone(); - } catch (CloneNotSupportedException e) { - // this won't happen, the super class is Object - } - - copy.environment = new HashMap( this.environment ); - - return copy; - } + public static void addVariableToEnvironment(Map environment, String keyAndValue) { + String[] parsedVarible = parseEnvironmentVariable(keyAndValue); + + environment.put(parsedVarible[0], parsedVarible[1]); + } } Added: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java?rev=373258&view=auto ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java (added) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java Sat Jan 28 15:15:24 2006 @@ -0,0 +1,100 @@ +/* + * Copyright 2006 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 java.util.Map; + +import org.apache.commons.exec.CommandLine; +import org.apache.commons.exec.CommandLineImpl; + +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 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 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; + } + +} Modified: 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=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java Sat Jan 28 15:15:24 2006 @@ -19,9 +19,10 @@ import java.io.File; import java.io.IOException; +import java.util.Map; import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.environment.Environment; +import org.apache.commons.exec.environment.EnvironmentUtil; public interface CommandLauncher { @@ -36,7 +37,7 @@ * @throws IOException * if attempting to run a command in a specific directory */ - Process exec(final CommandLine cmd, final Environment env) + Process exec(final CommandLine cmd, final Map env) throws IOException; /** @@ -54,6 +55,6 @@ * @throws IOException * if trying to change directory */ - Process exec(final CommandLine cmd, final Environment env, + Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException; } Modified: 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=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java Sat Jan 28 15:15:24 2006 @@ -19,9 +19,10 @@ import java.io.File; import java.io.IOException; +import java.util.Map; import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.environment.Environment; +import org.apache.commons.exec.environment.EnvironmentUtil; /** * A command launcher for a particular JVM/OS platform. This class is a general @@ -30,17 +31,17 @@ */ public abstract class CommandLauncherImpl implements CommandLauncher { - public Process exec(final CommandLine cmd, final Environment env) + public Process exec(final CommandLine cmd, final Map env) throws IOException { String[] envVar = null; if(env != null) { - envVar = env.getVariables(); + envVar = EnvironmentUtil.toStrings(env); } return Runtime.getRuntime().exec(cmd.getCommandline(), envVar); } - public abstract Process exec(final CommandLine cmd, final Environment env, + public abstract Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException; } Modified: 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=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java Sat Jan 28 15:15:24 2006 @@ -18,9 +18,9 @@ package org.apache.commons.exec.launcher; import java.io.IOException; +import java.util.Map; import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.environment.Environment; /** * A command launcher that proxies another command launcher. Sub-classes @@ -45,7 +45,7 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Environment env) + public Process exec(final CommandLine cmd, final Map env) throws IOException { return myLauncher.exec(cmd, env); } Modified: 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=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java Sat Jan 28 15:15:24 2006 @@ -19,9 +19,10 @@ import java.io.File; import java.io.IOException; +import java.util.Map; import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.environment.Environment; +import org.apache.commons.exec.environment.EnvironmentUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -48,13 +49,13 @@ * @throws IOException * probably forwarded from Runtime#exec */ - public Process exec(final CommandLine cmd, final Environment env, + public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { log.debug("Execute:Java13CommandLauncher: " + cmd); String[] envVars = null; if(env != null) { - envVars = env.getVariables(); + envVars = EnvironmentUtil.toStrings(env); } return Runtime.getRuntime().exec(cmd.getCommandline(), Modified: 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=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java Sat Jan 28 15:15:24 2006 @@ -19,10 +19,10 @@ import java.io.File; import java.io.IOException; +import java.util.Map; 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 @@ -51,7 +51,7 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Environment env, + public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { if (workingDir == null) { return exec(cmd, env); Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java Sat Jan 28 15:15:24 2006 @@ -22,12 +22,12 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.Map.Entry; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.CommandLineImpl; -import org.apache.commons.exec.environment.Environment; /** * A command launcher for VMS that writes the command to a temporary DCL script @@ -39,7 +39,7 @@ /** * Launches the given command in a new process. */ - public Process exec(final CommandLine cmd, final Environment env) + public Process exec(final CommandLine cmd, final Map env) throws IOException { CommandLine vmsCmd = new CommandLineImpl(); vmsCmd.setExecutable(createCommandFile(cmd, env).getPath()); @@ -53,7 +53,7 @@ * only works if <code>workingDir</code> is null or the logical * JAVA$FORK_SUPPORT_CHDIR needs to be set to TRUE. */ - public Process exec(final CommandLine cmd, final Environment env, + public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { CommandLine vmsCmd = new CommandLineImpl(); vmsCmd.setExecutable(createCommandFile(cmd, env).getPath()); @@ -65,7 +65,7 @@ * Writes the command into a temporary DCL script and returns the * corresponding File object. The script will be deleted on exit. */ - private File createCommandFile(final CommandLine cmd, final Environment env) + private File createCommandFile(final CommandLine cmd, final Map env) throws IOException { File script = File.createTempFile("ANT", ".COM"); script.deleteOnExit(); Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java Sat Jan 28 15:15:24 2006 @@ -19,10 +19,10 @@ import java.io.File; import java.io.IOException; +import java.util.Map; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.CommandLineImpl; -import org.apache.commons.exec.environment.Environment; /** * A command launcher for Windows XP/2000/NT that uses 'cmd.exe' when launching @@ -46,7 +46,7 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Environment env, + public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { if (workingDir == null) { return exec(cmd, env); Modified: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java Sat Jan 28 15:15:24 2006 @@ -18,11 +18,11 @@ package org.apache.commons.exec; import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.Map; import junit.framework.TestCase; -import org.apache.commons.exec.environment.Environment; - public class ExecTest extends TestCase { private String testDir = "src/test/scripts"; @@ -56,8 +56,8 @@ } public void testExecuteWithEnv() throws Exception { - Environment env = Environment.createEnvironment(); - env.addVariable("TEST_ENV_VAR", "XYZ"); + Map env = new HashMap(); + env.put("TEST_ENV_VAR", "XYZ"); CommandLine cl = new CommandLineImpl(); cl.setExecutable(testScript); Modified: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java?rev=373258&r1=373257&r2=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java Sat Jan 28 15:15:24 2006 @@ -17,7 +17,10 @@ package org.apache.commons.exec; +import java.util.Arrays; + import junit.framework.AssertionFailedError; +import junit.framework.TestCase; public final class TestUtil { @@ -32,5 +35,30 @@ } else { throw new AssertionFailedError("Test not supported for this OS"); } + } + + + public static void assertEquals(Object[] expected, Object[] actual, boolean orderSignificant) { + + if(expected == null && actual == null) { + // all good + } else if (actual == null) { + throw new AssertionFailedError("Expected non null array"); + } else if (expected == null) { + throw new AssertionFailedError("Expected null array"); + } else { + if(expected.length != actual.length) { + throw new AssertionFailedError("Arrays not of same length"); + } + + if(!orderSignificant) { + Arrays.sort(expected); + Arrays.sort(actual); + } + + for (int i = 0; i < actual.length; i++) { + TestCase.assertEquals("Array element at " + i, expected[i], actual[i]); + } + } } } Added: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java?rev=373258&view=auto ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java (added) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java Sat Jan 28 15:15:24 2006 @@ -0,0 +1,93 @@ +/* + * Copyright 2006 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 junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +public class TestUtilTest extends TestCase { + + public void testAssertArrayEquals() { + String[] expected = new String[]{"aaa", "bbb", "ccc"}; + String[] actual = new String[]{"aaa", "bbb", "ccc"}; + + TestUtil.assertEquals(expected, actual, true); + } + + public void testAssertArrayNotEquals() { + String[] expected = new String[]{"aaa", "bbb", "ccc"}; + String[] actual = new String[]{"aaa", "ddd", "ccc"}; + + try{ + TestUtil.assertEquals(expected, actual, true); + fail("Must throw AssertionFailedError"); + } catch(AssertionFailedError e) { + // OK + } + } + + public void testAssertArrayNotOrderEquals() { + String[] expected = new String[]{"aaa", "ccc", "bbb"}; + String[] actual = new String[]{"aaa", "ddd", "ccc"}; + + try{ + TestUtil.assertEquals(expected, actual, true); + fail("Must throw AssertionFailedError"); + } catch(AssertionFailedError e) { + // OK + } + } + + public void testAssertArrayEqualsOrderNotSignificant() { + String[] expected = new String[]{"aaa", "ccc", "bbb"}; + String[] actual = new String[]{"aaa", "bbb", "ccc"}; + + TestUtil.assertEquals(expected, actual, false); + } + + public void testAssertArrayEqualsNullNull() { + String[] expected = null; + String[] actual = null; + + TestUtil.assertEquals(expected, actual, false); + } + + public void testAssertArrayEqualsActualNull() { + String[] expected = new String[]{"aaa", "ccc", "bbb"}; + String[] actual = null; + + try{ + TestUtil.assertEquals(expected, actual, true); + fail("Must throw AssertionFailedError"); + } catch(AssertionFailedError e) { + // OK + } + } + + public void testAssertArrayEqualsExpectedNull() { + String[] expected = null; + String[] actual = new String[]{"aaa", "ddd", "ccc"}; + + try{ + TestUtil.assertEquals(expected, actual, true); + fail("Must throw AssertionFailedError"); + } catch(AssertionFailedError e) { + // OK + } + } +} Propchange: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtilTest.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java (from r356574, jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentTest.java) URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java?p2=jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java&p1=jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentTest.java&r1=356574&r2=373258&rev=373258&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentTest.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilTest.java Sat Jan 28 15:15:24 2006 @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2006 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. @@ -18,58 +18,28 @@ package org.apache.commons.exec.environment; import java.io.IOException; -import java.util.Iterator; +import java.util.HashMap; +import java.util.Map; import junit.framework.TestCase; -public class EnvironmentTest extends TestCase { +import org.apache.commons.exec.TestUtil; - private Environment getPrePopulatedEnvironment() { - Environment env = Environment.createEnvironment(); - env.addVariable("foo", "bar"); - env.addVariable("xxx", "yyy"); - env.addVariable("abc", "def"); +public class EnvironmentUtilTest extends TestCase { - return env; - } - - public void testAddAndGet() { - Environment env = Environment.createEnvironment(); - env.addVariable("foo", "bar"); - assertEquals(EnvironmentVariable - .createEnvironmentVariable("foo", "bar"), env.get("foo")); - } - - public void testSizeAndClear() { - Environment env = getPrePopulatedEnvironment(); - - assertEquals(3, env.size()); - env.clear(); - assertEquals(0, env.size()); - } + public void testToStrings() throws IOException { + Map env = new HashMap(); + + env.put("foo2", "bar2"); + env.put("foo", "bar"); - public void testContainsKey() { - Environment env = getPrePopulatedEnvironment(); + String[] envStrings = EnvironmentUtil.toStrings(env); - assertTrue(env.containsKey("foo")); - assertFalse(env.containsKey("dummy")); + String[] expected = new String[]{"foo=bar", "foo2=bar2"}; + + + TestUtil.assertEquals(expected, envStrings, false); } + - public void testContainsValue() { - Environment env = getPrePopulatedEnvironment(); - - assertTrue(env.containsValue(EnvironmentVariable - .createEnvironmentVariable("foo", "bar"))); - assertFalse(env.containsValue(EnvironmentVariable - .createEnvironmentVariable("dum", "my"))); - } - - public void testGetEnvironment() throws IOException { - Environment env = Environment.getProcEnvironment(); - - for (Iterator iter = env.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); - System.out.println(env.get(key)); - } - } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]