brett       2004/04/16 00:00:35

  Modified:    src/java/org/apache/maven/cli Tag: MAVEN-1_0-BRANCH App.java
                        CLIManager.java
  Log:
  improved help options
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.37.4.19 +90 -52    maven/src/java/org/apache/maven/cli/App.java
  
  Index: App.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/cli/App.java,v
  retrieving revision 1.37.4.18
  retrieving revision 1.37.4.19
  diff -u -r1.37.4.18 -r1.37.4.19
  --- App.java  12 Apr 2004 23:02:30 -0000      1.37.4.18
  +++ App.java  16 Apr 2004 07:00:34 -0000      1.37.4.19
  @@ -133,6 +133,12 @@
       /** Display help option. */
       private static final String DISPLAY_HELP = "h";
   
  +    /** Display plugin help option. */
  +    private static final String DISPLAY_PLUGIN_HELP = "P";
  +
  +    /** Display project help option. */
  +    private static final String DISPLAY_USAGE = "u";
  +
       /** Display info option. */
       private static final String DISPLAY_INFO = "i";
   
  @@ -463,15 +469,15 @@
               printConsoleMavenHeader();
           }
   
  -        //printConsoleProjectHeader( project );
  -        //System.out.println();
  -
           boolean failed = false;
   
           try
           {
               mavenSession.initialize();
   
  +            displayProjectHelp();
  +            displayPluginHelp();
  +
               if ( getCli().hasOption( DISPLAY_GOALS ) )
               {
                   displayGoals();
  @@ -566,6 +572,11 @@
               System.out.println( "BUILD SUCCESSFUL" );
           }
   
  +        final long mb = 1024 * 1024;
  +        System.gc();
  +        Runtime r = Runtime.getRuntime();
  +        log.debug( "Final Memory: " + ((r.totalMemory() - r.freeMemory()) / mb) + 
"M/" + (r.totalMemory() / mb) + "M");
  +
           Date fullStop = new Date();
   
           long fullDiff = fullStop.getTime() - fullStart.getTime();
  @@ -630,6 +641,39 @@
       }
   
       /**
  +     * Display the plugin help if the option is present, then exit
  +     */
  +    private void displayPluginHelp()
  +    {
  +        if ( getCli().hasOption( DISPLAY_PLUGIN_HELP ) )
  +        {
  +            String plugin = getCli().getOptionValue( DISPLAY_PLUGIN_HELP );
  +
  +            displayGoals( true, plugin );
  +
  +            // TODO: show project information for plugin
  +
  +            exit( RC_OK );
  +            return;
  +        }
  +    }
  +
  +    /**
  +     * Display the project help if the option is present, then exit
  +     */
  +    private void displayProjectHelp()
  +    {
  +        if ( getCli().hasOption( DISPLAY_USAGE ) )
  +        {
  +            // TODO: show maven.xml goals
  +            // TODO: show maven.xml goal hooks
  +            // TODO: show project information
  +            exit( RC_OK );
  +            return;
  +        }
  +    }
  +
  +    /**
        * Display the command line info if the option is present, then exit
        */
       private void displayInfo()
  @@ -792,28 +836,29 @@
       }
   
       /**
  -     * Prints the Project header to System.out
  -     *
  -     * @param mavenProject the project the print
  +     * Display helpful information regarding
  +     *  all documented goals.
        */
  -    /*
  -    protected void printConsoleProjectHeader( Project mavenProject )
  +    protected void displayGoals()
       {
  -        System.out.println( getRootContext().getDescriptorDirectory() );
  +        displayGoals( false, null );
       }
  -    */
   
       /**
  -     * Display helpful information regarding
  -     *  all documented goals.
  +     * Display helpful information regarding all documented goals.
  +     * @param pluginOnly show information for the given plugin only
  +     * @param plugin plugin to show info for
        */
  -    protected void displayGoals()
  +    protected void displayGoals( boolean pluginOnly, String plugin )
       {
  -        log.info("");
           String title = "Available [Plugins] / Goals";
  +        if ( pluginOnly )
  +        {
  +            title = ( plugin == null ? "Available plugins" : "Goals in " + plugin );
  +        }
           log.info( title );
  -        log.info( format( "", title.length(), '`' ) );
  -
  +        log.info( format( "", title.length(), '=' ) );
  +        log.info( "" );
   
           Set goals = mavenSession.getAllGoalNames();
   
  @@ -836,7 +881,7 @@
           String msgPrefix = "";
           boolean hasDesc = false;
           boolean firstLine = true;
  -        boolean haveGoalsWithNoDescription = false;
  +        List undocumentedGoals = new ArrayList();
           String lastPluginName = "";
   
           for ( Iterator i = list.iterator(); i.hasNext();)
  @@ -848,9 +893,24 @@
               String pluginName = st.nextToken(); //ex. java
               boolean newPlugin = !pluginName.equals( lastPluginName );
   
  +            if ( pluginOnly ) 
  +            {
  +                if ( plugin == null && !pluginName.equals( goalName ) )
  +                {
  +                    // only show default goal
  +                    continue;
  +                }
  +                else if ( plugin != null && !pluginName.equals( plugin ) )
  +                {
  +                    // only show specified plugin
  +                    continue;
  +                }
  +            }
  +
               // Prepare the description
  -            if ( goalDescription == null )
  +            if ( goalDescription == null || goalDescription.equals( "null" ) )
               {
  +                // If description equals the string "null", it came from the cache
                   hasDesc = false;
               }
               else
  @@ -897,7 +957,7 @@
                   }
   
                   // the first line of display goals should not start a new line
  -                if ( firstLine )
  +                if ( firstLine || pluginOnly )
                   {
                       msgPrefix = "[" + msgPrefix;
                       firstLine = false;
  @@ -945,22 +1005,20 @@
                       msgPrefix = format( msgPrefix, wrapIndent, '.' ) + " ";
                       wrapIndent += 1; // for spaces used to pad the prefix
   
  -                    System.out.println( msgPrefix
  -                                        + wrapConsoleMessage( goalDescription, 
wrapIndent,
  -                                                              CONSOLE_WIDTH ) );
  +                    log.info( msgPrefix + wrapConsoleMessage( goalDescription, 
wrapIndent, CONSOLE_WIDTH ) );
                   }
                   else
                   {
  -                    haveGoalsWithNoDescription = true;
  +                    undocumentedGoals.add( goalName );
                   }
               }
           }
   
  -        if ( haveGoalsWithNoDescription )
  +        if ( undocumentedGoals.isEmpty() == false )
           {
  -            displayGoalsWithoutDescriptions( list );
  +            displayGoalsWithoutDescriptions( undocumentedGoals );
           }
  -        log.info("");
  +        log.info( "" );
       }
   
       /** Display goals without descriptions.
  @@ -969,35 +1027,15 @@
        */
       private void displayGoalsWithoutDescriptions( List list )
       {
  -        System.out.println();
  -        System.out.println();
  -        System.out.println( "Non documented goals : " );
  -        System.out.println();
  +        log.info( "" );
  +        log.info( "Undocumented goals : " );
  +        log.info( "" );
   
           for ( Iterator i = list.iterator(); i.hasNext();)
           {
  -            String goalName = (String) i.next();
  -
  -            String goalDescription = mavenSession.getGoalDescription( goalName );
  -
  -            boolean hasDesc = false;
  +            String goalName = ( String ) i.next();
   
  -            /*
  -             * prepare the description
  -             */
  -            if ( goalDescription == null )
  -            {
  -                hasDesc = false;
  -            }
  -            else
  -            {
  -                hasDesc = goalDescription.trim().length() != 0;
  -            }
  -
  -            if ( !hasDesc )
  -            {
  -                System.out.println( "  " + goalName );
  -            }
  +            log.info( "  " + goalName );
           }
       }
   
  
  
  
  1.12.4.6  +11 -0     maven/src/java/org/apache/maven/cli/CLIManager.java
  
  Index: CLIManager.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/cli/CLIManager.java,v
  retrieving revision 1.12.4.5
  retrieving revision 1.12.4.6
  diff -u -r1.12.4.5 -r1.12.4.6
  --- CLIManager.java   4 Apr 2004 02:55:57 -0000       1.12.4.5
  +++ CLIManager.java   16 Apr 2004 07:00:35 -0000      1.12.4.6
  @@ -100,6 +100,17 @@
                              .create( 'g' ) );
   
           options.addOption( OptionBuilder
  +                           .withLongOpt( "plugin-help" )
  +                           .withDescription( "Display help on using a given plugin" 
)
  +                           .hasOptionalArg()
  +                           .create( 'P' ) );
  +
  +        options.addOption( OptionBuilder
  +                           .withLongOpt( "usage" )
  +                           .withDescription( "Display help on using the current 
project" )
  +                           .create( 'u' ) );
  +
  +        options.addOption( OptionBuilder
                              .withLongOpt( "help" )
                              .withDescription( "Display help information" )
                              .create( 'h' ) );
  
  
  

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

Reply via email to