You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tr...@apache.org on 2005/09/23 16:09:20 UTC
svn commit: r291119 - in
/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec:
Execute.java environment/Environment.java
launcher/CommandLauncherFactory.java
Author: trygvis
Date: Fri Sep 23 07:09:14 2005
New Revision: 291119
URL: http://svn.apache.org/viewcvs?rev=291119&view=rev
Log:
o Woops, forgot to commit these.
Modified:
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/environment/Environment.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
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=291119&r1=291118&r2=291119&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 Fri Sep 23 07:09:14 2005
@@ -31,7 +31,7 @@
/**
* Runs an external program.
*/
-public class Execute {
+public class Execute implements Cloneable {
private static Log LOG = LogFactory.getLog(Execute.class);
Modified: 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=291119&r1=291118&r2=291119&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/Environment.java Fri Sep 23 07:09:14 2005
@@ -24,10 +24,7 @@
import java.io.StringReader;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.CommandLineImpl;
@@ -39,16 +36,22 @@
/**
* Wrapper for environment variables.
- * @todo change from inheritence to delegation, implement map
*/
-public class Environment extends HashMap {
+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();
+
+ // ----------------------------------------------------------------------
+ // Static factory methods
+ // ----------------------------------------------------------------------
+
public static Environment createEnvironment() {
if (OS.isFamilyOpenVms()) {
return new OpenVmsEnvironment();
@@ -107,7 +110,7 @@
* new variable.
*/
public void addVariable(final EnvironmentVariable var) {
- put(var.getKey(), var);
+ environment.put(var.getKey(), var);
}
/**
@@ -121,7 +124,48 @@
* @throws NullPointerException if </CODE>key</CODE> or <CODE>value</CODE> is <CODE>null</CODE>.
*/
public void addVariable(final String key, final String value) {
- put(key, EnvironmentVariable.createEnvironmentVariable(key, 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);
}
/**
@@ -131,7 +175,7 @@
* the key.
*/
public EnvironmentVariable getVariable(final String key) {
- return (EnvironmentVariable) get(key);
+ return (EnvironmentVariable) environment.get(key);
}
/**
@@ -141,7 +185,7 @@
* the key.
*/
public String getVariableValue(final String key) {
- return ((EnvironmentVariable) get(key)).getValue();
+ return ((EnvironmentVariable) environment.get(key)).getValue();
}
/**
@@ -150,12 +194,12 @@
* @return array of key=value assignment strings
*/
public String[] getVariables() {
- if (size() == 0) {
+ if (environment.size() == 0) {
return null;
}
- String[] result = new String[size()];
+ String[] result = new String[environment.size()];
int i = 0;
- for (Iterator iter = entrySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
result[i] = entry.getValue().toString();
@@ -299,5 +343,23 @@
}
}
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;
}
}
Modified: 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=291119&r1=291118&r2=291119&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java Fri Sep 23 07:09:14 2005
@@ -33,17 +33,14 @@
*/
public static CommandLauncher createVMLauncher() {
// Try using a JDK 1.3 launcher
- CommandLauncher launcher = null;
- try {
- if (OS.isFamilyOpenVms()) {
- launcher = new VmsCommandLauncher();
- // TODO why not use Java13CommandLauncher on OS2?
- //} else if (!OS.isFamilyOS2()) {
- } else {
- launcher = new Java13CommandLauncher();
- }
- } catch (NoSuchMethodException exc) {
- // Ignore and keep trying
+ CommandLauncher launcher;
+
+ if (OS.isFamilyOpenVms()) {
+ launcher = new VmsCommandLauncher();
+ // TODO why not use Java13CommandLauncher on OS2?
+ //} else if (!OS.isFamilyOS2()) {
+ } else {
+ launcher = new Java13CommandLauncher();
}
return launcher;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org