commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r664646 - in /commons/proper/cli/trunk/src: java/org/apache/commons/cli2/ java/org/apache/commons/cli2/commandline/ java/org/apache/commons/cli2/option/ test/org/apache/commons/cli2/bug/
Date Mon, 09 Jun 2008 07:37:19 GMT
Author: bayard
Date: Mon Jun  9 00:37:19 2008
New Revision: 664646

URL: http://svn.apache.org/viewvc?rev=664646&view=rev
Log:
Applying Andrew's fix to CLI-61 and rolling back the getMessageKey addition to OptionException
that was applied from CLI-145

Modified:
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/OptionException.java
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/WriteableCommandLine.java
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/OptionException.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/OptionException.java?rev=664646&r1=664645&r2=664646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/OptionException.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/OptionException.java Mon Jun
 9 00:37:19 2008
@@ -43,9 +43,6 @@
     /** The message explaining the Exception */
     private final String message;
 
-    /** The id of the message */
-    private final String messageKey;
-
     /**
      * Creates a new OptionException.
      *
@@ -76,7 +73,6 @@
                            final String messageKey,
                            final String value) {
         this.option = option;
-        this.messageKey = messageKey;
 
         if (messageKey != null) {
             final StringBuffer buffer = new StringBuffer();
@@ -109,7 +105,4 @@
         return message;
     }
 
-    public String getMessageKey() {
-        return messageKey;
-    }
 }

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/WriteableCommandLine.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/WriteableCommandLine.java?rev=664646&r1=664645&r2=664646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/WriteableCommandLine.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/WriteableCommandLine.java Mon
Jun  9 00:37:19 2008
@@ -37,6 +37,16 @@
     void addValue(final Option option, final Object value);
 
     /**
+     * Retrieves the Argument values specified on the command line for the
+     * specified Option, this doesn't return any values supplied
+     * programmatically as defaults.
+     *
+     * @param option the Option associated with the values
+     * @return a list of values or an empty List if none are found
+     */
+    List getUndefaultedValues(final Option option);
+
+    /**
      * Sets the default values for an Option in the CommandLine
      * @param option the Option to add to
      * @param defaultValues the defaults for the option

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java?rev=664646&r1=664645&r2=664646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java
(original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java
Mon Jun  9 00:37:19 2008
@@ -129,6 +129,18 @@
         return valueList;
     }
 
+    public List getUndefaultedValues(Option option) {
+      // First grab the command line values
+      List valueList = (List) values.get(option);
+
+      // Finally use an empty list
+      if (valueList == null) {
+        valueList = Collections.EMPTY_LIST;
+      }
+
+      return valueList;
+    }
+
     public Boolean getSwitch(final Option option,
                              final Boolean defaultValue) {
         // First grab the command line values

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java?rev=664646&r1=664645&r2=664646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java Mon
Jun  9 00:37:19 2008
@@ -141,7 +141,7 @@
                               final Option option)
         throws OptionException {
         // count of arguments processed for this option.
-        int argumentCount = 0;
+        int argumentCount = commandLine.getUndefaultedValues(option).size();
 
         while (arguments.hasNext() && (argumentCount < maximum)) {
             final String allValuesQuoted = (String) arguments.next();

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java?rev=664646&r1=664645&r2=664646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java
(original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java
Mon Jun  9 00:37:19 2008
@@ -23,7 +23,6 @@
 import org.apache.commons.cli2.Argument;
 import org.apache.commons.cli2.Group;
 import org.apache.commons.cli2.OptionException;
-import org.apache.commons.cli2.resource.ResourceConstants;
 import org.apache.commons.cli2.builder.ArgumentBuilder;
 import org.apache.commons.cli2.builder.DefaultOptionBuilder;
 import org.apache.commons.cli2.builder.GroupBuilder;
@@ -74,7 +73,7 @@
             parser.parse(new String[] { "testfile.txt", "testfile.txt", "testfile.txt", "testfile.txt"
});
             fail("OptionException");
         } catch (OptionException e) {
-            assertEquals(ResourceConstants.ARGUMENT_UNEXPECTED_VALUE, e.getMessageKey());
+            assertEquals("Unexpected testfile.txt while processing ", e.getMessage());
         }
     }    
 }



Mime
View raw message