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/messenger TODO.txt build.xml
Date Wed, 19 Dec 2001 18:16:26 GMT
jstrachan    01/12/19 10:16:25

  Modified:    messenger TODO.txt build.xml
  Added:       cli      PROPOSAL.html README.txt STATUS.html TODO.txt
                        build.properties build.properties.sample build.xml
               cli/src/conf MANIFEST.MF
               cli/src/java/org/apache/commons/cli CommandLine.java
                        MissingArgumentException.java Option.java
                        Options.java ParseException.java
                        UnrecognizedOptionException.java overview.html
                        package.html
               cli/src/test/org/apache/commons/cli AllTest.java
                        BuildTest.java ParseTest.java ValueTest.java
  Log:
  Added initial version of CLI - a command line options tool. Its based on a combination of werken.opt and CLI from the Avalon framework. I've used werken.opt's source code with Bob's permission
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/cli/PROPOSAL.html
  
  Index: PROPOSAL.html
  ===================================================================
  <html>
  <head>
  <title>Proposal for CLI Package</title>
  </head>
  <body bgcolor="white">
  
  <div align="center">
  <h1>Proposal for <em>CLI</em> Package</h1>
  </div>
  
  <h3>(0) Rationale</h3>
  <p>
  <p>The <em>CLI</em> package provides a simple library
  for working with command line arguments. It provides similar
  features to the Unix getopt() feature.
  </p>
  
  <h3>(1) Scope of the Package</h3>
  <p>
     The package will create and maintain a number of classes for
     working with the command line and to be distributed under the ASF license.
  </p>
  
  <h3>(1.5) Interaction With Other Packages</h3>
  
  <p><em>CLI</em> relies on standard JDK 1.2 (or later) APIs.
  </p>
  
  <p>In addition JUnit is used as the testing framework.</p>
  
  <h3>(2) Initial Source of the Package</h3>
  
  <p>
     The source code is based on werken.opt 
     <a href="http://sourceforge.net/projects/werken-opt/">here</a>.
  </p>
  
  <p>
     The code is also influenced by the CLI package in Avalon Excalibur.
  </p>
  
  <p>The proposed package name for the new component is
  <code>org.apache.commons.cli</code>.</p>
  
  
  <h3>(3)  Required Jakarta-Commons Resources</h3>
  
  <ul>
  <li>CVS Repository - New directory <code>cli</code> in the
      <code>jakarta-commons</code> CVS repository.  All initial committers
      are already committers on <code>jakarta-commons</code>, so no
      additional user setups are required.</li>
  <li>Mailing List - Discussions will take place on the general
      <em>commons-dev@jakarta.apache.org</em> mailing list.  To help
      list subscribers identify messages of interest, it is suggested that
      the message subject of messages about this component be prefixed with
      [CLI].</li>
  <li>Bugzilla - New component "CLI" under the "Commons" product
      category, with appropriate version identifiers as needed.</li>
  <li>Jyve FAQ - New category "commons-cli" (when available).
  </ul>
  
  
  <h3>(4) Initial Committers</h3>
  <ul>
     <li>bob mcwhirter</li>
     <li>James Strachan</li>
  </ul>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/cli/README.txt
  
  Index: README.txt
  ===================================================================
  Jakarta Commons Cli
  ===================
  
  Welcome to the Cli component of the Jakarta Commons
  project.
  
  This component requires the excellent Ant utility.  It can 
  be found here :
  
    http://jakarta.apache.org/ant/
  
  For testing the project, you will also need JUnit :
  
    http://www.junit.org/
  
  To let the test process find JUnit, you may make a 
  copy of the build.properties.sample file, rename to
  build.properties,  and modify to reflect
  the location of the junit.jar on your computer.
  
  Once you have Ant propertly installed, and the
  build.properties file correctly reflects the location
  of your junit.jar, you are ready to build and test.
  
  To compile and test the component :
  
  $ ant test
  
  To build a jar :
  
  $ ant dist-jar
  
  To build the API documentation :
  
  $ ant doc
  
  To build the jar and API doc at once :
  
  $ ant dist
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/cli/STATUS.html
  
  Index: STATUS.html
  ===================================================================
  <html>
  <head>
  <title>Status File for Jakarta Commons "CLI" Package</title>
  <head>
  <body bgcolor="white">
  
  
  <div align="center">
  <h1>The Jakarta Commons <em>CLI</em> Package</h1>
  $Id: STATUS.html,v 1.1 2001/12/19 18:16:25 jstrachan Exp $<br>
  <a href="#Introduction">[Introduction]</a>
  <a href="#Dependencies">[Dependencies]</a>
  <a href="#Release Info">[Release Info]</a>
  <a href="#Committers">[Committers]</a>
  <a href="#Action Items">[Action Items]</a>
  <br><br>
  </div>
  
  
  <a name="Introduction"></a>
  <h3>1.  INTRODUCTION</h3>
  
  <p>The <em>CLI</em> package provides a simple library
  for working with command line arguments. It provides similar
  features to the Unix getopt() feature.
  </p>
  <p>
  The following classes are included:</p>
  <ul>
  <li><strong>Options</strong> - provide a simple mechanism to setup a programs options with a parse() method to parse the command line arguments.</li>
  <li><strong>CommandLine</strong> - the command line arguments after parsing.</li>
  </ul>
  
  <a name="Dependencies"></a>
  <h3>2.  DEPENDENCIES</h3>
  
  <p>The <em>CLI</em> package is dependent upon the following external
  components for building:</p>
  <ul>
  <li><a href="http://java.sun.com/j2se">Java Development Kit</a>
      (Version 1.2 or later)</li>
  </ul>
  
  <p>The <em>CLI</em> package is dependent upon the following external
  components for unit tests only:</p>
  
  <ul>
  <li><a href="http://www.junit.org">JUnit Testing Framework</a>
      (Version 3.7 or later) - for unit tests only, not required
      for deployment</li>
  </ul>
  
  
  <a name="Release Info"></a>
  <h3>3.  RELEASE INFO</h3>
  
  <p>Current Release:
  <!--
  <a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-cli/v1.0">Version 1.0</a>
  -->
  
  <p>Planned Next Release:  TBD</p>
  
  <a name="Committers"></a>
  <h3>4.  COMMITTERS</h3>
  
  <p>The following individuals are the primary developers and maintainers of this
  component.  Developers who plan to use <em>CLI</em> in their own
  projects are encouraged to collaborate on the future development of this
  component to ensure that it continues to meet a variety of needs.</p>
  <ul>
     <li><a href="mailto:bob@werken.com">bob mcwhirter</a></li>
     <li><a href="mailto:jstrachan@apache.org">James Strachan</a></li>
  </ul>
  
  <a name="Action Items"></a>
  <h3>5.  ACTION ITEMS</h3>
  
  <p>Want to help?  Here's some "to do" items the team has identified.</p>
  
  <table border="1">
    <tr>
      <th width="80%">Action Item</th>
      <th width="20%">Volunteer</th>
    </tr>
  
    <tr>
      <td><strong>Additional Documentation</strong>.  Create simple
          User's Guide, examples, or other documentation for this package.</td>
      <td align="center">&nbsp;</td>
    </tr>
  </table>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/cli/TODO.txt
  
  Index: TODO.txt
  ===================================================================
  Project To Do List
  ==================
  
  * provide a helper method to output the usage of a program
    displaying all the options, whether they take a value etc.
  
  * provide simple mechanism for mandatory options?
    
  
  
  
  1.1                  jakarta-commons-sandbox/cli/build.properties
  
  Index: build.properties
  ===================================================================
  #
  # Compile-time dependencies
  #
  
  #
  # Runtime dependencies
  #
  
  # junit.jar - JUnit 3.2+ Classpath
  junit.jar=/dom4j/dom4j/lib/junit.jar
  
  
  
  1.1                  jakarta-commons-sandbox/cli/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  #
  # Compile-time dependencies
  #
  
  
  #
  # Runtime dependencies
  #
  
  # junit.jar - JUnit 3.2+ Classpath
  junit.jar=/java/junit/junit.jar
  
  
  
  
  1.1                  jakarta-commons-sandbox/cli/build.xml
  
  Index: build.xml
  ===================================================================
  <!-- $Id: build.xml,v 1.1 2001/12/19 18:16:25 jstrachan Exp $ -->
  <project name="messenger" default="test" basedir=".">
  
     <!-- patternset describing files to be copied from the doc directory -->
     <patternset id="patternset-doc"/>
  
     <!-- patternset describing test classes -->
     <patternset id="patternset-test-classes">
        <include name="**/Test*.class"/>
     </patternset>
  
     <!-- patternset describing non test classes -->
     <patternset id="patternset-non-test-classes">
        <include name="**/*.class"/>
        <exclude name="**/Test*.class"/>
     </patternset>
  
     <!-- patternset describing non test source files (*.java, *html, etc.) -->
     <patternset id="patternset-javadocable-sources">
        <include name="**/*"/>
        <exclude name="**/Test*.java"/>
     </patternset>
  
     <!-- patternset describing config files -->
     <patternset id="patternset-config-files">
        <include name="**/*.xml"/>
     </patternset>
  
     <!-- ######################################################### -->
  
     <target name="init">
        <tstamp/>
  
        <!-- read properties from the build.properties, if any -->
        <property name="component-propfile" value="${basedir}/build.properties"/>
        <property file="${component-propfile}"/>
  
        <!-- read properties from the commons build.properties, if any -->
        <property name="commons-propfile" value="${basedir}/../build.properties"/>
        <property file="${commons-propfile}"/>
  
        <!-- read properties from the ${user.home}/propfile, if any -->
        <property name="user-propfile" value="${user.home}/build.properties"/>
        <property file="${user-propfile}"/>
  
  
        <!-- command line classpath, if any -->
        <property name="cp" value=""/>
  
        <property name="name" value="cli"/>
        <property name="Name" value="Commons CLI"/>
        <property name="Name-Long" value="Jakarta Commons CLI Package"/>
        <property name="version" value="1.0"/>
        <property name="quality" value="beta"/>
  
        <!-- The current version number of this component -->
        <property name="component.version"       value="${version}-${quality}"/>
  
        <property name="test.entry" value="org.apache.commons.cli.AllTest"/>
        <property name="test.failonerror" value="true" />
        <property name="test.runner" value="junit.textui.TestRunner" />
  
        <property name="workdir" value="${java.io.tmpdir}/buildtemp_${DSTAMP}${TSTAMP}"/>
  
        <property name="source" value="${basedir}"/>
        <property name="source.src" value="${basedir}/src"/>
        <property name="source.src.conf" value="${source.src}/conf"/>
        <property name="source.src.java" value="${source.src}/java"/>
        <property name="source.src.test" value="${source.src}/test"/>
        <property name="source.doc" value="${basedir}/doc"/>
        <property name="dest" value="${basedir}/dist"/>
        <property name="dest.classes" value="${dest}/classes"/>
        <property name="dest.doc" value="${dest}/doc"/>
        <property name="dest.doc.api" value="${dest.doc}/api"/>
        <property name="dest.jardir" value="${dest}"/>
        <property name="dest.jardir.jar" value="${dest.jardir}/commons-${name}.jar"/>
        <property name="javadoc-website-dir" value="../../jakarta-commons/docs/${name}/api"/>
        <property name="build.webapp" value="${webapp.dir}/web/WEB-INF"/>
  
        <available property="available-doc" file="${source.doc}"/> <!-- does this module have docs? -->
        <available property="available-src-java" file="${source.src.java}"/> <!-- does this module have java src? -->
        <available property="available-src-test" file="${source.src.test}"/> <!-- does this module have test src? -->
  
  
        <!-- now combine the classpaths -->
        <property name="classpath" value="${cp}"/>
  
        <!-- classpath for unit tests -->
        <property name="test.classpath" value="${cp}:${junit.jar}"/>
  
     </target>
  
     <!-- ######################################################### -->
  
     <target name="clean" depends="clean-dist,clean-build,clean-doc" description="removes generated files">
        <delete dir="${dest}"/>
     </target>
  
     <target name="clean-doc" depends="init,clean-javadoc">
        <delete dir="${dest.doc}"/>
     </target>
  
     <target name="clean-javadoc" depends="init">
        <delete dir="${dest.doc.api}"/>
     </target>
  
     <target name="clean-build" depends="init">
        <delete dir="${dest.classes}"/>
        <delete dir="${build.webapp}"/>
     </target>
  
     <target name="clean-dist" depends="init">
        <delete file="${dest.jardir.jar}"/>
     </target>
  
     <!-- ######################################################### -->
  
     <target name="doc" depends="init,doc-top,doc-copy,doc-javadoc" description="generates javadocs and other documentation">
     </target>
  
     <target name="doc-top" depends="init">
        <mkdir  dir="${dest}"/>
        <copy todir="${dest}" file="../LICENSE"/>
     </target>
  
     <target name="doc-copy" depends="init" if="available-doc">
  <!--
        <mkdir dir="${dest.xdocs}"/>
        <copy todir="${dest.xdocs}">
          <fileset dir="${source.xdocs}">
            <patternset refid="patternset-doc"/>
          </fileset>
        </copy>
  -->
        <copy todir="${dest.doc}">
          <fileset dir="${source.doc}">
            <patternset refid="patternset-doc"/>
          </fileset>
        </copy>
     </target>
  
  <!--
     <target name="doc-html" depends="init" if="available-doc">
      <style    
        basedir="${source.xdocs}" 
        destdir="${source.doc}" 
        style="site.xsl"
        includes="**/*.xml"
        excludes="project.xml"/>
     </target>
  -->
  
     <target name="doc-javadoc" depends="init" if="available-src-java">
        <!-- copy all the non-test sources out to the work directory and javadoc that -->
        <mkdir dir="${workdir}"/>
        <copy todir="${workdir}">
          <fileset dir="${source.src.java}">
            <patternset refid="patternset-javadocable-sources"/>
          </fileset>
        </copy>
        <replace dir="${workdir}" includes="**"
                 token="##VERSION##" value="${version}"/>
        <replace dir="${workdir}" includes="**"
                 token="##QUALITY##" value="${quality}"/>
        <mkdir dir="${dest.doc.api}"/>
        <javadoc packagenames="org.*"
                 sourcepath="${workdir}"
                 destdir="${dest.doc.api}"
                 windowtitle="${Name-Long}"
                 doctitle="${Name-Long}"
                 bottom="&lt;small&gt;Copyright &amp;copy; 2001 Apache Software Foundation. Documenation generated ${TODAY}&lt;/small&gt;."
                 protected="true"
                 version="true"
                 author="true"
                 splitindex="false"
                 nodeprecated="true"
                 nodeprecatedlist="true"
                 notree="true"
                 noindex="false"
                 nohelp="true"
                 nonavbar="false"
                 serialwarn="false">
            <link href="http://java.sun.com/j2se/1.3/docs/api"/>
        </javadoc>
        <delete dir="${workdir}"/>
     </target>
  
     <!-- Updates the JavaDoc in the jakarta-commons/docs area -->
     <target name="website" depends="doc-javadoc" if="available-src-java">
        <copy todir="${javadoc-website-dir}" filtering="no">
           <fileset dir="${dest.doc.api}"/>
        </copy>
     </target>
  
     <!-- ######################################################### -->
  
     <target name="build" depends="init,build-java" description="compiles source files"/>
  
     <target name="build-java" depends="init" if="available-src-java">
        <mkdir dir="${dest.classes}"/>
        <javac destdir="${dest.classes}"
               srcdir="${source.src.java}"
               classpath="${classpath}"
               debug="false"
               deprecation="false"
               optimize="true"/>
     </target>
  
     <target name="build-test" depends="init,build-java" if="available-src-test">
        <mkdir dir="${dest.classes}"/>
        <javac destdir="${dest.classes}"
               srcdir="${source.src.test}"
               classpath="${test.classpath}"
               debug="false"
               deprecation="true"
               optimize="true"/>
  
        <copy todir="${dest.classes}" filtering="no">
           <fileset dir="${source.src.conf}">
              <patternset refid="patternset-config-files"/>
           </fileset>
        </copy>
     </target>
  
     <!-- ######################################################### -->
  
     <!-- ######################################################### -->
  
     <target name="test" depends="build-test" if="test.entry" description="runs (junit) unit tests">
        <!--
        <junit printsummary="yes" fork="on" haltonfailure="yes">
        	<formatter type="plain" usefile="false"/>
        	<test name="${test.entry}"/>
        	<classpath>
            <pathelement location="${dest.classes}" />
            <pathelement path="${classpath}" />
            <pathelement path="${java.class.path}" />
        	</classpath>
        </junit>
        -->
  
        <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
          <classpath>
            <pathelement location="${dest.classes}" />
            <pathelement path="${test.classpath}"/>
            <pathelement path="${java.class.path}" />
          </classpath>
  
          <arg value="${test.entry}"/>
        </java>
     </target>
  
     <!-- ######################################################### -->
  
     <target name="dist" depends="dist-jar,doc" description="builds binary distribution"/>
  
     <target name="dist-jar" depends="build">
        <mkdir dir="${dest.jardir}"/>
        <mkdir dir="${workdir}"/>
        <copy todir="${workdir}">
           <fileset dir="${dest.classes}">
              <patternset refid="patternset-non-test-classes"/>
           </fileset>
        </copy>
        <jar jarfile="${dest.jardir.jar}" manifest="${source.src}/conf/MANIFEST.MF">
           <fileset dir="${workdir}"/>
        </jar>
        <delete dir="${workdir}"/>
        <delete dir="${dest.classes}"/>
     </target>
  
     <!-- ######################################################### -->
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/conf/MANIFEST.MF
  
  Index: MANIFEST.MF
  ===================================================================
  Extension-Name: org.apache.commons.cli
  Specification-Vendor: Apache Software Foundation
  Specification-Version: 1.0
  Implementation-Vendor: Apache Software Foundation
  Implementation-Version: 1.0-dev
  
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  /*
   * 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: CommandLine.java,v 1.1 2001/12/19 18:16:25 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;
  
  /** <p>Represents list of arguments parsed against
   * a {@link Options} descriptor.<p>
   *
   * <p>It allows querying of a boolean {@link #hasOption(char opt)},
   * in addition to retrieving the {@link #getOptionValue(char opt)}
   * for options requiring arguments.</p>
   *
   * <p>Additionally, any left-over or unrecognized arguments,
   * are available for further processing.</p>
   *
   * @author bob mcwhirter (bob @ werken.com)
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  
  public class CommandLine{
      
      private List _args    = new LinkedList();
      private Map  _options = new HashMap();
      
      CommandLine() {
      }
      
      /** <p>Query to see if an option has been set.</p>
       *
       * @param opt Short single-character name of the option
       * @return true if set, false if not
       */
      public boolean hasOption(char opt) {
          return _options.containsKey( new Character(opt) );
      }
      
      /** <p>Retrieve the argument, if any,  of an option.</p>
       *
       * @param opt Short single-character name of the option
       * @return Value of the argument if option is set, and has an argument, else null.
       */
      public String getOptionValue(char opt) {
          return (String) _options.get( new Character(opt) );
      }
      
      /** <p>Retrieve the argument, if any,  of an option.</p>
       *
       * @param opt Short single-character name of the option
       * @param defaultValue is the default value to be returned if the option is not specified
       * @return Value of the argument if option is set, and has an argument, else null.
       */
      public String getOptionValue(char opt, String defaultValue) {
          String answer = getOptionValue(opt);
          return (answer != null) ? answer : defaultValue;
      }
      
      /** <p>Retrieve any left-over non-recognized options and arguments</p>
       *
       * @return an array of remaining items passed in but not parsed
       */
      public String[] getArgs() {
          String[] answer = new String[ _args.size() ];
          _args.toArray( answer );
          return answer;
      }
      
      /** <p>Retrieve any left-over non-recognized options and arguments</p>
       *
       * @return List of remaining items passed in but not parsed
       */
      public List getArgList() {
          return _args;
      }
      
      /** <p>Dump state, suitable for debugging.</p>
       *
       * @return Stringified form of this object
       */
      public String toString() {
          StringBuffer buf = new StringBuffer();
          
          buf.append( "[ CommandLine: [ options: " );
          buf.append( _options.toString() );
          buf.append( " ] [ args: ");
          buf.append( _args.toString() );
          buf.append( " ] ]" );
          
          return buf.toString();
      }
      
      void addArg(String arg) {
          _args.add( arg );
      }
      
      void setOpt(char opt) {
          _options.put( new Character(opt),
          null );
      }
      
      void setOpt(char opt, String value) {
          _options.put( new Character(opt),
          value );
      }    
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/MissingArgumentException.java
  
  Index: MissingArgumentException.java
  ===================================================================
  /*
   * 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: MissingArgumentException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  /** <p>Exception thrown when an option requiring an argument
   * is not provided with an argument.</p>
   *
   * @author bob mcwhirter (bob @ werken.com)
   * @version $Revision: 1.1 $
   */
  public class MissingArgumentException extends ParseException {
      
      /** Construct a new Exception with a message
       *
       * @param msg Explanation of the exception
       */
      public MissingArgumentException(String msg) {
          super(msg);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Option.java
  
  Index: Option.java
  ===================================================================
  /*
   * 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.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  /** <p>Describes a single command-line option.  It maintains
   * information regarding the short-name of the option, the long-name,
   * if any exists, a flag indicating if an argument is required for
   * this option, and a self-documenting description of the option.</p>
   *
   * <p>An Option is not created independantly, but is create through
   * an instance of {@link Options}.<p>
   *
   * @see org.apache.commons.cli.Options
   * @see org.apache.commons.cli.CommandLine
   *
   * @author bob mcwhirter (bob @ werken.com)
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  
  public class Option {
      
      private Character     _opt         = null;
      private String        _longOpt     = null;
      private boolean       _hasArg      = false;
      private String        _description = null;
      
      public Option(char opt, boolean required, String description) {
          _opt         = new Character( opt );
          _hasArg      = required;
          _description = description;
      }
      
      public Option(char opt, String longOpt, boolean required, String description) {
          _opt         = new Character( opt );
          _longOpt     = longOpt;
          _hasArg      = required;
          _description = description;
      }
      
      /** <p>Retrieve the single-character name of this Option</p>
       *
       * <p>It is this character which can be used with
       * {@link CommandLine#hasOption(char opt)} and
       * {@link CommandLine#getOptionValue(char opt)} to check
       * for existence and argument.<p>
       *
       * @return Single character name of this option
       */
      public char getOpt() {
          return _opt.charValue();
      }
      
      /** <p>Retrieve the long name of this Option</p>
       *
       * @return Long name of this option, or null, if there is no long name
       */
      public String getLongOpt() {
          return _longOpt;
      }
      
      /** <p>Query to see if this Option has a long name</p>
       *
       * @return boolean flag indicating existence of a long name
       */
      public boolean hasLongOpt() {
          return ( _longOpt != null );
      }
      
      /** <p>Query to see if this Option requires an argument</p>
       *
       * @return boolean flag indicating if an argument is required
       */
      public boolean hasArg() {
          return _hasArg;
      }
      
      /** <p>Retrieve the self-documenting description of this Option</p>
       *
       * @return The string description of this option
       */
      public String getDescription() {
          return _description;
      }
      
      /** <p>Dump state, suitable for debugging.</p>
       *
       * @return Stringified form of this object
       */
      public String toString() {
          StringBuffer buf = new StringBuffer().append("[ option: ");
          
          buf.append( _opt );
          
          if ( _longOpt != null ) {
              buf.append(" ")
              .append(_longOpt);
          }
          
          buf.append(" ");
          
          if ( _hasArg ) {
              buf.append( "+ARG" );
          }
          
          buf.append(" :: ")
          .append( _description )
          .append(" ]");
          
          return buf.toString();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Options.java
  
  Index: Options.java
  ===================================================================
  /*
   * 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: Options.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.LinkedList;
  import java.util.Iterator;
  import java.util.Collections;
  
  /** <p>Main entry-point into the <code>werken.opt</code> library.</p>
   *
   * <p>Options represents a collection of {@link Option} objects, which
   * describe the possible options for a command-line.<p>
   *
   * <p>It may flexibly parse long and short options, with or without
   * values.  Additionally, it may parse only a portion of a commandline,
   * allowing for flexible multi-stage parsing.<p>
   *
   * @see org.apache.commons.cli.CommandLine
   *
   * @author bob mcwhirter (bob @ werken.com)
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class Options {
      
      private List _options   = new ArrayList();
      private Map  _shortOpts = new HashMap();
      private Map  _longOpts  = new HashMap();
      
      /** <p>Construct a new Options descriptor</p>
       */
      public Options() {        
      }
      
      /** <p>Add an option that only contains a short-name</p>
       * <p>It may be specified as requiring an argument.</p>
       *
       * @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
       */
      public Options addOption(char opt, boolean hasArg, String description) {
          addOption( new Option(opt, hasArg, description) );        
          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 hasArg flag signally if an argument is required after this option
       * @param description Self-documenting description
       */
      public Options addOption(char opt, String longOpt, boolean hasArg, String description) {
          addOption( new Option(opt, longOpt, hasArg, description) );        
          return this;
      }
      
      /** <p>Parse the given list of arguments against this descriptor<p>
       *
       * @param args Args to parse
       *
       * @returns {@link CommandLine} containing information related to parse state
       */
      public CommandLine parse(String[] args) throws MissingArgumentException, UnrecognizedOptionException {
          return parse( args, 0, args.length, false);
      }
      
      /** <p>Parse the given list of arguments against this descriptor</p>
       *
       * <p>This method will cease parsing upon the first non-option token,
       * storing the rest of the tokens for access through {@link CommandLine#getArgs()}.</p>
       *
       * <p>This is useful for parsing a command-line in pieces, such as:</p>
       *
       * <p><code>
       * <pre>
       * myApp -s &lt;server&gt; -p &lt;port&gt; command -p &lt;printer&gt; -s &lt;style&gt;
       * </pre>
       * </code></p>
       *
       * <p>Here, it'll parse up-to, but not including <code>command</code>. The
       * tokens <code>command -p &lt;printer&gt; -s &lt;style&gt;</code> are available
       * through {@link CommandLine#getArgs()}, which may subsequently be parsed by
       * another different <code>Options</code> instance.<p>
       *
       * @param args Args to parse
       * @param stopAtNonOption stop parsing at the first non-option token
       *
       * @returns {@link CommandLine} containing information related to parse state
       */
      public CommandLine parse(String[] args, boolean stopAtNonOption) throws MissingArgumentException, UnrecognizedOptionException {
          return parse( args, 0, args.length, stopAtNonOption);
      }
      
      /** <p>Parse the given list of arguments against this descriptor</p>
       *
       * <p>This method allows parsing from <code>formIndex</code> inclusive
       * 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 fromIndex index of args to start parsing
       * @param toIndex index of args to stop parsing
       *
       * @returns {@link CommandLine} containing information related to parse state
       */
      public CommandLine parse(String[] args, int fromIndex, int toIndex) throws MissingArgumentException, UnrecognizedOptionException {
          return parse( args, fromIndex, toIndex, false );
      }
      
      /** <p>Parse the given list of arguments against this descriptor</p>
       *
       * <p>This method will cease parsing upon the first non-option token,
       * storing the rest of the tokens for access through {@link CommandLine#getArgs()}.</p>
       *
       * <p>This is useful for parsing a command-line in pieces, such as:</p>
       *
       * <p><code>
       * <pre>
       * myApp -s &lt;server&gt; -p &lt;port&gt; command -p &lt;printer&gt; -s &lt;style&gt;
       * </pre>
       * </code></p>
       *
       * <p>Here, it'll parse up-to, but not including <code>command</code>. The
       * tokens <code>command -p &lt;printer&gt; -s &lt;style&gt;</code> are available
       * through {@link CommandLine#getArgs()}, which may subsequently be parsed by
       * another different <code>Options</code> instance.<p>
       *
       * <p>This method also allows parsing from <code>formIndex</code> inclusive
       * 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 fromIndex index of args to start parsing
       * @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 {
          List argList = new ArrayList();
          
          for ( int i = fromIndex; i < toIndex ; ++i ) {
              argList.add( args[i] );
          }
          
          return parse( argList, stopAtNonOption);
      }
      
      /** <p>Parse the given list of arguments against this descriptor</p>
       *
       * @param args Args to parse
       *
       * @returns {@link CommandLine} containing information related to parse state
       */
      public CommandLine parse(List args) throws MissingArgumentException, UnrecognizedOptionException {
          return parse( args, false );
      }
      
      /** <p>Parse the given list of arguments against this descriptor</p>
       *
       * <p>This method will cease parsing upon the first non-option token,
       * storing the rest of the tokens for access through {@link CommandLine#getArgs()}.</p>
       *
       * <p>This is useful for parsing a command-line in pieces, such as:</p>
       *
       * <p><code>
       * <pre>
       * myApp -s &lt;server&gt; -p &lt;port&gt; command -p &lt;printer&gt; -s &lt;style&gt;
       * </pre>
       * </code></p>
       *
       * <p>Here, it'll parse up-to, but not including <code>command</code>. The
       * tokens <code>command -p &lt;printer&gt; -s &lt;style&gt;</code> are available
       * through {@link CommandLine#getArgs()}, which may subsequently be parsed by
       * another different <code>Options</code> instance.<p>
       *
       * <p>This method also allows parsing from <code>formIndex</code> inclusive
       * 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 stopAtNonOption stop parsing at the first non-option token
       *
       * @returns {@link CommandLine} containing information related to parse state
       */
      public CommandLine parse(List inArgs, boolean stopAtNonOption) throws MissingArgumentException, UnrecognizedOptionException {
          CommandLine cl = new CommandLine();
          
          List args = burst( inArgs,
          stopAtNonOption );
          
          Iterator argIter = args.iterator();
          String   eachArg = null;
          Option   eachOpt = null;
          boolean  eatTheRest = false;
          
          while ( argIter.hasNext() ) {
              eachArg = (String) argIter.next();
              
              if ( eachArg.equals("--") ) {
                  // signalled end-of-opts.  Eat the rest
                  
                  eatTheRest = true;
              }
              else if ( eachArg.startsWith("--") ) {
                  eachOpt = (Option) _longOpts.get( eachArg );
                  
                  if ( eachOpt == null ) {
                      throw new UnrecognizedOptionException("Unrecognized option: " + eachArg);
                      // maybe someone will parse these args later
                      // cl.addArg( eachArg );
                  }
                  else {
                      if ( eachOpt.hasArg() ) {
                          if ( argIter.hasNext() ) {
                              eachArg = (String) argIter.next();
                              
                              cl.setOpt( eachOpt.getOpt(),
                              eachArg );
                          }
                          else {
                              throw new MissingArgumentException( eachArg + " requires an argument.");
                          }
                          
                      }
                      else {
                          cl.setOpt( eachOpt.getOpt() );
                      }
                  }
                  
              }
              else if ( eachArg.equals("-") ) {
                  // Just-another-argument
                  
                  if ( stopAtNonOption ) {
                      eatTheRest = true;
                  }
                  else {
                      cl.addArg( eachArg );
                  }
              }
              else if ( eachArg.startsWith("-") ) {
                  eachOpt = (Option) _shortOpts.get( eachArg );
                  
                  if ( eachOpt == null ) {
                      throw new UnrecognizedOptionException("Unrecognized option: " + eachArg);
                      // maybe someone will parse these args later
                      // cl.addArg( eachArg );
                  }
                  else {
                      if ( eachOpt.hasArg() ) {
                          if ( argIter.hasNext() ) {
                              eachArg = (String) argIter.next();
                              
                              cl.setOpt( eachOpt.getOpt(), eachArg );
                              
                          }
                          else {
                              throw new MissingArgumentException( eachArg + " requires an argument.");
                          }
                          
                      }
                      else {
                          cl.setOpt( eachOpt.getOpt() );
                      }
                  }
              }
              else {
                  cl.addArg( eachArg );
                  if ( stopAtNonOption ) {
                      eatTheRest = true;
                  }
              }
              
              if ( eatTheRest ) {
                  while ( argIter.hasNext() ) {
                      eachArg = (String) argIter.next();
                      cl.addArg( eachArg );
                  }
              }
          }
          
          return cl;
      }
      
      private List burst(List inArgs, boolean stopAtNonOption) {
          List args = new LinkedList();
          
          Iterator argIter = inArgs.iterator();
          String   eachArg = null;
          
          boolean eatTheRest = false;
          
          while ( argIter.hasNext() ) {
              eachArg = (String) argIter.next();
              
              if ( eachArg.equals("--") ) {
                  // Look for -- to indicate end-of-options, and
                  // just stuff it, along with everything past it
                  // into the returned list.
                  
                  args.add( eachArg );
                  eatTheRest = true;
              }
              else if ( eachArg.startsWith("--") ) {
                  // It's a long-option, so doesn't need any
                  // bursting applied to it.
                  
                  args.add( eachArg );
              }
              else if ( eachArg.startsWith("-") ) {
                  // It might be a short arg needing
                  // some bursting
                  
                  if ( eachArg.length() == 1) {
                      // It's not really an option, so
                      // just drop it on the list
                      
                      if ( stopAtNonOption ) {
                          eatTheRest = true;
                      }
                      else {
                          args.add( eachArg );
                      }
                  }
                  else if ( eachArg.length() == 2 ) {
                      // No bursting required
                      
                      args.add( eachArg );
                  }
                  else {
                      // Needs bursting.  Figure out
                      // if we have multiple options,
                      // or maybe an option plus an arg,
                      // or some combination thereof.
                      
                      for ( int i = 1 ; i < eachArg.length() ; ++i ) {
                          String optStr = "-" + eachArg.charAt(i);
                          Option opt    = (Option) _shortOpts.get( optStr );
                          
                          if ( (opt != null) && (opt.hasArg()) ) {
                              // If the current option has an argument,
                              // then consider the rest of the eachArg
                              // to be that argument.
                              
                              args.add( optStr );
                              
                              if ( (i+1) < eachArg.length() ) {
                                  String optArg = eachArg.substring(i+1);
                                  args.add( optArg );
                              }                            
                              break;
                          }
                          else {
                              // No argument, so prepend the single dash,
                              // and then drop it into the arglist.
                              
                              args.add( optStr );
                          }
                      }
                  }
              }
              else {
                  // It's just a normal non-option arg,
                  // so dump it into the list of returned
                  // values.
                  
                  args.add( eachArg );
                  
                  if ( stopAtNonOption ) {
                      eatTheRest = true;
                  }
              }
              
              if ( eatTheRest ) {
                  while ( argIter.hasNext() ) {
                      args.add( argIter.next() );
                  }
              }
          }
          
          return args;
      }
      
      private void addOption(Option opt)  {
          String shortOptStr = "-" + opt.getOpt();
          
          if ( opt.hasLongOpt() ) {
              _longOpts.put( "--" + opt.getLongOpt(), opt );
          }
          
          _shortOpts.put( "-" + opt.getOpt(), 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
       */
      public List getOptions() {
          return Collections.unmodifiableList(_options);
      }
      
      /** <p>Retrieve the named {@link Option}<p>
       *
       * @param opt short single-character name of the {@link Option}
       */
      public Option getOption(char opt) {
          return (Option) _shortOpts.get( "-" + opt );
      }
      
      /** <p>Retrieve the named {@link Option}<p>
       *
       * @param opt long name of the {@link Option}
       */
      public Option getOption(String longOpt) {
          return (Option) _longOpts.get( longOpt );
      }
      
      /** <p>Dump state, suitable for debugging.</p>
       *
       * @return Stringified form of this object
       */
      public String toString() {
          StringBuffer buf = new StringBuffer();
          
          buf.append("[ Options: [ short ");
          buf.append( _shortOpts.toString() );
          buf.append( " ] [ long " );
          buf.append( _longOpts );
          buf.append( " ]");
          
          return buf.toString();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/ParseException.java
  
  Index: ParseException.java
  ===================================================================
  /*
   * 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: ParseException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  /** <p>Base for Exceptions thrown during parsing of a command-line<p>
   *
   * @author bob mcwhirter (bob @ werken.com)
   * @version $Revision: 1.1 $
   */
  public class ParseException extends Exception {
      
      /** Construct a new Exception with a message
       *
       * @param msg Explanation of the exception
       */
      public ParseException(String msg) {
          super(msg);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/UnrecognizedOptionException.java
  
  Index: UnrecognizedOptionException.java
  ===================================================================
  /*
   * 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: UnrecognizedOptionException.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  /** <p>Exception thrown during parsing signalling an unrecognized
   * option was seen.<p>
   *
   *
   * @author bob mcwhiter (bob @ werken.com)
   * @version $Revision: 1.1 $
   */
  public class UnrecognizedOptionException extends ParseException {
      
      /** Construct a new Exception with a message
       *
       * @param msg Explanation of the exception
       */
      public UnrecognizedOptionException(String msg) {
          super(msg);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/overview.html
  
  Index: overview.html
  ===================================================================
  
  <body>
   
      <p>Commons CLI -- version ##VERSION## (##QUALITY##)</p>
  
  	<p>The commons-cli package aides in parsing command-line arguments.</p>
  
  	<p>Allow command-line arguments to be parsed against a descriptor of
  	valid options (long and short), potentially with arguments.</p>
  
  	<p>command-line arguments may be of the typical <code>String[]</code>
  	form, but also may be a <code>java.util.List</code>.  Indexes allow
  	for parsing only a portion of the command-line.  Also, functionality
  	for parsing the command-line in phases is built in, allowing for
  	'cvs-style' command-lines, where some global options are specified
  	before a 'command' argument, and command-specific options are
  	specified after the command argument:
  	
  	<code>
  	<pre>
  		myApp -p &lt;port&gt; command -p &lt;printer&gt;
  	</pre>
  	</code>
  	
  
  	<p>The homepage for the project is
  	<a href="http://jakarta.apache.org/commons/">jakarta commons/</a>
  </body>
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/package.html
  
  Index: package.html
  ===================================================================
  
  <body>
  
      <p>Commons CLI -- version ##VERSION## (##QUALITY##)</p>
  
  </body>
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli/AllTest.java
  
  Index: AllTest.java
  ===================================================================
  /*
   * 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: AllTest.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  public class AllTest 
  {
      public static Test suite() { 
  
          TestSuite suite= new TestSuite(); 
  
          suite.addTest(BuildTest.suite()); 
          suite.addTest(ValueTest.suite()); 
          suite.addTest(ParseTest.suite()); 
  
          return suite; 
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli/BuildTest.java
  
  Index: BuildTest.java
  ===================================================================
  /*
   * 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: BuildTest.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  public class BuildTest extends TestCase
  {
  
      public static Test suite() { 
          return new TestSuite(BuildTest.class); 
      }
  
      public BuildTest(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
  
      }
  
      public void tearDown()
      {
  
      }
  
      public void testSimple()
      {
          Options opts = new Options();
          
          opts.addOption('a',
                         false,
                         "toggle -a");
  
          opts.addOption('b',
                         true,
                         "toggle -b");
  /*
          try
          {
              opts.addOption('a',
                             false,
                             "toggle -a");
              
              opts.addOption('b',
                             true,
                             "toggle -b");
          }
          catch (DuplicateOptionException e)
          {
              fail(e.toString());
          }
  */
      }
  
      public void testDuplicateSimple()
      {
          Options opts = new Options();
          opts.addOption('a',
                         false,
                         "toggle -a");
  
          opts.addOption('a',
                         true,
                         "toggle -a*");
          
          assertEquals( "last one in wins", "toggle -a*", opts.getOption('a').getDescription() );
  /*
          try
          {
              opts.addOption('a',
                             false,
                             "toggle -a");
              
              opts.addOption('a',
                             true,
                             "toggle -a");
  
              fail("Should've thrown DuplicateOptionException");
          }
          catch (DuplicateOptionException e)
          {
          }
   */
      }
  
      public void testLong()
      {
          Options opts = new Options();
          
          opts.addOption('a',
                         "--a",
                         false,
                         "toggle -a");
  
          opts.addOption('b',
                         "--b",
                         true,
                         "set -b");
  
  /*        
          try
          {
              opts.addOption('a',
                             "--a",
                             false,
                             "toggle -a");
  
              opts.addOption('b',
                             "--b",
                             true,
                             "set -b");
          }
          catch (DuplicateOptionException e)
          {
              fail(e.toString());
          }
  */
      }
  
      public void testDuplicateLong()
      {
          Options opts = new Options();
          opts.addOption('a',
                         "--a",
                         false,
                         "toggle -a");
  
          opts.addOption('a',
                         "--a",
                         false,
                         "toggle -a*");
          assertEquals( "last one in wins", "toggle -a*", opts.getOption('a').getDescription() );
  /*
          try
          {
              opts.addOption('a',
                             "--a",
                             false,
                             "toggle -a");
  
              opts.addOption('a',
                             "--a",
                             false,
                             "toggle -a");
  
              fail("Should've thrown DuplicateOptionException");
          }
          catch (DuplicateOptionException e)
          {
          }
  */
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli/ParseTest.java
  
  Index: ParseTest.java
  ===================================================================
  /*
   * 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: ParseTest.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  public class ParseTest extends TestCase
  {
  
      private Options _options = null;
  
      public static Test suite() { 
          return new TestSuite(ParseTest.class); 
      }
  
      public ParseTest(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
          _options = new Options()
              .addOption('a',
                         "enable-a",
                         false,
                         "turn [a] on or off")
              .addOption('b',
                         "bfile",
                         true,
                         "set the value of [b]")
              .addOption('c',
                         "copt",
                         false,
                         "turn [c] on or off");
  /*        
          try
          {
              _options
                  .addOption('a',
                             "enable-a",
                             false,
                             "turn [a] on or off")
                  .addOption('b',
                             "bfile",
                             true,
                             "set the value of [b]")
                  .addOption('c',
                             "copt",
                             false,
                             "turn [c] on or off");
              
          }
          catch (CLIException e)
          {
              e.printStackTrace();
          }
  */
      }
  
      public void tearDown()
      {
  
      }
  
      public void testSimpleShort()
      {
          String[] args = new String[] { "-a",
                                         "-b", "toast",
                                         "foo", "bar" };
  
          try
          {
              CommandLine cl = _options.parse(args);
              
              assertTrue( "Confirm -a is set", cl.hasOption('a') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testSimpleLong()
      {
          String[] args = new String[] { "--enable-a",
                                         "--bfile", "toast",
                                         "foo", "bar" };
  
          try
          {
              CommandLine cl = _options.parse(args);
              
              assertTrue( "Confirm -a is set", cl.hasOption('a') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
          } 
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testComplexShort()
      {
          String[] args = new String[] { "-acbtoast",
                                         "foo", "bar" };
  
          try
          {
              CommandLine cl = _options.parse(args);
              
              assertTrue( "Confirm -a is set", cl.hasOption('a') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm -c is set", cl.hasOption('c') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testExtraOption()
      {
          String[] args = new String[] { "-adbtoast",
                                         "foo", "bar" };
  
          boolean caught = false;
  
          try
          {
              CommandLine cl = _options.parse(args);
              
              assertTrue( "Confirm -a is set", cl.hasOption('a') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm size of extra args", cl.getArgList().size() == 3);
          }
          catch (UnrecognizedOptionException e)
          {
              caught = true;
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
          assertTrue( "Confirm UnrecognizedOptionException caught", caught );
      }
  
      public void testMissingArg()
      {
  
          String[] args = new String[] { "-acb" };
  
          boolean caught = false;
  
          try
          {
              CommandLine cl = _options.parse(args);
          }
          catch (MissingArgumentException e)
          {
              caught = true;
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
  
          assertTrue( "Confirm MissingArgumentException caught", caught );
      }
  
      public void testStop()
      {
          String[] args = new String[] { "-c",
                                         "foober",
                                         "-btoast" };
  
          try
          {
              CommandLine cl = _options.parse(args,
                                              true);
              assertTrue( "Confirm -c is set", cl.hasOption('c') );
              assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testMultiple()
      {
          String[] args = new String[] { "-c",
                                         "foobar",
                                         "-btoast" };
  
          try
          {
              CommandLine cl = _options.parse(args,
                                              true);
              assertTrue( "Confirm -c is set", cl.hasOption('c') );
              assertTrue( "Confirm  2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
  
              cl = _options.parse( cl.getArgList() );
  
              assertTrue( "Confirm -c is not set", ! cl.hasOption('c') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
              assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testMultipleWithLong()
      {
          String[] args = new String[] { "--copt",
                                         "foobar",
                                         "--bfile", "toast" };
  
          try
          {
              CommandLine cl = _options.parse(args,
                                              true);
              assertTrue( "Confirm -c is set", cl.hasOption('c') );
              assertTrue( "Confirm  3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
  
              cl = _options.parse( cl.getArgList() );
  
              assertTrue( "Confirm -c is not set", ! cl.hasOption('c') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("toast") );
              assertTrue( "Confirm  1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
              assertTrue( "Confirm  value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testDoubleDash()
      {
          String[] args = new String[] { "--copt",
                                         "--",
                                         "-b", "toast" };
  
          try
          {
              CommandLine cl = _options.parse(args);
  
              assertTrue( "Confirm -c is set", cl.hasOption('c') );
              assertTrue( "Confirm -b is not set", ! cl.hasOption('b') );
              assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
  
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
      }
  
      public void testSingleDash()
      {
          String[] args = new String[] { "--copt",
                                         "-b", "-",
                                         "-a",
                                         "-" };
  
          try
          {
              CommandLine cl = _options.parse(args);
  
              assertTrue( "Confirm -a is set", cl.hasOption('a') );
              assertTrue( "Confirm -b is set", cl.hasOption('b') );
              assertTrue( "Confirm arg of -b", cl.getOptionValue('b').equals("-") );
              assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
              assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
          }
          catch (ParseException e)
          {
              fail( e.toString() );
          }
          
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli/ValueTest.java
  
  Index: ValueTest.java
  ===================================================================
  /*
   * 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: ValueTest.java,v 1.1 2001/12/19 18:16:25 jstrachan Exp $
   */
  
  package org.apache.commons.cli;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  public class ValueTest extends TestCase
  {
  
      public static Test suite() { 
          return new TestSuite(ValueTest.class); 
          /*
          TestSuite suite = new TestSuite();
  
          suite.addTest( new ValueTest("testLongNoArg") );
  
          return suite;
          */
      }
  
      private CommandLine _cl = null;
  
  
      public ValueTest(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
          Options opts = new Options();
          opts.addOption('a',
                         false,
                         "toggle -a");
  
          opts.addOption('b',
                         true,
                         "set -b");
  
          opts.addOption('c',
                         "c",
                         false,
                         "toggle -c");
  
          opts.addOption('d',
                         "d",
                         true,
                         "set -d");
  
  /*            
          try
          {
              opts.addOption('a',
                             false,
                             "toggle -a");
              
              opts.addOption('b',
                             true,
                             "set -b");
              
              opts.addOption('c',
                             "c",
                             false,
                             "toggle -c");
              
              opts.addOption('d',
                             "d",
                             true,
                             "set -d");
          }
          catch (DuplicateOptionException e)
          {
              fail("Cannot setUp() Options: " + e.toString());
          }
  */
  
          String[] args = new String[] { "-a",
                                         "-b", "foo",
                                         "--c",
                                         "--d", "bar" };
  
          try
          {
              _cl = opts.parse(args);
          }
          catch (ParseException e)
          {
              fail("Cannot setUp() CommandLine: " + e.toString());
          }
      }
  
      public void tearDown()
      {
  
      }
  
      public void testShortNoArg()
      {
          assertTrue( _cl.hasOption('a') );
          assertNull( _cl.getOptionValue('a') );
      }
  
      public void testShortWithArg()
      {
          assertTrue( _cl.hasOption('b') );
          assertNotNull( _cl.getOptionValue('b') );
          assertEquals( _cl.getOptionValue('b'), "foo");
      }
  
      public void testLongNoArg()
      {
          assertTrue( _cl.hasOption('c') );
          assertNull( _cl.getOptionValue('c') );
      }
  
      public void testLongWithArg()
      {
          assertTrue( _cl.hasOption('d') );
          assertNotNull( _cl.getOptionValue('d') );
          assertEquals( _cl.getOptionValue('d'), "bar");
      }
  }
  
  
  
  1.6       +7 -0      jakarta-commons-sandbox/messenger/TODO.txt
  
  Index: TODO.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/TODO.txt,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TODO.txt	2001/11/13 09:42:27	1.5
  +++ TODO.txt	2001/12/19 18:16:25	1.6
  @@ -5,6 +5,13 @@
   * Allow the replyTo destination and Messenger to be overridden 
     in the XML deployment configuration for Messagelets and Servlets.
   
  +* provide a <sender> element in the subscriber XML document which will
  +  then act as a very simple router. e.g. 
  +
  +  <subscribe connection="foo" destination="incoming">
  +    <send connection="bar" destination="outgoing"/>
  +  </subscribe>
  +
   * Maybe Ant tasks to generate messages from <fileSets> or something?
   
   * write JMSServlet such that
  
  
  
  1.23      +2 -13     jakarta-commons-sandbox/messenger/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- build.xml	2001/10/30 11:14:30	1.22
  +++ build.xml	2001/12/19 18:16:25	1.23
  @@ -1,4 +1,4 @@
  -<!-- $Id: build.xml,v 1.22 2001/10/30 11:14:30 jstrachan Exp $ -->
  +<!-- $Id: build.xml,v 1.23 2001/12/19 18:16:25 jstrachan Exp $ -->
   <project name="messenger" default="test" basedir=".">
   
      <!-- patternset describing files to be copied from the doc directory -->
  @@ -100,17 +100,6 @@
   
      <!-- ######################################################### -->
   
  -   <target name="copy-javadoc-source" depends="init" if="available-src-java">
  -      <mkdir dir="${javadoc-source-dir}"/>
  -      <copy todir="${javadoc-source-dir}" filtering="no">
  -         <fileset dir="${source.src.java}">
  -            <patternset refid="patternset-javadocable-sources"/>
  -         </fileset>
  -      </copy>
  -   </target>
  -
  -   <!-- ######################################################### -->
  -
      <target name="clean" depends="clean-dist,clean-build,clean-doc" description="removes generated files">
         <delete dir="${dest}"/>
      </target>
  @@ -197,7 +186,7 @@
                  nonavbar="false"
                  serialwarn="false">
             <link href="http://java.sun.com/j2ee/j2sdkee/techdocs/api"/>
  -          <link href="http://java.sun.com/products/jdk/1.3/docs/api"/>
  +          <link href="http://java.sun.com/j2se/1.4/docs/api"/>
         </javadoc>
         <delete dir="${workdir}"/>
      </target>
  
  
  

--
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