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/11/30 18:17:48 UTC

cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/app Maven.java

jvanzyl     2002/11/30 09:17:48

  Modified:    src/java/org/apache/maven/app Maven.java
  Log:
  refactoring
  
  Revision  Changes    Path
  1.144     +76 -252   jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java
  
  Index: Maven.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java,v
  retrieving revision 1.143
  retrieving revision 1.144
  diff -u -r1.143 -r1.144
  --- Maven.java	27 Nov 2002 01:24:00 -0000	1.143
  +++ Maven.java	30 Nov 2002 17:17:47 -0000	1.144
  @@ -60,7 +60,6 @@
   import com.werken.werkz.Session;
   import org.apache.commons.grant.GrantProject;
   import org.apache.commons.jelly.JellyContext;
  -import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.tags.ant.AntTagLibrary;
   import org.apache.commons.jelly.tags.jeez.JeezTagLibrary;
   import org.apache.commons.jelly.tags.werkz.JellyBuildListener;
  @@ -101,9 +100,6 @@
    *       during compilation.
    * @todo Remove any notions of the filesystem. This should strictly be
    *       a logical entity for building projects.
  - * @todo Maven should be given an live instance of a Project object. Any
  - *       logic like checking for the existance of a project.xml file and
  - *       it's size should be moved to the CLI wrapper.
    * @todo Use the context to pass information into Maven. We will consider
    *       Maven a component and pass the information into Maven using a
    *       context a la Avalon.
  @@ -142,9 +138,6 @@
       // I N S T A N C E  M E M B E R S
       // ------------------------------------------------------------
   
  -    /** ${maven.home}/ directory. */
  -    private File mavenHome;
  -
       /** Project directory. */
       private File dir;
   
  @@ -158,25 +151,7 @@
       private Project project;
   
       /** Jelly conext. */
  -    private MavenJellyContext jellyContext;
  -
  -    /** The Ant project. */
  -    private GrantProject antProject;
  -
  -    /** Weriz project. */
  -    private com.werken.werkz.Project werkzProject;
  -
  -    /** Jelly's output. */
  -    private XMLOutput output;
  -
  -    /** Set debugging. */
  -    private boolean isDebug;
  -
  -    /** Plugin Manager */
  -    private PluginManager pluginManager;
  -
  -    /** Project verifier */
  -    private ProjectVerifier projectVerifier;
  +    private MavenJellyContext context;
   
       /** Produce logging information without adornments */
       private boolean emacsMode = false;
  @@ -188,8 +163,6 @@
       /** Default Constructor. */
       public Maven()
       {
  -        this.werkzProject = new com.werken.werkz.Project();
  -        this.pluginManager = new PluginManager();
           this.goalNames = new ArrayList( 3 );
       }
   
  @@ -252,11 +225,14 @@
   
       /** Retrieve the Ant project.
        *
  +     * NOTE: public for xdoc plugin, can be reverted to private when
  +     * dvsl is replaced.
  +     *
        *  @return The ant project.
        */
  -    private GrantProject getAntProject()
  +    public GrantProject getAntProject()
       {
  -        return antProject;
  +        return getContext().getAntProject();
       }
   
       /**
  @@ -266,25 +242,7 @@
        */
       private void setAntProject( GrantProject antProject )
       {
  -        this.antProject = antProject;
  -    }
  -
  -    /** Retrieve the Ant project.
  -     *
  -     *  @return The ant project.
  -     */
  -    public org.apache.tools.ant.Project getBaseAntProject()
  -    {
  -        return antProject;
  -    }
  -
  -    /**
  -     * retrieve the werkz project object
  -     * @return the {@link com.werken.werkz.Project Werkz Project}
  -     */
  -    public com.werken.werkz.Project getWerkzProject()
  -    {
  -        return werkzProject;
  +        getContext().setAntProject( antProject );
       }
   
       /** Set the project directory.
  @@ -294,12 +252,12 @@
       public void setDir( File dir )
       {
           this.dir = dir;
  -        
  +
           if (dir != null)
           {
               System.setProperty( "user.dir", dir.getPath() );
               setProjectBuildFile( new File( dir, PROJECT_BUILD_FILE_NAME ) );
  -        }            
  +        }
       }
   
       /** Retrieve the project directory.
  @@ -316,24 +274,6 @@
           return this.dir;
       }
   
  -    /** Set the ${maven.home} directory.
  -     *
  -     *  @param mavenHome The ${maven.home} directory.
  -     */
  -    public void setMavenHome( File mavenHome )
  -    {
  -        this.mavenHome = mavenHome;
  -    }
  -
  -    /** Retrieve the ${maven.home} directory.
  -     *
  -     *  @return The ${maven.home} directory.
  -     */
  -    public File getMavenHome()
  -    {
  -        return this.mavenHome;
  -    }
  -
       /** Retrieve the list of goal names.
        *
        *  @return The list of goal names.
  @@ -381,7 +321,7 @@
        */
       public void setContext( MavenJellyContext jellyContext )
       {
  -        this.jellyContext = jellyContext;
  +        this.context = jellyContext;
       }
   
       /** Retrieve the Jelly context.
  @@ -390,68 +330,7 @@
        */
       public MavenJellyContext getContext()
       {
  -        return jellyContext;
  -    }
  -
  -    /** Retrieve the XML execution output sink.
  -     *
  -     *  @return The output sink.
  -     */
  -    public XMLOutput getXMLOutput()
  -    {
  -        return this.output;
  -    }
  -
  -    /**
  -     * Set the XMLOutput used by Jelly
  -     *
  -     * @param output XMLOutput to use.
  -     * @param isDebug Debugging flag.
  -     */
  -    public void setXMLOutput( XMLOutput output, boolean isDebug )
  -    {
  -        this.output = output;
  -        this.isDebug = isDebug;
  -    }
  -
  -    /**
  -     * Determine whether debugging is on/off
  -     *
  -     * @return boolean
  -     */
  -    public boolean isDebug()
  -    {
  -        return this.isDebug;
  -    }
  -
  -    /**
  -     * Set the project verifier.
  -     *
  -     * @param projectVerifier Maven project verifier.
  -     */
  -    public void setProjectVerifier( ProjectVerifier projectVerifier )
  -    {
  -        this.projectVerifier = projectVerifier;
  -    }
  -
  -    /**
  -     * Get the project verifier.
  -     *
  -     * @return Maven project verifier.
  -     */
  -    public ProjectVerifier getProjectVerifier()
  -    {
  -        return projectVerifier;
  -    }
  -
  -    /**
  -     * Get the plugin manager.
  -     *
  -     * @return Maven plugin manager.
  -     */
  -    public PluginManager getPluginManager()
  -    {
  -        return this.pluginManager;
  +        return context;
       }
   
       /**
  @@ -474,41 +353,61 @@
           return emacsMode;
       }
   
  -    /**
  -     * Retrieve all property names.
  -     *
  -     * @return an Iterator over the current property names in this context
  -     */
  -    public Iterator getPropertyNames()
  -    {
  -        return getContext().getVariableNames();
  -    }
  +    // ------------------------------------------------------------
  +    // I M P L E M E N T A T I O N
  +    // ------------------------------------------------------------
   
  -    /**
  -     * Set a variable in the jelly context.
  +    /** Perform pre-build initialization.
        *
  -     * @param name Name of variable.
  -     * @param value Value of variable.
  +     *  @throws Exception If an error occurs while performing
  +     *          runtime initialization.
        */
  -    public void setVariable( String name, Object value )
  +    public void initialize()
  +        throws Exception
       {
  -        getContext().setVariable( name, value );
  +
  +        initializeAnt();
  +        initializeJelly();
  +        initializeTagLibs();
  +        initializeDriver();
  +
  +        // Create the dependency classpath for this plugin so that the
  +        // values can be made available in the plugin.jelly script.
  +        CreateDependencyClasspath cdc = new CreateDependencyClasspath();
  +        cdc.setRefid( "maven.dependency.classpath" );
  +        cdc.setMavenProject( getProject() );
  +        cdc.setContext( getContext() );
  +        cdc.execute();
  +
  +        ProjectVerifier projectVerifier = new ProjectVerifier();
  +        projectVerifier.setContext( getContext() );
  +        getContext().setProjectVerifier( projectVerifier );
  +        initializePlugins();
  +        loadProjectBuildFile();
       }
   
       /**
  -     * Get a variable from the jelly context.
  -     *
  -     * @param key Key for object to retrieve from maven jelly context.
  -     * @return Object from the maven jelly context.
  +     * Initialize Ant.
        */
  -    public Object getVariable( String key )
  +    private void initializeAnt()
       {
  -        return getContext().getVariable( key );
  -    }
   
  -    // ------------------------------------------------------------
  -    // I M P L E M E N T A T I O N
  -    // ------------------------------------------------------------
  +        setAntProject( new GrantProject() );
  +
  +        getAntProject().setPropsHandler( new JellyPropsHandler( getContext() ) );
  +        getAntProject().init();
  +        getAntProject().setBaseDir( getDir() );
  +        getAntProject().getBaseDir();
  +
  +        PrintStream demuxOut =
  +            new PrintStream( new DemuxOutputStream( getAntProject(), false ) );
  +
  +        PrintStream demuxErr =
  +            new PrintStream( new DemuxOutputStream( getAntProject(), true ) );
  +
  +        System.setOut( demuxOut );
  +        System.setErr( demuxErr );
  +    }
   
       /**
        * Initialize Jelly.
  @@ -519,7 +418,8 @@
           throws Exception
       {
           getContext().setVariable( MavenConstants.MAVEN_OBJECT, this );
  -        getContext().setVariable( MavenConstants.WERKZ_PROJECT, getWerkzProject() );
  +        getContext().setWerkzProject ( new com.werken.werkz.Project() );
  +        getContext().setProject( getProject() );
   
           if ( hasProjectBuildFile() )
           {
  @@ -527,9 +427,8 @@
                                         getProjectBuildFile().toURL() );
           }
   
  -        JellyBuildListener listener = new JellyBuildListener( output );
  -
  -        listener.isDebug( isDebug );
  +        JellyBuildListener listener = new JellyBuildListener( getContext().getXMLOutput() );
  +        listener.isDebug( getContext().getDebugOn().booleanValue() );
           listener.setEmacsMode( emacsMode );
   
           getAntProject().addBuildListener( listener );
  @@ -551,60 +450,6 @@
       }
   
       /**
  -     * Initialize Ant.
  -     */
  -    private void initializeAnt()
  -    {
  -        setAntProject( new GrantProject() );
  -
  -        getAntProject().setPropsHandler( new JellyPropsHandler( getContext() ) );
  -
  -        getContext().setVariable( MavenConstants.MAVEN_ANT_PROJECT, antProject );
  -
  -        getAntProject().init();
  -        getAntProject().setBaseDir( getDir() );
  -        getAntProject().getBaseDir();
  -
  -        PrintStream demuxOut =
  -            new PrintStream( new DemuxOutputStream( getAntProject(), false ) );
  -
  -        PrintStream demuxErr =
  -            new PrintStream( new DemuxOutputStream( getAntProject(), true ) );
  -
  -        System.setOut( demuxOut );
  -        System.setErr( demuxErr );
  -
  -        getContext().setVariable( MavenConstants.MAVEN_ANT_PROJECT, antProject );
  -    }
  -
  -    /** Perform pre-build initialization.
  -     *
  -     *  @throws Exception If an error occurs while performing
  -     *          runtime initialization.
  -     */
  -    public void runtimeInitialization()
  -        throws Exception
  -    {
  -
  -        initializeAnt();
  -        initializeJelly();
  -        initializeTagLibs();
  -        initializeDriver();
  -
  -        // Create the dependency classpath for this plugin so that the
  -        // values can be made available in the plugin.jelly script.
  -        CreateDependencyClasspath cdc = new CreateDependencyClasspath();
  -        cdc.setRefid( "maven.dependency.classpath" );
  -        cdc.setMavenProject( getProject() );
  -        cdc.setContext( getContext() );
  -        cdc.execute();
  -
  -        createProjectVerifier();
  -        initializePlugins();
  -        loadProjectBuildFile();
  -    }
  -
  -    /**
        * Return an InputStream found in the classpath. Used
        *  specifically to find resources stored in the maven.jar
        *
  @@ -627,14 +472,12 @@
       private void initializeDriver()
           throws Exception
       {
  -        getContext().setVariable( MavenConstants.MAVEN_POM, getProject() );
  -
           InputStream driverInputStream = getResourceAsStream( DRIVER_SCRIPT_NAME );
   
           JellyUtils.runScript( driverInputStream,
                                 null,
                                 getContext(),
  -                              getXMLOutput() );
  +                              getContext().getXMLOutput() );
       }
   
       /** Initialize all plugins.
  @@ -645,12 +488,11 @@
       private void initializePlugins()
           throws Exception
       {
  -        pluginManager.setMavenHome( getMavenHome() );
  -        pluginManager.setAntProject( getAntProject() );
  +        PluginManager pluginManager = new PluginManager();
           pluginManager.setContext( getContext() );
  -        pluginManager.setXMLOutput( getXMLOutput() );
  -        pluginManager.setProjectVerifier( getProjectVerifier() );
  -        pluginManager.initializePlugins();
  +        pluginManager.initialize();
  +
  +        getContext().setPluginManager( pluginManager );
       }
   
       /**
  @@ -659,20 +501,6 @@
        * @return ProjectVerifier An initialized project verifier.
        * @throws Exception If an error occurs while creating the project verifier.
        */
  -    private ProjectVerifier createProjectVerifier()
  -        throws Exception
  -    {
  -        projectVerifier = new ProjectVerifier();
  -        projectVerifier.setContext( getContext() );
  -        Boolean online = (Boolean) getVariable( MavenConstants.ONLINE );
  -
  -        if ( online != null && !online.booleanValue() )
  -        {
  -            projectVerifier.setOnline( false );
  -        }
  -
  -        return projectVerifier;
  -    }
   
       /**
        * Verify a project. Basically make sure the dependencies are
  @@ -683,8 +511,7 @@
       public void verifyProject()
           throws Exception
       {
  -        projectVerifier.setMavenProject( getProject() );
  -        getProjectVerifier().doExecute();
  +        getContext().getProjectVerifier().execute();
       }
   
       /** Run maven.
  @@ -697,11 +524,8 @@
           try
           {
               INSTANCES.push( this );
  -
               JellyContext context = getContext();
  -
  -            context.setVariable( MavenConstants.MAVEN_GOALS, getGoalNames() );
  -
  +            getContext().setVariable( MavenConstants.MAVEN_GOALS, getGoalNames() );
               runGoals( goalNames );
           }
           finally
  @@ -725,7 +549,7 @@
               return;
           }
   
  -        getPluginManager().loadProjectBuildFile( projectBuildFile );
  +        getContext().getPluginManager().loadProjectBuildFile( projectBuildFile );
       }
   
       /** Attain the goals.
  @@ -742,7 +566,7 @@
       {
           if ( goalNames.isEmpty() )
           {
  -            String defaultGoalName = getWerkzProject().getDefaultGoalName();
  +            String defaultGoalName = getContext().getWerkzProject().getDefaultGoalName();
   
               if ( defaultGoalName != null )
               {
  @@ -750,7 +574,7 @@
               }
               else
               {
  -                goalNames.add( getVariable( DEFAULT_GOAL ) );
  +                goalNames.add( getContext().getVariable( DEFAULT_GOAL ) );
               }
           }
   
  @@ -758,9 +582,9 @@
           {
               String eachGoalName = (String) i.next();
   
  -            getPluginManager().prepForGoal( eachGoalName );
  +            getContext().getPluginManager().prepForGoal( eachGoalName );
   
  -            Goal eachGoal = getWerkzProject().getGoal( eachGoalName );
  +            Goal eachGoal = getContext().getWerkzProject().getGoal( eachGoalName );
   
               if ( eachGoal == null )
               {
  @@ -768,21 +592,21 @@
               }
           }
   
  -        Session session = new JellySession( output );
  +        Session session = new JellySession( getContext().getXMLOutput() );
           Thread.currentThread().setContextClassLoader( null );
   
           for ( Iterator i = goalNames.iterator(); i.hasNext(); )
           {
               String eachGoalName = (String) i.next();
   
  -            Goal eachGoal = werkzProject.getGoal( eachGoalName );
  +            Goal eachGoal = getContext().getWerkzProject().getGoal( eachGoalName );
   
               if ( eachGoal == null )
               {
                   if ( !eachGoalName.startsWith( "maven:" ) )
                   {
                       eachGoalName = "maven:" + eachGoalName;
  -                    eachGoal = werkzProject.getGoal( eachGoalName );
  +                    eachGoal = getContext().getWerkzProject().getGoal( eachGoalName );
                   }
               }