Author: sgoeschl
Date: Mon Sep 20 19:18:34 2010
New Revision: 999067

URL: http://svn.apache.org/viewvc?rev=999067&view=rev
Log:
Added a copy constructor for CommandLine()

Modified:
    
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
    
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java

Modified: 
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
URL: 
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java?rev=999067&r1=999066&r2=999067&view=diff
==============================================================================
--- 
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
 (original)
+++ 
commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java
 Mon Sep 20 19:18:34 2010
@@ -21,6 +21,8 @@ package org.apache.commons.exec;
 import org.apache.commons.exec.util.StringUtils;
 
 import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.Map;
@@ -110,6 +112,29 @@ public class CommandLine {
     }
 
     /**
+     * Copy constructor.
+     *
+     * @param other the instance to copy
+     */
+    public CommandLine(CommandLine other)
+    {
+        this.executable = other.getExecutable();
+        this.isFile = other.isFile();
+        this.arguments.addAll(other.arguments);
+
+        if(other.getSubstitutionMap() != null)
+        {
+            this.substitutionMap = new HashMap();
+            Iterator iterator = other.substitutionMap.keySet().iterator();
+            while(iterator.hasNext())
+            {
+                Object key = iterator.next();
+                this.substitutionMap.put(key, 
other.getSubstitutionMap().get(key));
+            }
+        }
+    }
+
+    /**
      * Returns the executable.
      * 
      * @return The executable

Modified: 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java?rev=999067&r1=999066&r2=999067&view=diff
==============================================================================
--- 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java
 (original)
+++ 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java
 Mon Sep 20 19:18:34 2010
@@ -21,6 +21,7 @@ package org.apache.commons.exec;
 import java.io.File;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Map;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
@@ -506,4 +507,20 @@ public class CommandLineTest extends Tes
         assertEquals("CFG=\"WeightsEngine - Win32Release\"", args[2]);
     }
 
+    public void testCopyConstructor()
+    {
+        Map map = new HashMap();
+        map.put("bar", "bar");
+        CommandLine other = new CommandLine("test");
+        other.addArgument("foo");
+        other.setSubstitutionMap(map);
+
+        CommandLine cmdl = new CommandLine(other);
+        assertEquals(other.getExecutable(), cmdl.getExecutable());
+        assertEquals(other.getArguments(), cmdl.getArguments());
+        assertEquals(other.isFile(), cmdl.isFile());
+        assertEquals(other.getSubstitutionMap(), cmdl.getSubstitutionMap());
+
+    }
+
 }


Reply via email to