commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli AllTest.java
Date Thu, 06 Jun 2002 09:37:27 GMT
jstrachan    2002/06/06 02:37:26

  Modified:    cli/src/java/org/apache/commons/cli
                        MissingArgumentException.java CommandLine.java
                        Option.java ParseException.java
                        AlreadySelectedException.java
                        UnrecognizedOptionException.java OptionGroup.java
                        MissingOptionException.java Options.java
               cli      .cvsignore project.xml project.properties
  Removed:     cli/src/test/org/apache/commons/cli AllTest.java
  Log:
  Applied John Keyes patches to tidy up the source code and remove some sourcecheck errors.
  Also turned off a few non-essential style checking properties such as brace formatting.
  
  Also removed the redundant AllTest.java which is no longer required. 
  Patched project.xml to properly find all the unit test cases
  
  Revision  Changes    Path
  1.2       +58 -7     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingArgumentException.java
  
  Index: MissingArgumentException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingArgumentException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MissingArgumentException.java	19 Dec 2001 18:16:25 -0000	1.1
  +++ MissingArgumentException.java	6 Jun 2002 09:37:26 -0000	1.2
  @@ -1,11 +1,62 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingArgumentException.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: MissingArgumentException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -14,7 +65,7 @@
    * is not provided with an argument.</p>
    *
    * @author bob mcwhirter (bob @ werken.com)
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class MissingArgumentException extends ParseException {
       
  
  
  
  1.3       +109 -25   jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/CommandLine.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommandLine.java	17 May 2002 11:44:32 -0000	1.2
  +++ CommandLine.java	6 Jun 2002 09:37:26 -0000	1.3
  @@ -1,18 +1,67 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/CommandLine.java,v 1.3 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: CommandLine.java,v 1.2 2002/05/17 11:44:32 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
   
   import java.util.List;
  -
  -import java.util.List;
   import java.util.LinkedList;
   import java.util.Map;
   import java.util.HashMap;
  @@ -29,14 +78,20 @@
    *
    * @author bob mcwhirter (bob @ werken.com)
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   
  -public class CommandLine{
  -    
  -    private List _args    = new LinkedList();
  -    private Map  _options = new HashMap();
  +public class CommandLine {
       
  +    /** the unrecognised options/arguments */
  +    private List args    = new LinkedList();
  +
  +    /** the recognised options/arguments */
  +    private Map  options = new HashMap();
  +
  +    /**
  +     * <p>Creates a command line.</p>
  +     */
       CommandLine() {
       }
       
  @@ -46,7 +101,7 @@
        * @return true if set, false if not
        */
       public boolean hasOption(char opt) {
  -        return _options.containsKey( new Character(opt) );
  +        return options.containsKey( new Character(opt) );
       }
       
       /** <p>Retrieve the argument, if any,  of an option.</p>
  @@ -55,12 +110,17 @@
        * @return Value of the argument if option is set, and has an argument, else null.
        */
       public String getOptionValue(char opt) {
  -        String[] result = (String[])_options.get( new Character(opt) );
  +        String[] result = (String[])options.get( new Character(opt) );
           return result == null ? null : result[0];
       }
   
  +    /** <p>Retrieves the array of values, if any, of an option.</p>
  +     *
  +     * @param opt Single-character name of the option
  +     * @return An array of values if the option is set, and has an argument, else null.
  +     */
       public String[] getOptionValues(char opt) {
  -        String[] result = (String[])_options.get( new Character(opt) );
  +        String[] result = (String[])options.get( new Character(opt) );
           return result == null ? null : result;
       }
       
  @@ -80,8 +140,8 @@
        * @return an array of remaining items passed in but not parsed
        */
       public String[] getArgs() {
  -        String[] answer = new String[ _args.size() ];
  -        _args.toArray( answer );
  +        String[] answer = new String[ args.size() ];
  +        args.toArray( answer );
           return answer;
       }
       
  @@ -90,7 +150,7 @@
        * @return List of remaining items passed in but not parsed
        */
       public List getArgList() {
  -        return _args;
  +        return args;
       }
       
       /** <p>Dump state, suitable for debugging.</p>
  @@ -101,28 +161,52 @@
           StringBuffer buf = new StringBuffer();
           
           buf.append( "[ CommandLine: [ options: " );
  -        buf.append( _options.toString() );
  +        buf.append( options.toString() );
           buf.append( " ] [ args: ");
  -        buf.append( _args.toString() );
  +        buf.append( args.toString() );
           buf.append( " ] ]" );
           
           return buf.toString();
       }
       
  +    /**
  +     * <p>Add left-over unrecognized option/argument.</p>
  +     *
  +     * @param arg the unrecognised option/argument.
  +     */
       void addArg(String arg) {
  -        _args.add( arg );
  +        args.add( arg );
       }
       
  +    /**
  +     * <p>Add an option that does not have any value to the 
  +     * command line.</p>
  +     *
  +     * @param opt the processed option
  +     */
       void setOpt(char opt) {
  -        _options.put( new Character(opt), null );
  +        options.put( new Character(opt), null );
       }
       
  +    /**
  +     * <p>Add an option with the specified value to the 
  +     * command line.</p>
  +     *
  +     * @param opt the processed option
  +     * @param value the value of the option
  +     */
       void setOpt(char opt, String value) {
  -        _options.put( new Character(opt), value );
  +        options.put( new Character(opt), value );
       }
       
  +    /**
  +     * <p>Add an option to the command line.  The values of 
  +     * the option are stored.</p>
  +     *
  +     * @param opt the processed option
  +     */
       void setOpt(Option opt) {
  -        _options.put( new Character( opt.getOpt() ),
  +        options.put( new Character( opt.getOpt() ),
                         opt.getValues() );
       }
   }
  
  
  
  1.4       +135 -13   jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Option.java
  
  Index: Option.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Option.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Option.java	17 May 2002 11:44:32 -0000	1.3
  +++ Option.java	6 Jun 2002 09:37:26 -0000	1.4
  @@ -1,11 +1,72 @@
   /*
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Option.java,v 1.4 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
  + *
  + */
  +
  +/*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: Option.java,v 1.3 2002/05/17 11:44:32 jstrachan Exp $
  + * $Id: Option.java,v 1.4 2002/06/06 09:37:26 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -25,41 +86,89 @@
    *
    * @author bob mcwhirter (bob @ werken.com)
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   
   public class Option {
       
  -    private Character  _opt          = null;
  +    /** opt the single character representation of the option */
  +    private Character _opt          = null;
  +
  +    /** longOpt is the long representation of the option */
       private String     _longOpt      = null;
  +
  +    /** hasArg specifies whether this option has an associated argument */
       private boolean    _hasArg       = false;
  +
  +    /** description of the option */
       private String     _description  = null;
  +
  +    /** required specifies whether this option is required to be present */
       private boolean    _required     = false;
  +
  +    /** multipleArgs specifies whether this option has multiple argument values */
       private boolean    _multipleArgs = false;   
  -    private ArrayList  _values       = new ArrayList();
  +
  +    /** ?? */
  +    private ArrayList  values       = new ArrayList();
       
   
  +    /**
  +     * Creates an Option using the specified parameters.
  +     *
  +     * @param opt character representation of the option
  +     * @param hasArg specifies whether the Option takes an argument or not
  +     * @param description describes the function of the option
  +     */
       public Option(char opt, boolean hasArg, String description) {
           this(opt, null, hasArg, description, false, false);
       }
       
  +    /**
  +     * Creates an Option using the specified parameters.
  +     *
  +     * @param opt character representation of the option
  +     * @param longOpt the long representation of the option
  +     * @param hasArg specifies whether the Option takes an argument or not
  +     * @param description describes the function of the option
  +     */
       public Option(char opt, String longOpt, boolean hasArg, String description) {
           this(opt, longOpt, hasArg, description, false, false );
       }
   
  +    /**
  +     * Creates an Option using the specified parameters.
  +     *
  +     * @param opt character representation of the option
  +     * @param longOpt the long representation of the option
  +     * @param hasArg specifies whether the Option takes an argument or not
  +     * @param description describes the function of the option
  +     * @param required specifies whether the option is required or not
  +     */
       public Option(char opt, String longOpt, boolean hasArg, String description,
                     boolean required ) {
           this(opt, longOpt, hasArg, description, required, false );
       }
   
  +    /**
  +     * Creates an Option using the specified parameters.
  +     *
  +     * @param opt character representation of the option
  +     * @param longOpt the long representation of the option
  +     * @param hasArg specifies whether the Option takes an argument or not
  +     * @param description describes the function of the option
  +     * @param required specifies whether the option is required or not
  +     * @param multipleArgs specifies whether the option has multiple argument 
  +     * values
  +     */
       public Option(char opt, String longOpt, boolean hasArg, String description, 
                     boolean required, boolean multipleArgs ) {
  -        _opt          = new Character( opt );
  -        _longOpt      = longOpt;
  -        _hasArg       = hasArg;
  -        _description  = description;
  -        _required     = required;
  -        _multipleArgs = multipleArgs;
  +        this._opt          = new Character( opt );
  +        this._longOpt      = longOpt;
  +        this._hasArg       = hasArg;
  +        this._description  = description;
  +        this._required     = required;
  +        this._multipleArgs = multipleArgs;
       }
       
       /** <p>Retrieve the single-character name of this Option</p>
  @@ -150,15 +259,28 @@
           return buf.toString();
       }
   
  +    /**
  +     * Adds the specified value to this Option
  +     * 
  +     * @param value is a/the value of this Option
  +     */
       public void addValue( String value ) {
  -        _values.add( value );
  +        values.add( value );
       }
   
  +    /**
  +     * @return the value/first value of this Option or null if there are no
  +     * values
  +     */
       public String getValue() {
  -        return _values.size()==0 ? null : (String)_values.get( 0 );
  +        return values.size()==0 ? null : (String)values.get( 0 );
       }
   
  +    /**
  +     * @return the values of this Option or null if there are no
  +     * values
  +     */
       public String[] getValues() {
  -        return _values.size()==0 ? null : (String[])_values.toArray(new String[]{});
  +        return values.size()==0 ? null : (String[])values.toArray(new String[]{});
       }
   }
  
  
  
  1.2       +60 -8     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/ParseException.java
  
  Index: ParseException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/ParseException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParseException.java	19 Dec 2001 18:16:25 -0000	1.1
  +++ ParseException.java	6 Jun 2002 09:37:26 -0000	1.2
  @@ -1,11 +1,62 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/ParseException.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: ParseException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -13,9 +64,10 @@
   /** <p>Base for Exceptions thrown during parsing of a command-line<p>
    *
    * @author bob mcwhirter (bob @ werken.com)
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
  -public class ParseException extends Exception {
  +public class ParseException extends Exception 
  +{
       
       /** Construct a new Exception with a message
        *
  
  
  
  1.4       +62 -12    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/AlreadySelectedException.java
  
  Index: AlreadySelectedException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/AlreadySelectedException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AlreadySelectedException.java	17 May 2002 15:11:58 -0000	1.3
  +++ AlreadySelectedException.java	6 Jun 2002 09:37:26 -0000	1.4
  @@ -1,29 +1,79 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/AlreadySelectedException.java,v 1.4 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: AlreadySelectedException.java,v 1.3 2002/05/17 15:11:58 jstrachan Exp $
    */
  +
   package org.apache.commons.cli;
   
   /** <p>Exception thrown when more than one option in an option group
    * has been provided.</p>
    *
    * @author John Keyes (john @ integralsource.com)
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
  -class AlreadySelectedException extends ParseException
  -{
  +class AlreadySelectedException extends ParseException {
   
       /** Construct a new Exception with a message
        *
  -     * @param msg Explanation of the exception
  +     * @param message Explanation of the exception
        */
  -    public AlreadySelectedException( String message )
  -    {
  +    public AlreadySelectedException( String message ) {
           super( message );
       }
   }
  
  
  
  1.2       +58 -7     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/UnrecognizedOptionException.java
  
  Index: UnrecognizedOptionException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/UnrecognizedOptionException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnrecognizedOptionException.java	19 Dec 2001 18:16:25 -0000	1.1
  +++ UnrecognizedOptionException.java	6 Jun 2002 09:37:26 -0000	1.2
  @@ -1,11 +1,62 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/UnrecognizedOptionException.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: UnrecognizedOptionException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -15,7 +66,7 @@
    *
    *
    * @author bob mcwhiter (bob @ werken.com)
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class UnrecognizedOptionException extends ParseException {
       
  
  
  
  1.2       +83 -42    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/OptionGroup.java
  
  Index: OptionGroup.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/OptionGroup.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OptionGroup.java	23 Apr 2002 16:08:02 -0000	1.1
  +++ OptionGroup.java	6 Jun 2002 09:37:26 -0000	1.2
  @@ -1,42 +1,89 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/OptionGroup.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: OptionGroup.java,v 1.1 2002/04/23 16:08:02 jstrachan Exp $
    */
  +
   package org.apache.commons.cli;
   
  -import java.util.ArrayList;
   import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.List;
   
   /**
    * A group of mutually exclusive options.
    * @author John Keyes ( john at integralsource.com )
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
  -public class OptionGroup 
  -{
  -    /*
  -     * hold the options
  -     */
  +public class OptionGroup {
  +    /** hold the options */
       private HashMap optionMap = new HashMap();
   
  -    /*
  -     * the name of the selected option
  -     */
  +    /** the name of the selected option */
       private Option selected;
   
       /**
        * add <code>opt</code> to this group
  +     *
  +     * @param opt the option to add to this group
  +     * @return this option group with opt added
        */
  -    public OptionGroup addOption( Option opt )
  -    {
  +    public OptionGroup addOption(Option opt) {
           // key   - option name
           // value - the option
           optionMap.put( "-" + opt.getOpt(), opt );
  @@ -47,8 +94,7 @@
        * @return the names of the options in this group as a 
        * <code>Collection</code>
        */
  -    private Collection getNames( )
  -    {
  +    private Collection getNames() {
           // the key set is the collection of names
           return optionMap.keySet();
       }
  @@ -56,38 +102,35 @@
       /**
        * @return the options in this group as a <code>Collection</code>
        */
  -    public Collection getOptions( )
  -    {
  +    public Collection getOptions() {
           // the values are the collection of options
           return optionMap.values();
       }
   
       /**
        * set the selected option of this group to <code>name</code>.
  -     * @param name the name of the option that is selected
  -     * @throws AlreadySelectedException
  +     * @param opt the option that is selected
  +     * @throws AlreadySelectedException if an option from this group has 
  +     * already been selected.
        */
  -    public void setSelected( Option opt )
  -    throws AlreadySelectedException
  -    {
  +    public void setSelected(Option opt) throws AlreadySelectedException {
           // if no option has already been selected or the 
           // same option is being reselected then set the
           // selected member variable
  -        if ( this.selected == null || this.selected.equals( opt ) )
  -        {
  +        if ( this.selected == null || this.selected.equals( opt ) ) {
               this.selected = opt;
           }
  -        else
  -        {
  -            throw new AlreadySelectedException( "an option from this group has already been selected: '" + selected + "'");
  +        else {
  +            throw new AlreadySelectedException( "an option from this group has " + 
  +                                                "already been selected: '" + 
  +                                                selected + "'");
           }
       }
   
       /**
        * @return the selected option name
        */
  -    public Option getSelected( )
  -    {
  +    public Option getSelected() {
           return selected;
       }
   
  @@ -133,17 +176,16 @@
       */
   
       /**
  -     * return the stringified representation of this group
  +     * <p>Returns the stringified version of this OptionGroup.</p>
  +     * @return the stringified representation of this group
        */
  -    public String toString()
  -    {
  +    public String toString() {
           StringBuffer buff = new StringBuffer();
   
           Iterator iter = getOptions().iterator();
   
           buff.append( "[" );
  -        while( iter.hasNext() )
  -        {
  +        while( iter.hasNext() ) {
               Option option = (Option)iter.next();
   
               buff.append( "-" );
  @@ -151,8 +193,7 @@
               buff.append( " " );
               buff.append( option.getDescription( ) );
   
  -            if( iter.hasNext() )
  -            {
  +            if( iter.hasNext() ) {
                   buff.append( ", " );
               }
           }
  
  
  
  1.2       +57 -6     jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingOptionException.java
  
  Index: MissingOptionException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingOptionException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MissingOptionException.java	23 Apr 2002 16:08:02 -0000	1.1
  +++ MissingOptionException.java	6 Jun 2002 09:37:26 -0000	1.2
  @@ -1,11 +1,62 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingOptionException.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: MissingOptionException.java,v 1.1 2002/04/23 16:08:02 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -14,7 +65,7 @@
    * is not provided with an argument.</p>
    *
    * @author bob mcwhirter (bob @ werken.com)
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class MissingOptionException extends ParseException {
       
  
  
  
  1.4       +219 -77   jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Options.java
  
  Index: Options.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Options.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Options.java	17 May 2002 11:44:32 -0000	1.3
  +++ Options.java	6 Jun 2002 09:37:26 -0000	1.4
  @@ -1,11 +1,62 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Options.java,v 1.4 2002/06/06 09:37:26 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/06/06 09:37:26 $
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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 Group.
  + *
  + * 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/>.
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - * 
  - * $Id: Options.java,v 1.3 2002/05/17 11:44:32 jstrachan Exp $
    */
   
   package org.apache.commons.cli;
  @@ -16,7 +67,6 @@
   import java.util.List;
   import java.util.ListIterator;
   import java.util.ArrayList;
  -import java.util.Arrays;
   import java.util.LinkedList;
   import java.util.Iterator;
   import java.util.Collections;
  @@ -34,31 +84,45 @@
    *
    * @author bob mcwhirter (bob @ werken.com)
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class Options {
       
  -    private List _options      = new ArrayList();
  -    private Map  _shortOpts    = new HashMap();
  -    private Map  _longOpts     = new HashMap();
  -    private Map  _requiredOpts = new HashMap();
  +    /** the list of options */
  +    private List options      = new ArrayList();
  +
  +    /** a map of the options with the character key */
  +    private Map  shortOpts    = new HashMap();
  +
  +    /** a map of the options with the long key */
  +    private Map  longOpts     = new HashMap();
  +
  +    /** a map of the required options */
  +    private Map  requiredOpts = new HashMap();
       
  -    private Map _optionGroups  = new HashMap();
  +    /** a map of the option groups */
  +    private Map optionGroups  = new HashMap();
   
       /** <p>Construct a new Options descriptor</p>
        */
       public Options() {        
       }
   
  -    public Options addOptionGroup( OptionGroup group )
  -    {
  +    /**
  +     * <p>Add the specified option group.</p>
  +     *
  +     * @param group the OptionGroup that is to be added
  +     * @return the resulting Options instance
  +     */
  +    public Options addOptionGroup( OptionGroup group ) {
           Iterator options = group.getOptions().iterator();
  -        while( options.hasNext() )
  -        {
  +
  +        while( options.hasNext() ) {
               Option option = (Option)options.next();
               addOption( option );
  -            _optionGroups.put( option, group );
  +            optionGroups.put( option, group );
           }
  +
           return this;
       }
   
  @@ -68,6 +132,7 @@
        * @param opt Short single-character name of the option.
        * @param hasArg flag signally if an argument is required after this option
        * @param description Self-documenting description
  +     * @return the resulting Options instance
        */
       public Options addOption(char opt, boolean hasArg, String description) {
           addOption( opt, null, hasArg, description, false );
  @@ -78,8 +143,10 @@
        * <p>It may be specified as requiring an argument.</p>
        *
        * @param opt Short single-character name of the option.
  +     * @param longOpt Long multi-character name of the option.
        * @param hasArg flag signally if an argument is required after this option
        * @param description Self-documenting description
  +     * @return the resulting Options instance
        */
       public Options addOption(char opt, String longOpt, boolean hasArg, String description) {
           addOption( opt, longOpt, hasArg, description, false );        
  @@ -90,8 +157,11 @@
        * <p>It may be specified as requiring an argument.</p>
        *
        * @param opt Short single-character name of the option.
  +     * @param longOpt Long multi-character name of the option.
        * @param hasArg flag signally if an argument is required after this option
        * @param description Self-documenting description
  +     * @param required specifies if this option is required
  +     * @return the resulting Options instance
        */
       public Options addOption(char opt, String longOpt, boolean hasArg, String description,
                                boolean required) {
  @@ -99,6 +169,17 @@
           return this;
       }
   
  +    /** <p>Add an option that contains a short-name and a long-name</p>
  +     * <p>It may be specified as requiring an argument.</p>
  +     *
  +     * @param opt Short single-character name of the option.
  +     * @param longOpt Long multi-character name of the option.
  +     * @param hasArg flag signally if an argument is required after this option
  +     * @param description Self-documenting description
  +     * @param required specifies if this option is required
  +     * @param multipleArgs specifies if this option can accept multiple argument values
  +     * @return the resulting Options instance
  +     */
       public Options addOption(char opt, String longOpt, boolean hasArg, String description,
                                boolean required, boolean multipleArgs) {
           addOption( new Option(opt, longOpt, hasArg, description, required, multipleArgs) );        
  @@ -109,10 +190,16 @@
        *
        * @param args Args to parse
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
        */
       public CommandLine parse(String[] args) 
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           return parse( args, 0, args.length, false);
       }
       
  @@ -137,10 +224,16 @@
        * @param args Args to parse
        * @param stopAtNonOption stop parsing at the first non-option token
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
        */
       public CommandLine parse(String[] args, boolean stopAtNonOption) 
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           return parse( args, 0, args.length, stopAtNonOption);
       }
       
  @@ -154,10 +247,16 @@
        * @param fromIndex index of args to start parsing
        * @param toIndex index of args to stop parsing
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
        */
       public CommandLine parse(String[] args, int fromIndex, int toIndex) 
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           return parse( args, fromIndex, toIndex, false );
       }
       
  @@ -188,10 +287,16 @@
        * @param toIndex index of args to stop parsing
        * @param stopAtNonOption stop parsing at the first non-option token
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  -     */
  -    public CommandLine parse(String[] args, int fromIndex, int toIndex, boolean stopAtNonOption) 
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
  +     */
  +    public CommandLine parse(String[] args, int fromIndex, int toIndex, boolean stopAtNonOption)
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           List argList = java.util.Arrays.asList( args );
           
           return parse( argList, stopAtNonOption);
  @@ -201,10 +306,16 @@
        *
        * @param args Args to parse
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
        */
       public CommandLine parse(List args)
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           return parse( args, false );
       }
       
  @@ -230,13 +341,19 @@
        * to <code>toIndex</code> exclusive, of the <code>args</code> parameter,
        * to allow parsing a specific portion of a command-line.<p>
        *
  -     * @param args Args to parse
  +     * @param inArgs Arguments to parse
        * @param stopAtNonOption stop parsing at the first non-option token
        *
  -     * @returns {@link CommandLine} containing information related to parse state
  +     * @return {@link CommandLine} containing information related to parse state
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws MissingOptionException if a required option is not present
  +     * @throws AlreadySelectedException if the same option appears more than once
        */
       public CommandLine parse(List inArgs, boolean stopAtNonOption) 
  -    throws MissingArgumentException, UnrecognizedOptionException, MissingOptionException, AlreadySelectedException {
  +    throws MissingArgumentException, UnrecognizedOptionException, 
  +        MissingOptionException, AlreadySelectedException {
           CommandLine cl = new CommandLine();
           
           List args = burst( inArgs, stopAtNonOption );
  @@ -256,7 +373,7 @@
                   eatTheRest = true;
               }
               else if ( eachArg.startsWith("--") ) {
  -                eachOpt = (Option) _longOpts.get( eachArg );
  +                eachOpt = (Option) longOpts.get( eachArg );
                   processOption( eachArg, eachOpt, argIter, cl );
               }
               else if ( eachArg.equals("-") ) {
  @@ -270,11 +387,10 @@
                   }
               }
               else if ( eachArg.startsWith("-") ) {
  -                eachOpt = (Option) _shortOpts.get( eachArg );
  +                eachOpt = (Option) shortOpts.get( eachArg );
                   processOption( eachArg, eachOpt, argIter, cl );
               }                
  -            else
  -            {
  +            else {
                   cl.addArg( eachArg );
                   if ( stopAtNonOption ) {
                       eatTheRest = true;
  @@ -294,21 +410,21 @@
   
           return cl;
       }
  -    
  -    private void checkRequiredOptions() 
  -    throws MissingOptionException
  -    {
  -        if( _requiredOpts.size() > 0 )
  -        {
  -            Set optKeys = _requiredOpts.keySet();
  +
  +    /**
  +     * @throws MissingOptionException if all of the required options are
  +     * not present.
  +     */
  +    private void checkRequiredOptions() throws MissingOptionException {
  +        if( requiredOpts.size() > 0 ) {
  +            Set optKeys = requiredOpts.keySet();
   
               Iterator iter = optKeys.iterator();
   
               StringBuffer buff = new StringBuffer();
   
  -            while( iter.hasNext() )
  -            {
  -                Option missing = (Option)_requiredOpts.get( iter.next() );
  +            while( iter.hasNext() ) {
  +                Option missing = (Option)requiredOpts.get( iter.next() );
                   buff.append( "-" );
                   buff.append( missing.getOpt() );
                   buff.append( " " );
  @@ -319,21 +435,37 @@
           }
       }
   
  -    private void processOption( String eachArg, Option option, ListIterator argIter, CommandLine cl )
  -    throws UnrecognizedOptionException, AlreadySelectedException, MissingArgumentException
  -    {
  +    /**
  +     * <p>processOption rakes the current option and checks if it is
  +     * an unrecognised option, whether the argument value is missing or
  +     * whether the option has already been selected.</p>
  +     *
  +     * @param eachArg the current option read from command line
  +     * @param option the current option corresponding to eachArg
  +     * @param argIter the argument iterator
  +     * @param cl the current command line
  +     *
  +     * @throws MissingArgumentException if an argument value for an option is not present
  +     * @throws UnrecognizedOptionException if an unrecognised option is present
  +     * @throws AlreadySelectedException if the same option appears more than once
  +     */
  +    private void processOption( String eachArg, Option option, ListIterator argIter, 
  +                                CommandLine cl)
  +    throws UnrecognizedOptionException, AlreadySelectedException, 
  +        MissingArgumentException {
  +
           if ( option == null ) {
               throw new UnrecognizedOptionException("Unrecognized option: " + eachArg);
           }
           else {
   
  -            if ( _optionGroups.get( option ) != null ) {
  -                ( (OptionGroup)( _optionGroups.get( option ) ) ).setSelected( option );
  +            if ( optionGroups.get( option ) != null ) {
  +                ( (OptionGroup)( optionGroups.get( option ) ) ).setSelected( option );
               }
   
               // if required remove from list
               if ( option.isRequired() ) {
  -                _requiredOpts.remove( "-" + option.getOpt() );
  +                requiredOpts.remove( "-" + option.getOpt() );
               }
   
               if ( option.hasArg() ) {
  @@ -341,30 +473,24 @@
                       eachArg = (String) argIter.next();
                       option.addValue( eachArg );
                       
  -                    if( option.hasMultipleArgs() )
  -                    {
  -                        while( argIter.hasNext() )
  -                        {
  +                    if( option.hasMultipleArgs() ) {
  +                        while( argIter.hasNext() ) {
                               eachArg = (String)argIter.next();
  -                            if( eachArg.startsWith("-") )
  -                            {
  +                            if( eachArg.startsWith("-") ) {
                                   argIter.previous();
                                   cl.setOpt( option );
                                   break;
                               }
  -                            else
  -                            {
  +                            else {
                                   option.addValue( eachArg );
                               }
                           }
                       }
  -                    else
  -                    {
  +                    else {
                           cl.setOpt( option );
                           return;
                       }
  -                    if( !argIter.hasNext() )
  -                    {
  +                    if( !argIter.hasNext() ) {
                           cl.setOpt( option );
                       }
                   }
  @@ -380,6 +506,15 @@
           }
       }
   
  +    /**
  +     * <p>Processes the argument list according to POSIX command line
  +     * processing rules.</p>
  +     *
  +     * @param inArgs the argument list
  +     * @param stopAtNonOption stop processing when the first non option
  +     * is encountered.
  +     * @return the processed list of arguments.
  +     */
       private List burst(List inArgs, boolean stopAtNonOption) {
           List args = new LinkedList();
           
  @@ -433,7 +568,7 @@
                       
                       for ( int i = 1 ; i < eachArg.length() ; ++i ) {
                           String optStr = "-" + eachArg.charAt(i);
  -                        Option opt    = (Option) _shortOpts.get( optStr );
  +                        Option opt    = (Option) shortOpts.get( optStr );
                           
                           if ( (opt != null) && (opt.hasArg()) ) {
                               // If the current option has an argument,
  @@ -479,44 +614,51 @@
           return args;
       }
       
  +    /**
  +     * <p>Adds the option to the necessary member lists</p>
  +     *
  +     * @param opt the option that is to be added 
  +     */
       private void addOption(Option opt)  {
           String shortOptStr = "-" + opt.getOpt();
           
           if ( opt.hasLongOpt() ) {
  -            _longOpts.put( "--" + opt.getLongOpt(), opt );
  +            longOpts.put( "--" + opt.getLongOpt(), opt );
           }
           
           if ( opt.isRequired() ) {
  -            _requiredOpts.put( "-" + opt.getOpt(), opt );
  +            requiredOpts.put( "-" + opt.getOpt(), opt );
           }
   
  -        _shortOpts.put( "-" + opt.getOpt(), opt );
  +        shortOpts.put( "-" + opt.getOpt(), opt );
           
  -        _options.add( opt );
  +        options.add( opt );
       }
       
       /** <p>Retrieve a read-only list of options in this set</p>
        *
  -     * @returns read-only List of {@link Option} objects in this descriptor
  +     * @return read-only List of {@link Option} objects in this descriptor
        */
       public List getOptions() {
  -        return Collections.unmodifiableList(_options);
  +        return Collections.unmodifiableList(options);
       }
       
       /** <p>Retrieve the named {@link Option}<p>
        *
        * @param opt short single-character name of the {@link Option}
  +     * @return the option represented by opt
        */
       public Option getOption(char opt) {
  -        return (Option) _shortOpts.get( "-" + opt );
  +        return (Option) shortOpts.get( "-" + opt );
       }
       
       /** <p>Retrieve the named {@link Option}<p>
        *
  -     * @param opt long name of the {@link Option}
  +     * @param longOpt long name of the {@link Option}
  +     * @return the option represented by longOpt
        */
       public Option getOption(String longOpt) {
  -        return (Option) _longOpts.get( longOpt );
  +        return (Option) longOpts.get( longOpt );
       }
       
       /** <p>Dump state, suitable for debugging.</p>
  @@ -527,9 +669,9 @@
           StringBuffer buf = new StringBuffer();
           
           buf.append("[ Options: [ short ");
  -        buf.append( _shortOpts.toString() );
  +        buf.append( shortOpts.toString() );
           buf.append( " ] [ long " );
  -        buf.append( _longOpts );
  +        buf.append( longOpts );
           buf.append( " ]");
           
           return buf.toString();
  
  
  
  1.3       +1 -0      jakarta-commons-sandbox/cli/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/.cvsignore,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- .cvsignore	22 May 2002 17:45:55 -0000	1.2
  +++ .cvsignore	6 Jun 2002 09:37:26 -0000	1.3
  @@ -4,3 +4,4 @@
   velocity.log
   .project
   
  +maven.log
  
  
  
  1.4       +1 -1      jakarta-commons-sandbox/cli/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/project.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.xml	2 Jun 2002 18:15:24 -0000	1.3
  +++ project.xml	6 Jun 2002 09:37:26 -0000	1.4
  @@ -75,7 +75,7 @@
       <!-- Unit test classes -->
   
       <unitTestPatterns>
  -      <unitTestPattern>include = **/Test*.java</unitTestPattern>
  +      <unitTestPattern>include = **/*Test*.java</unitTestPattern>
       </unitTestPatterns>
   
       <!-- Integration unit test classes -->
  
  
  
  1.2       +7 -6      jakarta-commons-sandbox/cli/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/project.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- project.properties	22 May 2002 23:07:29 -0000	1.1
  +++ project.properties	6 Jun 2002 09:37:26 -0000	1.2
  @@ -8,15 +8,16 @@
   
   maven.jarResources.basedir=${basedir}/src/java
    
  +# coding standards
   
  -# use Sun coding standards
  -
  -maven.checkstyle.lcurly.type = eol
  -maven.checkstyle.lcurly.method = eol
  -maven.checkstyle.lcurly.other = eol
  +maven.checkstyle.lcurly.type = ignore
  +maven.checkstyle.lcurly.method = ignore
  +maven.checkstyle.lcurly.other = ignore
   maven.checkstyle.header.file = LICENSE.txt
  -maven.checkstyle.header.ignore.line = 1,2,3,4,5,6
  +maven.checkstyle.header.ignore.line = 1,2,3,4
   maven.checkstyle.const.pattern = ^[a-z][a-zA-Z0-9]*$
  +maven.checkstyle.member.pattern = ^[_]*[a-z][a-zA-Z0-9]*$
  +maven.checkstyle.javadoc.scope = protected
   
   # disable these non-critical errors to highlight
   # more important ones like missing javadoc
  
  
  

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


Mime
View raw message