commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roxspr...@apache.org
Subject cvs commit: jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2 PropertyOptionTest.java CommandLineTest.java GroupTest.java ApplicationTest.java
Date Fri, 24 Oct 2003 18:49:49 GMT
roxspring    2003/10/24 11:49:49

  Modified:    cli/src/java/org/apache/commons/cli2 ArgumentBuilder.java
                        Option.java GroupImpl.java PropertyOption.java
                        ArgumentImpl.java CommandLine.java ParentImpl.java
                        Group.java CommandLineParser.java
               cli/src/test/org/apache/commons/cli2 PropertyOptionTest.java
                        CommandLineTest.java GroupTest.java
                        ApplicationTest.java
  Added:       cli/src/java/org/apache/commons/cli2 OptionImpl.java
  Log:
  Moving ConsumeRemaining logic to ArgumentImpl
  PR: 24038
  
  Option:
  The documented contract of process(..) has been strengthened so that the method is expected
to process at least one argument from the ListIterator.  Also added new canProcess(ListIterator)
method to allow more convenient tests.
  
  OptionImpl:
  Added new supertype to existing Options with a standard canProcess(ListIterator) implementation.
 Also added a standard toString() method making use of appendUsage(..).
  
  Group:
  Removed processOptions(..) and processArguments(..) since there is no need to enforce the
