trygvis     2004/05/16 04:38:31

  Modified:    maven-core/src/main/java/org/apache/maven MavenCli.java
  Log:
  o Reorganized the CLI handling.
  o Added --help option processing.
  o Added --version option processing. Still needs to know it's own version somehow.
  o Added -g option processing for listing all goals.
    Needs better formatting and possibly more output.
  
  Revision  Changes    Path
  1.5       +73 -29    
maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java
  
  Index: MavenCli.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MavenCli.java     9 May 2004 23:00:59 -0000       1.4
  +++ MavenCli.java     16 May 2004 11:38:31 -0000      1.5
  @@ -16,6 +16,10 @@
    * limitations under the License.
    */
   
  +import java.io.File;
  +import java.util.Iterator;
  +import java.util.TreeMap;
  +
   import org.apache.commons.cli.CommandLine;
   import org.apache.commons.cli.CommandLineParser;
   import org.apache.commons.cli.HelpFormatter;
  @@ -23,10 +27,9 @@
   import org.apache.commons.cli.Options;
   import org.apache.commons.cli.ParseException;
   import org.apache.commons.cli.PosixParser;
  -import org.codehaus.classworlds.ClassWorld;
  +import org.apache.maven.plugin.GoalDescriptor;
   
  -import java.io.File;
  -import java.util.Iterator;
  +import org.codehaus.classworlds.ClassWorld;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  @@ -38,14 +41,6 @@
   
       public static final String POM_VERSION_4_FILE_NAME = "project2.xml";
   
  -    private static final String WORK_OFFLINE = "o";
  -
  -    private static final String REACTOR = "r";
  -
  -    private static final String SET_SYSTEM_PROPERTY = "D";
  -
  -    private static final String DEBUG = "X";
  -
       public static void main( String[] args, ClassWorld classWorld )
           throws Exception
       {
  @@ -76,10 +71,44 @@
           }
   
           // ----------------------------------------------------------------------
  +        // Process particular command line options
  +        // ----------------------------------------------------------------------
  +
  +        if ( commandLine.hasOption( CLIManager.HELP ) )
  +        {
  +            cliManager.displayHelp();
  +
  +            return;
  +        }
  +
  +        if ( commandLine.hasOption( CLIManager.VERSION ) )
  +        {
  +            // TODO: create some sane output.
  +            System.out.println( "Maven version: " );
  +
  +            return;
  +        }
  +
  +        if ( commandLine.hasOption( CLIManager.LIST_GOALS ) )
  +        {
  +            Iterator goals = new TreeMap( maven.getGoalDescriptors() 
).values().iterator();
  +
  +            System.out.println( "Goals: " );
  +
  +            while ( goals.hasNext() )
  +            {
  +                GoalDescriptor goal = (GoalDescriptor)goals.next();
  +                System.out.println( "    " + goal.getName() );
  +            }
  +
  +            return;
  +        }
  +
  +        // ----------------------------------------------------------------------
           // Execute the goals
           // ----------------------------------------------------------------------
   
  -        if ( commandLine.hasOption( REACTOR ) )
  +        if ( commandLine.hasOption( CLIManager.REACTOR ) )
           {
               for ( Iterator i = commandLine.getArgList().iterator(); i.hasNext(); )
               {
  @@ -101,7 +130,7 @@
           // and therefore are set in the session properties. System properties
           // are most dominant.
   
  -        if ( commandLine.hasOption( DEBUG ) )
  +        if ( commandLine.hasOption( CLIManager.DEBUG ) )
           {
               System.setProperty( MavenConstants.DEBUG_ON, "true" );
           }
  @@ -110,7 +139,7 @@
               System.setProperty( MavenConstants.DEBUG_ON, "false" );
           }
   
  -        if ( commandLine.hasOption( WORK_OFFLINE ) )
  +        if ( commandLine.hasOption( CLIManager.WORK_OFFLINE ) )
           {
               System.setProperty( "maven.mode.online", "false" );
           }
  @@ -119,9 +148,9 @@
               System.setProperty( "maven.mode.online", "true" );
           }
   
  -        if ( commandLine.hasOption( SET_SYSTEM_PROPERTY ) )
  +        if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
           {
  -            String[] defStrs = commandLine.getOptionValues( SET_SYSTEM_PROPERTY );
  +            String[] defStrs = commandLine.getOptionValues( 
CLIManager.SET_SYSTEM_PROPERTY );
   
               for ( int i = 0; i < defStrs.length; ++i )
               {
  @@ -156,23 +185,39 @@
   
       static class CLIManager
       {
  +        public static final char NO_BANNER = 'b';
  +
  +        public static final char SET_SYSTEM_PROPERTY = 'D';
  +
  +        public static final char WORK_OFFLINE = 'o';
  +
  +        public static final char REACTOR = 'r';
  +
  +        public static final char DEBUG = 'X';
  +
  +        public static final char HELP = 'h';
  +
  +        public static final char VERSION = 'v';
  +
  +        public static final char LIST_GOALS = 'g';
  +
           private Options options = null;
   
  -        CLIManager()
  +        public CLIManager()
           {
               options = new Options();
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "nobanner" )
                                  .withDescription( "Suppress logo banner" )
  -                               .create( 'b' ) );
  +                               .create( NO_BANNER ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "define" )
                                  .hasArg()
                                  .withDescription( "Define a system property" )
  -                               .create( 'D' ) );
  -
  +                               .create( SET_SYSTEM_PROPERTY ) );
  +/*
               options.addOption( OptionBuilder
                                  .withLongOpt( "dir" )
                                  .hasArg()
  @@ -183,36 +228,36 @@
                                  .withLongOpt( "exception" )
                                  .withDescription( "Produce exception stack traces" )
                                  .create( 'e' ) );
  -
  +*/
               options.addOption( OptionBuilder
                                  .withLongOpt( "goalDescriptors" )
                                  .withDescription( "Display available 
goalDescriptors" )
  -                               .create( 'g' ) );
  +                               .create( LIST_GOALS ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "help" )
                                  .withDescription( "Display help information" )
  -                               .create( 'h' ) );
  +                               .create( HELP ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "offline" )
                                  .withDescription( "Build is happening offline" )
  -                               .create( 'o' ) );
  +                               .create( WORK_OFFLINE ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "version" )
                                  .withDescription( "Display version information" )
  -                               .create( 'v' ) );
  +                               .create( VERSION ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "debug" )
                                  .withDescription( "Produce execution debug output" )
  -                               .create( 'X' ) );
  +                               .create( DEBUG ) );
   
               options.addOption( OptionBuilder
                                  .withLongOpt( "reactor" )
                                  .withDescription( "Execute goals for project found 
in the reactor" )
  -                               .create( 'r' ) );
  +                               .create( REACTOR ) );
           }
   
           public CommandLine parse( String[] args ) throws ParseException
  @@ -227,7 +272,6 @@
               HelpFormatter formatter = new HelpFormatter();
   
               formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", 
"\nOptions:", options, "\n" );
  -
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to