rpms/jakarta-commons-cli/devel jakarta-commons-cli-MultiOptions.patch, NONE, 1.1 jakarta-commons-cli.spec, 1.12, 1.13

Deepak Bhole dbhole at fedoraproject.org
Thu Feb 26 20:12:42 UTC 2009


Author: dbhole

Update of /cvs/extras/rpms/jakarta-commons-cli/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv2338

Modified Files:
	jakarta-commons-cli.spec 
Added Files:
	jakarta-commons-cli-MultiOptions.patch 
Log Message:

- Add multi options patch to cvs



jakarta-commons-cli-MultiOptions.patch:

--- NEW FILE jakarta-commons-cli-MultiOptions.patch ---
Index: src/test/org/apache/commons/cli/ApplicationTest.java
===================================================================
--- src/test/org/apache/commons/cli/ApplicationTest.java	(revision 635884)
+++ src/test/org/apache/commons/cli/ApplicationTest.java	(working copy)
@@ -96,15 +96,16 @@
         options.addOption( "listener", true, "add an instance of a class as a project listener" );
         options.addOption( "buildfile", true, "use given buildfile" );
         options.addOption( OptionBuilder.withDescription( "use value for given property" )
-                                        .hasArgs()
+                                        .hasArgs(1)
                                         .withValueSeparator()
                                         .create( 'D' ) );
                            //, null, true, , false, true );
         options.addOption( "find", true, "search for buildfile towards the root of the filesystem and use it" );
 
         String[] args = new String[]{ "-buildfile", "mybuild.xml",
+            "-projecthelp",
             "-Dproperty=value", "-Dproperty1=value1",
-            "-projecthelp" };
+            "compile" };
 
         try {
             CommandLine line = parser.parse( options, args );
@@ -121,6 +122,7 @@
 
             // check option
             assertTrue( line.hasOption( "projecthelp") );
+            assertEquals(1, line.getArgs().length);
         }
         catch( ParseException exp ) {
             fail( "Unexpected exception:" + exp.getMessage() );
@@ -128,4 +130,4 @@
 
     }
 
-}
\ No newline at end of file
+}
Index: src/java/org/apache/commons/cli/Option.java
===================================================================
--- src/java/org/apache/commons/cli/Option.java	(revision 635884)
+++ src/java/org/apache/commons/cli/Option.java	(working copy)
@@ -437,13 +437,15 @@
             // while there are more value separators
             while (index != -1)
             {
-                // next value to be added 
-                if (values.size() == (numberOfArgs - 1))
-                {
-                    break;
-                }
+                // Next few lines commented out in the patch. You
+            	// can have multiple values in one argument, so it does not
+            	// make sense to terminate the loop early (you would lose
+            	// the excess arguments anyway).
+//                if (values.size() == (numberOfArgs - 1))
+//                {
+//                    break;
+//                }
 
-
                 // store
                 add(value.substring(0, index));
 
@@ -463,9 +465,7 @@
     }
 
     /**
-     * Add the value to this Option.  If the number of arguments
-     * is greater than zero and there is enough space in the list then
-     * add the value.  Otherwise, throw a runtime exception.
+     * Add the value to this Option.
      *
      * @param value The value to be added to this Option
      *
@@ -473,10 +473,14 @@
      */
     private void add(String value)
     {
-        if ((numberOfArgs > 0) && (values.size() > (numberOfArgs - 1)))
-        {
-            throw new RuntimeException("Cannot add value, list full.");
-        }
+    	// The patch removes the following code as we check for
+    	// numberOfArgs in the caller (where we can tell the difference
+    	// between (e.g) multiple instances of an option versus one
+    	// instance of the option with multiple arguments).
+//        if ((numberOfArgs > 0) && (values.size() > (numberOfArgs - 1)))
+//        {
+//            throw new RuntimeException("Cannot add value, list full.");
+//        }
 
 
         // store value
Index: src/java/org/apache/commons/cli/Parser.java
===================================================================
--- src/java/org/apache/commons/cli/Parser.java	(revision 635884)
+++ src/java/org/apache/commons/cli/Parser.java	(working copy)
@@ -325,7 +325,9 @@
     public void processArgs(Option opt, ListIterator iter)
         throws ParseException
     {
-        // loop until an option is found
+        // loop until another option is found, or we have read the maximum
+    	// number of args.
+    	int argCount = 0;
         while (iter.hasNext())
         {
             String str = (String) iter.next();
@@ -347,6 +349,12 @@
                 iter.previous();
                 break;
             }
+            
+            argCount++;
+            if (argCount >= opt.getArgs() && opt.getArgs() >= 0)
+            {
+            	break;
+            }
         }
 
         if ((opt.getValues() == null) && !opt.hasOptionalArg())



Index: jakarta-commons-cli.spec
===================================================================
RCS file: /cvs/extras/rpms/jakarta-commons-cli/devel/jakarta-commons-cli.spec,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- jakarta-commons-cli.spec	26 Feb 2009 20:02:09 -0000	1.12
+++ jakarta-commons-cli.spec	26 Feb 2009 20:12:12 -0000	1.13
@@ -5,7 +5,7 @@
 
 Name:           %{name}
 Version:        1.1
-Release:        3%{?dist}
+Release:        4%{?dist}
 Epoch:          0
 Summary:        Command Line Interface Library for Java
 License:        ASL 2.0
@@ -88,6 +88,9 @@
 
 
 %changelog
+* Thu Feb 26 2009 Deepak Bhole <dbhole at redhat.com> 0:1.1-4
+- Add multi options patch to cvs
+
 * Thu Feb 26 2009 Deepak Bhole <dbhole at redhat.com> 0:1.1-3
 - Fix rhbz: 480093. Add MultiOptions.patch from the Debian cli package
 




More information about the scm-commits mailing list