separation, and it made things less convenient with the new process(..) contract.
  
  GroupImpl:
  canProcess(String) now checks
  
  ArgumentImpl:
  Now throws MissingValueException() is process(..) is called when no arguments can be processed.
  
  CommandLine:
  Removed all references to the list of unprocessed arguments.
  
  CommandLineParser:
  parse(..) now repeatedly processes options until there is nothing more to process.
  
  Revision  Changes    Path
  1.5       +22 -3     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ArgumentBuilder.java
  
  Index: ArgumentBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ArgumentBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArgumentBuilder.java	21 Oct 2003 20:23:21 -0000	1.4
  +++ ArgumentBuilder.java	24 Oct 2003 18:49:48 -0000	1.5
  @@ -110,6 +110,11 @@
        * The validator object that should be used to ensure the values are valid
        */
       private Validator validator;
  +    
  +    /**
  +     * The string used for any consume remaining option, typically "--"
  +     */
  +    private String consumeRemaining;
   
       /**
        * Creates a new Argument instance using the options specified in this
  @@ -147,6 +152,7 @@
           maximum = Integer.MAX_VALUE;
           initialSeparator = ArgumentImpl.DEFAULT_INITIAL_SEPARATOR;
           subsequentSeparator = ArgumentImpl.DEFAULT_SUBSEQUENT_SEPARATOR;
  +        consumeRemaining = "--";
       }
   
       /**
  @@ -238,6 +244,19 @@
       public final ArgumentBuilder withValidator(final Validator validator)
       {
           this.validator = validator;
  +        return this;
  +    }
  +    
  +    /**
  +     * Sets the "consume remaining" option, defaults to "--".
  +     * Use this if you want to allow values that might be confused with
  +     * option strings.
  +     *
  +     * @param consumeRemaining The string to use for the consume remaining option.
  +     */
  +    public final ArgumentBuilder withConsumeRemaining(final String consumeRemaining)
  +    {
  +        this.consumeRemaining = consumeRemaining;
           return this;
       }
   }
  
  
  
  1.2       +20 -8     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/Option.java
  
  Index: Option.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/Option.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Option.java	18 Oct 2003 22:00:13 -0000	1.1
  +++ Option.java	24 Oct 2003 18:49:48 -0000	1.2
  @@ -76,10 +76,11 @@
   	/**
   	 * Processes String arguments into a CommandLine.
   	 * 
  -	 * The iterator will initially point at the first argument to be processed 
  -	 * and at the end of the method should point to the first argument not 
  -	 * processed.
  -	 *  
  +	 * The iterator will initially point at the first argument to be processed
  +	 * and at the end of the method should point to the first argument not
  +	 * processed.  This method MUST process at least one argument from the
  +     * ListIterator.
  +	 *
   	 * @param commandLine The CommandLine object to store results in
   	 * @param args The arguments to process
   	 */
  @@ -93,7 +94,18 @@
   	 * @param arg The argument to be tested
   	 * @return true if the argument can be processed by this Option
   	 */
  -	public boolean canProcess(final String arg);
  +	public boolean canProcess(final String argument);
  +    
  +    /**
  +     * Indicates whether this Option will be able to process the particular
  +     * argument.  The ListIterator must be restored to the initial state
  +     * before returning the boolean.
  +     * 
  +     * @see #canProcess(String)
  +     * @param arguments the ListIterator over String arguments
  +     * @return true if the argument can be processed by this Option 
  +     */
  +    public boolean canProcess(final ListIterator arguments);
   
   	/**
   	 * Identifies the argument prefixes that should trigger this option.
  
  
  
  1.3       +56 -58    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/GroupImpl.java
  
  Index: GroupImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/GroupImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GroupImpl.java	22 Oct 2003 16:32:14 -0000	1.2
  +++ GroupImpl.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -73,7 +73,7 @@
   import java.util.SortedMap;
   import java.util.TreeMap;
   
  -public class GroupImpl implements Group {
  +public class GroupImpl extends OptionImpl implements Group {
   
   	private final String name;
   	private final String description;
  @@ -132,6 +132,16 @@
   				return true;
   			}
   		}
  +        
  +        final ListIterator j = anonymous.listIterator();
  +        while(j.hasNext())
  +        {
  +            final Option option = (Option)j.next();
  +            System.out.println("   "+option);
  +            if(option.canProcess(arg)){
  +                return true;
  +            }
  +        }
   
   		return false;
   	}
  @@ -164,62 +174,50 @@
   		final CommandLine commandLine,
   		final ListIterator arguments)
   		throws OptionException {
  -
  -		processOptions(commandLine, arguments);
  -		processArguments(commandLine, arguments);
  +        
  +        boolean foundOption = true;
  +        while (arguments.hasNext() && foundOption) {
  +            foundOption = false;
  +            final String arg = (String) arguments.next();
  +
  +            final Option opt = (Option) optionMap.get(arg);
  +            if (opt != null) {
  +                arguments.previous();
  +                opt.process(commandLine, arguments);
  +                foundOption = true;
  +            } else {
  +                final SortedMap tailMap = optionMap.tailMap(arg);
  +
  +                final Iterator i = tailMap.entrySet().iterator();
  +                while (i.hasNext()) {
  +                    final Map.Entry entry = (Map.Entry) i.next();
  +                    final Option option = (Option) entry.getValue();
  +                    if (option.canProcess(arg)) {
  +                        arguments.previous();
  +                        option.process(commandLine, arguments);
  +                        foundOption = true;
  +                    }
  +                }
  +            }
  +        }
  +    
  +        if (!foundOption) {
  +            arguments.previous();
  +        }
  +    
  +        for (final Iterator i = anonymous.iterator(); i.hasNext();) {
  +            final Argument argument = (Argument) i.next();
  +            if(argument.canProcess(arguments)){
  +                argument.process(commandLine, arguments);
  +                foundOption = true;
  +            }
  +        }
  +
  +        if (!foundOption) {
  +            throw new MissingOptionException(this);
  +        }
   	}
   
  -	/* (non-Javadoc)
  -	 * @see org.apache.commons.cli2.Group#processOptions(org.apache.commons.cli2.CommandLine,
java.util.ListIterator, java.util.Set)
  -	 */
  -	public void processOptions(CommandLine commandLine, ListIterator arguments)
  -		throws OptionException {
  -
  -		boolean foundOption = true;
  -		while (arguments.hasNext() && foundOption) {
  -			foundOption = false;
  -			final String arg = (String) arguments.next();
  -
  -			final Option opt = (Option) optionMap.get(arg);
  -			if (opt != null) {
  -				arguments.previous();
  -				opt.process(commandLine, arguments);
  -				foundOption = true;
  -			} else {
  -				final SortedMap tailMap = optionMap.tailMap(arg);
  -
  -				final Iterator i = tailMap.entrySet().iterator();
  -				while (i.hasNext()) {
  -					final Map.Entry entry = (Map.Entry) i.next();
  -					final Option option = (Option) entry.getValue();
  -					if (option.canProcess(arg)) {
  -						arguments.previous();
  -						option.process(commandLine, arguments);
  -						foundOption = true;
  -					}
  -				}
  -			}
  -		}
  -
  -		if (!foundOption) {
  -			arguments.previous();
  -		}
  -	}
  -
  -	/* (non-Javadoc)
  -	 * @see org.apache.commons.cli2.Group#processAnonymousArguments(org.apache.commons.cli2.CommandLine,
java.util.ListIterator, java.util.Set)
  -	 */
  -	public void processArguments(
  -		CommandLine commandLine,
  -		ListIterator arguments)
  -		throws OptionException {
  -
  -		for (final Iterator i = anonymous.iterator(); i.hasNext();) {
  -			final Argument argument = (Argument) i.next();
  -
  -			argument.process(commandLine, arguments);
  -		}
  -	}
   	/* (non-Javadoc)
   	 * @see org.apache.commons.cli2.Option#validate(org.apache.commons.cli2.CommandLine)
   	 */
  
  
  
  1.3       +4 -4      jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/PropertyOption.java
  
  Index: PropertyOption.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/PropertyOption.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PropertyOption.java	23 Oct 2003 08:34:45 -0000	1.2
  +++ PropertyOption.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -72,7 +72,7 @@
    * "-Dprop=value"
    * opions
    */
  -public class PropertyOption implements Option {
  +public class PropertyOption extends OptionImpl implements Option {
   
   	private static final String DEFAULT_OPTION_STRING = "-D";
   	private static final String DEFAULT_DESCRIPTION =
  
  
  
  1.6       +8 -6      jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ArgumentImpl.java
  
  Index: ArgumentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ArgumentImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArgumentImpl.java	23 Oct 2003 23:34:23 -0000	1.5
  +++ ArgumentImpl.java	24 Oct 2003 18:49:48 -0000	1.6
  @@ -74,7 +74,7 @@
    * An implementation of an Argument.
    * @author Rob Oxspring
    */
  -public class ArgumentImpl implements Argument
  +public class ArgumentImpl extends OptionImpl implements Argument
   {
   
       private final String name;
  @@ -143,6 +143,7 @@
           throws OptionException {
   
           int argumentCount = commandLine.getValues(this).size();
  +        final int initialCount = argumentCount;
           while (arguments.hasNext() && argumentCount < maximum) {
   
               final String allValues = (String) arguments.next();
  @@ -161,12 +162,13 @@
                   ++argumentCount;
                   commandLine.addValue(this, values.nextToken());
               }
  +            
               if (values.hasMoreTokens()) {
                   throw new UnexpectedValueException(this, values.nextToken());
               }
           }
  -
  -        if (argumentCount < minimum) {
  +        
  +        if (argumentCount < minimum || initialCount == argumentCount) {
               throw new MissingValueException(this);
           }
       }
  
  
  
  1.5       +4 -16     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLine.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommandLine.java	24 Oct 2003 00:10:31 -0000	1.4
  +++ CommandLine.java	24 Oct 2003 18:49:48 -0000	1.5
  @@ -79,7 +79,6 @@
   public class CommandLine {
   
   	private final Properties properties = new Properties();
  -	private final List unprocessed = new ArrayList();
   	private final List options = new ArrayList();
   	private final Map nameToOption = new HashMap();
   	private final Map values = new HashMap();
  @@ -121,10 +120,6 @@
   		}
   	}
   
  -	public void addUnprocessed(final String argument) {
  -		unprocessed.add(argument);
  -	}
  -
   	public boolean hasOption(final String trigger) {
   		return nameToOption.containsKey(trigger);
   	}
  @@ -173,10 +168,6 @@
   		return (Boolean) switches.get(option);
   	}
   
  -	public List getUnprocessed() {
  -		return Collections.unmodifiableList(unprocessed);
  -	}
  -
   	public void addProperty(final String property, final String value) {
   		properties.setProperty(property, value);
   	}
  @@ -209,10 +200,7 @@
   
   		// need to add group header
   
  -		final List args = new ArrayList(normalised);
  -		args.addAll(unprocessed);
  -
  -		for (final Iterator i = args.iterator(); i.hasNext();) {
  +		for (final Iterator i = normalised.iterator(); i.hasNext();) {
   			final String arg = (String) i.next();
   			if (arg.indexOf(' ') >= 0) {
   				buffer.append("\"").append(arg).append("\"");
  
  
  
  1.3       +5 -5      jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ParentImpl.java
  
  Index: ParentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/ParentImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParentImpl.java	22 Oct 2003 23:34:42 -0000	1.2
  +++ ParentImpl.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -70,7 +70,7 @@
   /**
    * @author Rob Oxspring
    */
  -public abstract class ParentImpl implements Parent {
  +public abstract class ParentImpl extends OptionImpl implements Parent {
   
   	private final Group children;
   
  @@ -105,7 +105,7 @@
   			argument.processValues(commandLine, arguments, this);
   		}
   
  -		if (children != null) {
  +		if (children != null && children.canProcess(arguments)) {
   			children.process(commandLine, arguments);
   		}
   	}
  
  
  
  1.2       +78 -89    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/Group.java
  
  Index: Group.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/Group.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Group.java	18 Oct 2003 22:00:09 -0000	1.1
  +++ Group.java	24 Oct 2003 18:49:48 -0000	1.2
  @@ -1,90 +1,79 @@
  -/*
  - * $Header$
  - * $Revision$
  - * $Date$
  - *
  - * ====================================================================
  - *
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2003 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache GroupImpl.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */
  -package org.apache.commons.cli2;
  -
  -import java.util.Comparator;
  -import java.util.ListIterator;
  -import java.util.Set;
  -
  -/**
  - * @author Rob Oxspring
  - *
  - * To change the template for this generated type comment go to
  - * Window>Preferences>Java>Code Generation>Code and Comments
  - */
  -public interface Group extends Option {
  -
  -	public void processOptions(
  -		final CommandLine commandLine,
  -		final ListIterator arguments)
  -		throws OptionException;
  -
  -	public void processArguments(
  -		final CommandLine commandLine,
  -		final ListIterator arguments)
  -		throws OptionException;
  -
  -	public void appendUsage(
  -		final StringBuffer buffer,
  -		final Set helpSettings,
  -		final Comparator comp,
  -		final String separator);
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache GroupImpl.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + *
  + */
  +package org.apache.commons.cli2;
  +
  +import java.util.Comparator;
  +import java.util.Set;
  +
  +/**
  + * @author Rob Oxspring
  + *
  + * To change the template for this generated type comment go to
  + * Window>Preferences>Java>Code Generation>Code and Comments
  + */
  +public interface Group extends Option {
  +
  +	public void appendUsage(
  +		final StringBuffer buffer,
  +		final Set helpSettings,
  +		final Comparator comp,
  +		final String separator);
   }
  
  
  
  1.3       +13 -16    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLineParser.java
  
  Index: CommandLineParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLineParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommandLineParser.java	22 Oct 2003 17:01:06 -0000	1.2
  +++ CommandLineParser.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -99,19 +99,16 @@
   		final List argumentList = new LinkedList(Arrays.asList(arguments));
   		final ListIterator iterator = argumentList.listIterator();
   		final CommandLine commandLine = new CommandLine(group, new ArrayList());
  -		group.process(commandLine, iterator);
  -
  -		if (unprocessedAllowed) {
  -			while (iterator.hasNext()) {
  -				commandLine.addUnprocessed((String) iterator.next());
  -			}
  -		} else {
  -			if (iterator.hasNext()) {
  -				throw new UnexpectedOptionException(
  -					group,
  -					(String) iterator.next());
  -			}
  -		}
  +        
  +        while(group.canProcess(iterator))
  +        {
  +            group.process(commandLine, iterator);
  +        }
  +        
  +        if(iterator.hasNext()){
  +            final String arg = (String)iterator.next();
  +            throw new UnexpectedOptionException(group,arg);
  +        }
   
   		group.validate(commandLine);
   
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/OptionImpl.java
  
  Index: OptionImpl.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/OptionImpl.java,v
1.1 2003/10/24 18:49:48 roxspring Exp $
   * $Revision: 1.1 $
   * $Date: 2003/10/24 18:49:48 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache GroupImpl.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.cli2;
  
  import java.util.ListIterator;
  
  /**
   * @author Rob Oxspring
   *
   * To change the template for this generated type comment go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  public abstract class OptionImpl implements Option {
  
      /* (non-Javadoc)
       * @see org.apache.commons.cli2.Option#canProcess(java.util.ListIterator)
       */
      public boolean canProcess(final ListIterator arguments) {
          if(arguments.hasNext()){
              final String argument = (String)arguments.next();
              arguments.previous();
              return canProcess(argument);
          }
          else{
              return false;
          }
      }
      
      public String toString(){
          final StringBuffer buffer = new StringBuffer();
          appendUsage(buffer, HelpSetting.ALL, null);
          return buffer.toString();
      }
  }
  
  
  
  1.4       +4 -4      jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/PropertyOptionTest.java
  
  Index: PropertyOptionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/PropertyOptionTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertyOptionTest.java	23 Oct 2003 08:34:45 -0000	1.3
  +++ PropertyOptionTest.java	24 Oct 2003 18:49:48 -0000	1.4
  @@ -84,7 +84,7 @@
   
   	public void testCanProcess_Null() {
   		final Option option = new PropertyOption();
  -		assertFalse(option.canProcess(null));
  +		assertFalse(option.canProcess((String)null));
   	}
   
   	public void testCanProcess_TooShort() {
  
  
  
  1.5       +3 -28     jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/CommandLineTest.java
  
  Index: CommandLineTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/CommandLineTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommandLineTest.java	24 Oct 2003 00:10:31 -0000	1.4
  +++ CommandLineTest.java	24 Oct 2003 18:49:48 -0000	1.5
  @@ -94,31 +94,6 @@
   		assertEquals("myval3", commandLine.getProperty("myprop2"));
   	}
   
  -	public void testUnprocessed() {
  -		final Option option = new PropertyOption();
  -		final List args = OptionTestCase.list();
  -		final CommandLine commandLine =
  -			OptionTestCase.commandLine(option, args);
  -
  -		assertTrue(commandLine.getUnprocessed().isEmpty());
  -
  -		commandLine.addUnprocessed("file1");
  -		assertEquals(1, commandLine.getUnprocessed().size());
  -		assertEquals("file1", commandLine.getUnprocessed().get(0));
  -
  -		commandLine.addUnprocessed("file2");
  -		assertEquals(2, commandLine.getUnprocessed().size());
  -		assertEquals("file1", commandLine.getUnprocessed().get(0));
  -		assertEquals("file2", commandLine.getUnprocessed().get(1));
  -
  -		try {
  -			commandLine.getUnprocessed().add("file3");
  -			fail("Should not be able to add to the list this way");
  -		} catch (UnsupportedOperationException uoe) {
  -            // nothing to check
  -		}
  -	}
  -
   	public void testNormalised() {
   		final Option option = new PropertyOption();
   		final List args = OptionTestCase.list();
  
  
  
  1.3       +5 -5      jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/GroupTest.java
  
  Index: GroupTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/GroupTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GroupTest.java	22 Oct 2003 16:32:14 -0000	1.2
  +++ GroupTest.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -143,7 +143,7 @@
   		final List args = list("compile,test", "dist");
   		final ListIterator iterator = args.listIterator();
   		final CommandLine commandLine = commandLine(option, args);
  -		option.processArguments(commandLine, iterator);
  +		option.process(commandLine, iterator);
   
   		assertFalse(iterator.hasNext());
   		assertTrue(commandLine.hasOption("target"));
  @@ -159,7 +159,7 @@
   		final List args = list("-?", "-k");
   		final ListIterator iterator = args.listIterator();
   		final CommandLine commandLine = commandLine(option, args);
  -		option.processOptions(commandLine, iterator);
  +		option.process(commandLine, iterator);
   
   		assertFalse(iterator.hasNext());
   		assertTrue(commandLine.hasOption("--help"));
  
  
  
  1.3       +3 -7      jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ApplicationTest.java
  
  Index: ApplicationTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ApplicationTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ApplicationTest.java	20 Oct 2003 21:28:18 -0000	1.2
  +++ ApplicationTest.java	24 Oct 2003 18:49:48 -0000	1.3
  @@ -251,10 +251,6 @@
   		assertEquals("mybuild.xml", line.getValue("-buildfile"));
   		assertTrue(line.hasOption("-projecthelp"));
   		assertFalse(line.hasOption("-help"));
  -
  -		// check targets
  -		final List unprocessed = line.getUnprocessed();
  -		assertTrue(unprocessed.isEmpty());
   	}
   
   	public void testCVS() throws OptionException {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message