You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2002/12/31 08:02:47 UTC

cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/cli App.java CLIManager.java

jvanzyl     2002/12/30 23:02:47

  Modified:    src/java/org/apache/maven/cli App.java CLIManager.java
  Log:
  refactoring
  
  Revision  Changes    Path
  1.16      +70 -105   jakarta-turbine-maven/src/java/org/apache/maven/cli/App.java
  
  Index: App.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/cli/App.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- App.java	18 Dec 2002 17:11:01 -0000	1.15
  +++ App.java	31 Dec 2002 07:02:47 -0000	1.16
  @@ -26,12 +26,12 @@
    *    if and wherever such third-party acknowledgments normally appear.
    *
    * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Maven" must not be used to endorse or promote products
  + *    "Apache MavenSession" 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",
  - *    "Apache Maven", nor may "Apache" appear in their name, without
  + *    "Apache MavenSession", nor may "Apache" appear in their name, without
    *    prior written permission of the Apache Software Foundation.
    *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  @@ -64,13 +64,12 @@
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.maven.Maven;
   import org.apache.maven.MavenUtils;
  -import org.apache.maven.UnknownGoalException;
  -import org.apache.maven.jelly.MavenJellyContext;
  -import org.apache.maven.project.Project;
  +import org.apache.maven.MavenSession;
   import org.apache.maven.verifier.RepoConfigException;
   import org.apache.maven.verifier.UnsatisfiedDependencyException;
  +import org.apache.maven.UnknownGoalException;
  +import org.apache.maven.jelly.MavenJellyContext;
   
   import java.io.File;
   import java.io.IOException;
  @@ -89,8 +88,8 @@
   import java.util.StringTokenizer;
   
   /**
  - * The CLI wrapper for controlling Maven processes which are
  - * encapsulated in the Maven bean.
  + * The CLI wrapper for controlling MavenSession processes which are
  + * encapsulated in the MavenSession bean.
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
    * @author dIon Gillard
  @@ -99,10 +98,10 @@
    *
    * @todo Separate the computation of the available goals from the display
    *       of the goals. The goal computation logic needs to be moved
  - *       out of this class and be placed in Maven.java proper.
  + *       out of this class and be placed in MavenSession.java proper.
    * @todo All logging needs to be done via commons-logging. No
    *       System.out.* and Jelly needs to be taught to take a
  - *       logger. In an attempt to isolate everything in Maven.java.
  + *       logger. In an attempt to isolate everything in MavenSession.java.
    */
   public class App
   {
  @@ -204,8 +203,10 @@
       /** Jelly's underlying writer. */
       private Writer writer;
   
  -    /** Maven Jelly context. */
  -    private MavenJellyContext context;
  +    /** MavenSession Jelly rootContext. */
  +    private MavenJellyContext rootContext;
  +
  +    private MavenSession mavenSession;
   
       /** Constructor. */
       public App()
  @@ -217,23 +218,23 @@
       // ----------------------------------------------------------------------
   
       /**
  -     * Set Jelly context.
  +     * Set Jelly rootContext.
        *
  -     * @param context The maven jelly context.
  +     * @param rootContext The mavenSession jelly rootContext.
        */
  -    public void setContext( MavenJellyContext context )
  +    public void setRootContext( MavenJellyContext rootContext )
       {
  -        this.context = context;
  +        this.rootContext = rootContext;
       }
   
       /**
  -     * Retrieve the Jelly context.
  +     * Retrieve the Jelly rootContext.
        *
  -     * @return The Jelly context.
  +     * @return The Jelly rootContext.
        */
  -    public MavenJellyContext getContext()
  +    public MavenJellyContext getRootContext()
       {
  -        return context;
  +        return rootContext;
       }
   
       /**
  @@ -278,10 +279,8 @@
           setCli( CLIManager.parse( args ) );
   
           initializeSystemProperties();
  -        initializeContext( getDescriptorFile() );
  -        initializeMavenBean();
  -        initializeProject();
  -        initializeIO();
  +        initializeRootContext();
  +        initializeMavenSession();
       }
   
       /**
  @@ -324,61 +323,12 @@
       }
   
       /**
  -     * Initialize the context that will be used by all the components
  -     * used in Maven.
  -     *
  -     * @param descriptorFile The XML based POM descriptor.
  -     */
  -    private void initializeContext( File descriptorFile )
  -    {
  -        setContext( MavenUtils.createContext( descriptorFile.getParentFile() ));
  -
  -        getContext().setDescriptorFile( descriptorFile );
  -        getContext().setDescriptorDirectory( descriptorFile.getParentFile() );
  -    }
  -
  -    /**
  -     * Initialize the maven bean.
  -     */
  -    private void initializeMavenBean()
  -    {
  -        Maven maven = new Maven();
  -        maven.setContext( getContext() );
  -        maven.addGoalNames( getCli().getArgList() );
  -        getContext().setMaven( maven );
  -    }
  -
  -    /**
  -     * Load the maven project descriptor.
  -     *
  -     * @throws Exception If there is an error while
  -     *          reading the project descriptor.
  -     */
  -    private void initializeProject()
  -        throws Exception
  -    {
  -        File descriptorFile = getContext().getDescriptorFile();
  -
  -        if ( descriptorFile.exists() )
  -        {
  -            if ( descriptorFile.length() == 0 )
  -            {
  -                throw new Exception( MavenUtils.getMessage( "empty.descriptor.error",
  -                                                            getContext().getDescriptorFile().getName() ) );
  -            }
  -
  -            getContext().setProject( MavenUtils.getProject( getContext().getDescriptorFile(),
  -                                                            getContext().getDescriptorDirectory() ) );
  -        }
  -    }
  -
  -    /**
        *  Initialize the IO streams.
        *
        * @throws IOException on error creating XML output and handling System.err
        *         and out
        */
  -    protected void initializeIO()
  +    protected void initializeRootContext()
           throws IOException
       {
           this.consoleOut = System.out;
  @@ -387,48 +337,64 @@
           this.writer = new OutputStreamWriter( this.consoleOut );
           XMLOutput output = XMLOutput.createXMLOutput( writer, false );
   
  +        // We will assume here that there might not be a project.xml file present
  +        // and we will create the root context from the directory gleaned from
  +        // the user.dir system property.
  +        MavenJellyContext c = MavenUtils.createContext( new File( System.getProperty("user.dir") ) );
  +        setRootContext( c );
  +
           if ( getCli().hasOption( DEBUG ) )
           {
  -            getContext().setXMLOutput( output );
  -            getContext().setDebugOn( Boolean.TRUE );
  +            getRootContext().setXMLOutput( output );
  +            getRootContext().setDebugOn( Boolean.TRUE );
           }
           else
           {
  -            getContext().setXMLOutput( output );
  -            getContext().setDebugOn( Boolean.FALSE );
  +            getRootContext().setXMLOutput( output );
  +            getRootContext().setDebugOn( Boolean.FALSE );
           }
   
           if ( getCli().hasOption( EMACS_OUTPUT ) )
           {
  -            getContext().setEmacsModeOn( Boolean.TRUE );
  +            getRootContext().setEmacsModeOn( Boolean.TRUE );
           }
           else
           {
  -            getContext().setEmacsModeOn( Boolean.FALSE );
  +            getRootContext().setEmacsModeOn( Boolean.FALSE );
           }
  -    }
   
  -    /**
  -     * Check the online status.
  -     */
  -    private void checkOnline()
  -    {
  -        if ( getContext().getOnline() != null )
  +        if ( getRootContext().getOnline() != null )
           {
               return;
           }
   
           if ( getCli().hasOption( WORK_OFFLINE ) )
           {
  -            getContext().setOnline( Boolean.FALSE );
  +            getRootContext().setOnline( Boolean.FALSE );
           }
           else
           {
  -            getContext().setOnline( Boolean.TRUE );
  +            getRootContext().setOnline( Boolean.TRUE );
           }
       }
   
       /**
  +     * Initialize the mavenSession bean.
  +     */
  +    private void initializeMavenSession()
  +    {
  +        // Even though the rootProject contains the rootContext we set both in
  +        // the even that there is no rootProject and the user is requesting goals
  +        // to be attained that do not directly relate to a project. A goaly that
  +        // may, say, generate the skeletal maven application build.
  +
  +        mavenSession = new MavenSession();
  +        mavenSession.setRootContext( getRootContext() );
  +        mavenSession.setRootDescriptorFile( getDescriptorFile() );
  +        mavenSession.addGoalNames( getCli().getArgList() );
  +    }
  +
  +    /**
        * Setup any system properties that have been specified on
        * the CLI.
        */
  @@ -474,7 +440,7 @@
        * Perform main operations in a non-static method.
        *
        * @param args Arguments passed in from main().
  -     * @param fullStart Date the maven process was started.
  +     * @param fullStart Date the mavenSession process was started.
        */
       public void doMain( String[] args, Date fullStart )
       {
  @@ -500,7 +466,7 @@
           }
           catch ( Exception e )
           {
  -            System.err.println( e.getLocalizedMessage() );
  +            e.printStackTrace();
               returnCode = RC_INIT_ERROR;
               done = true;
           }
  @@ -528,21 +494,20 @@
               return;
           }
   
  -        if ( !getCli().hasOption( CONSOLE_BANNER ) )
  +        if ( getCli().hasOption( CONSOLE_BANNER ) == false )
           {
               printConsoleMavenHeader();
               System.out.println();
           }
   
  -        printConsoleProjectHeader( getContext().getProject() );
  +        //printConsoleProjectHeader( project );
           System.out.println();
   
           boolean failed = false;
   
           try
           {
  -            checkOnline();
  -            getContext().getMaven().initialize();
  +            mavenSession.initialize();
   
               if ( getCli().hasOption( DISPLAY_GOALS ) )
               {
  @@ -553,8 +518,7 @@
               }
               else
               {
  -                getContext().getMaven().verifyProject();
  -                getContext().getMaven().attainGoals();
  +                mavenSession.attainGoals();
               }
           }
           catch ( UnsatisfiedDependencyException e )
  @@ -758,14 +722,14 @@
       }
   
       /**
  -     * Prints the Maven header to System.out
  +     * Prints the MavenSession header to System.out
        */
       protected void printConsoleMavenHeader()
       {
           System.out.println( " __  __" );
           System.out.println( "|  \\/  |__ Jakarta _ ___" );
           System.out.println( "| |\\/| / _` \\ V / -_) ' \\  ~ intelligent projects ~" );
  -        System.out.println( "|_|  |_\\__,_|\\_/\\___|_||_|   v. " + org.apache.maven.Maven.APP_VERSION );
  +        System.out.println( "|_|  |_\\__,_|\\_/\\___|_||_|   v. " + org.apache.maven.MavenSession.APP_VERSION );
       }
   
       /**
  @@ -773,10 +737,12 @@
        *
        * @param mavenProject the project the print
        */
  +    /*
       protected void printConsoleProjectHeader( Project mavenProject )
       {
  -        System.out.println( getContext().getDescriptorDirectory() );
  +        System.out.println( getRootContext().getDescriptorDirectory() );
       }
  +    */
   
       /**
        * Display helpful information regarding
  @@ -790,7 +756,7 @@
           System.out.println( format( "", title.length(), '`' ) );
   
   
  -        Set goals = getContext().getPluginManager().getGoalNames();
  +        Set goals = mavenSession.getAllGoalNames();
   
           List list = new ArrayList( goals );
   
  @@ -806,7 +772,6 @@
           };
           Collections.sort( list, comparator );
   
  -
           int wrapIndent = 30;
           String msgPrefix = "";
           boolean hasDesc = false;
  @@ -817,7 +782,7 @@
           for ( Iterator i = list.iterator(); i.hasNext(); )
           {
               String goalName = (String) i.next(); // goal name
  -            String goalDescription = getContext().getPluginManager().getGoalDescription( goalName );
  +            String goalDescription = mavenSession.getGoalDescription( goalName );
   
               StringTokenizer st = new StringTokenizer( goalName, ":" );
               String pluginName = st.nextToken(); //ex. java
  @@ -953,7 +918,7 @@
           {
               String goalName = (String) i.next();
   
  -            String goalDescription = getContext().getPluginManager().getGoalDescription( goalName );
  +            String goalDescription = mavenSession.getGoalDescription( goalName );
   
               boolean hasDesc = false;
   
  @@ -1096,7 +1061,7 @@
       }
   
       /**
  -     * Main CLI entry point for Maven.
  +     * Main CLI entry point for MavenSession.
        *
        * @param args CLI arguments.
        */
  
  
  
  1.5       +8 -8      jakarta-turbine-maven/src/java/org/apache/maven/cli/CLIManager.java
  
  Index: CLIManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/cli/CLIManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CLIManager.java	27 Dec 2002 18:15:00 -0000	1.4
  +++ CLIManager.java	31 Dec 2002 07:02:47 -0000	1.5
  @@ -26,12 +26,12 @@
    *    if and wherever such third-party acknowledgments normally appear.
    *
    * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Maven" must not be used to endorse or promote products
  + *    "Apache MavenSession" 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",
  - *    "Apache Maven", nor may "Apache" appear in their name, without
  + *    "Apache MavenSession", nor may "Apache" appear in their name, without
    *    prior written permission of the Apache Software Foundation.
    *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  @@ -58,18 +58,18 @@
   
   import org.apache.commons.cli.CommandLine;
   import org.apache.commons.cli.CommandLineParser;
  +import org.apache.commons.cli.CommandLineParserFactory;
   import org.apache.commons.cli.HelpFormatter;
   import org.apache.commons.cli.OptionBuilder;
   import org.apache.commons.cli.Options;
   import org.apache.commons.cli.ParseException;
  -import org.apache.commons.cli.PosixParser;
   import org.apache.env.Which;
   
  -/** Utility for managing and parsing Maven's command-line.
  +/** Utility for managing and parsing MavenSession's command-line.
    *
    *  <p>
    *  <b>implementation note:</b> This is the class to modify when
  - *  adding, removing or modifying Maven's command-line options
  + *  adding, removing or modifying MavenSession's command-line options
    *  and flags.
    *  </p>
    *
  @@ -85,7 +85,7 @@
   public class CLIManager
   {
   
  -    /** Maven't command-line option configuration. */
  +    /** MavenSession't command-line option configuration. */
       private static Options options = null;
   
       /** Configure the option set. */
  @@ -183,7 +183,7 @@
        */
       public static CommandLine parse( String[] args ) throws ParseException
       {
  -        CommandLineParser parser = new PosixParser();
  +        CommandLineParser parser = CommandLineParserFactory.newParser();
           return parser.parse( options, args );
       }
   
  @@ -203,7 +203,7 @@
   
       /** Display system information. This is generally useful, maybe
        *  this could be made part of CLI? But it definitely shouldn't
  -     *  be stuck in Maven.
  +     *  be stuck in MavenSession.
        */
       public static void displayInfo()
       {