ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r706432 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/util/cli/CommandLineParser.java test/java/org/apache/ivy/MainTest.java
Date Mon, 20 Oct 2008 22:26:49 GMT
Author: maartenc
Date: Mon Oct 20 15:26:49 2008
New Revision: 706432

URL: http://svn.apache.org/viewvc?rev=706432&view=rev
Log:
FIX: Support for passing arbitrary arguments to the -main invoked class when using the standalone
mode is severely limited (IVY-952) (thanks to Patrick Woodworth)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/cli/CommandLineParser.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/MainTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=706432&r1=706431&r2=706432&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon Oct 20 15:26:49 2008
@@ -108,6 +108,7 @@
 - FIX: pre-resolve-dependency event doesn't export branch information (IVY-941) (thanks to
Jaroslaw Wypychowski)
 - FIX: cachefileset produces an empty fileset when the cache refers to libs in directories
that only have the root directory in common (IVY-948) (thanks to Chris Wood)
 - FIX: Extra Attributes specified in the Dependency's Module Descriptor are not available
to resolvers (IVY-929) (thanks to Scott Hebert)
+- FIX: Support for passing arbitrary arguments to the -main invoked class when using the
standalone mode is severely limited (IVY-952) (thanks to Patrick Woodworth)
 
    2.0.0-rc1
 =====================================

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/cli/CommandLineParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/cli/CommandLineParser.java?rev=706432&r1=706431&r2=706432&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/cli/CommandLineParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/cli/CommandLineParser.java Mon Oct 20
15:26:49 2008
@@ -54,22 +54,34 @@
     
     public CommandLine parse(String[] args) throws ParseException {
         CommandLine line = new CommandLine();
-        for (ListIterator iterator = Arrays.asList(args).listIterator(); iterator.hasNext();)
{
+        
+        int index = args.length;
+        ListIterator iterator = Arrays.asList(args).listIterator();
+        while (iterator.hasNext()) {
             String arg = (String) iterator.next();
-            if (arg.startsWith("-")) {
-                Option option = (Option) options.get(arg.substring(1));
-                if (option == null) {
-                    throw new ParseException("Unrecognized option: " + arg);
-                }
-                line.addOptionValues(arg.substring(1), option.parse(iterator));
-            } else {
-                // left over args
-                int index = iterator.previousIndex() + 1;
-                String[] leftOverArgs = new String[args.length - index];
-                System.arraycopy(args, index, leftOverArgs, 0, leftOverArgs.length);
-                line.setLeftOverArgs(leftOverArgs);
+            if ("--".equals(arg)) {
+                // skip this argument and stop looping
+                index = iterator.nextIndex();
+                break;
+            }
+
+            if (!arg.startsWith("-")) {
+                index = iterator.previousIndex();
+                break;
             }
+            
+            Option option = (Option) options.get(arg.substring(1));
+            if (option == null) {
+                throw new ParseException("Unrecognized option: " + arg);
+            }
+            line.addOptionValues(arg.substring(1), option.parse(iterator));
         }
+        
+        // left over args
+        String[] leftOverArgs = new String[args.length - index];
+        System.arraycopy(args, index, leftOverArgs, 0, leftOverArgs.length);
+        line.setLeftOverArgs(leftOverArgs);
+
         return line;
     }
 

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/MainTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/MainTest.java?rev=706432&r1=706431&r2=706432&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/MainTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/MainTest.java Mon Oct 20 15:26:49 2008
@@ -20,6 +20,7 @@
 import java.io.File;
 
 import org.apache.ivy.util.CacheCleaner;
+import org.apache.ivy.util.cli.CommandLine;
 import org.apache.ivy.util.cli.ParseException;
 
 import junit.framework.TestCase;
@@ -84,6 +85,48 @@
         });
         assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
     }
+    
+    public void testExtraParams1() throws Exception {
+        String[] params = new String[] {
+                "-settings", "test/repositories/ivysettings.xml",
+                "-confs", "default",
+                "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml",
+                "foo1", "foo2"
+        };
+        CommandLine line = Main.getParser().parse(params);
+        String[] leftOver = line.getLeftOverArgs();
+        assertNotNull(leftOver);
+        assertEquals(2, leftOver.length);
+        assertEquals("foo1", leftOver[0]);
+        assertEquals("foo2", leftOver[1]);
+    }
+
+    public void testExtraParams2() throws Exception {
+        String[] params = new String[] {
+                "-settings", "test/repositories/ivysettings.xml",
+                "-confs", "default",
+                "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml",
+                "--", "foo1", "foo2"
+        };
+        CommandLine line = Main.getParser().parse(params);
+        String[] leftOver = line.getLeftOverArgs();
+        assertNotNull(leftOver);
+        assertEquals(2, leftOver.length);
+        assertEquals("foo1", leftOver[0]);
+        assertEquals("foo2", leftOver[1]);
+    }
+
+    public void testExtraParams3() throws Exception {
+        String[] params = new String[] {
+                "-settings", "test/repositories/ivysettings.xml",
+                "-confs", "default",
+                "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"
+        };
+        CommandLine line = Main.getParser().parse(params);
+        String[] leftOver = line.getLeftOverArgs();
+        assertNotNull(leftOver);
+        assertEquals(0, leftOver.length);
+    }
 
     private void run(String[] args) throws Exception {
         Main.run(Main.getParser(), args);



Mime
View raw message