jvanzyl     2004/04/05 09:28:25

  Modified:    maven-core/src/main/java/org/apache/maven DefaultMaven.java
                        Maven.java MavenCommandLineFrontEnd.java
               maven-core/src/main/java/org/apache/maven/lifecycle
                        MavenLifecycleContext.java
               maven-core/src/main/java/org/apache/maven/lifecycle/phase
                        GoalAttainmentPhase.java
               maven-core/src/main/resources/org/apache/maven plexus.xml
               maven-core/src/test/java/org/apache/maven/plugin
                        PluginTest.java
  Log:
  hook in the maven lifecycle manager
  
  Revision  Changes    Path
  1.15      +33 -13    
maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
  
  Index: DefaultMaven.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DefaultMaven.java 5 Apr 2004 16:01:31 -0000       1.14
  +++ DefaultMaven.java 5 Apr 2004 16:28:24 -0000       1.15
  @@ -16,13 +16,19 @@
    * limitations under the License.
    */
   
  -import org.apache.maven.plugin.PluginExecutionResponse;
  +import org.apache.maven.lifecycle.MavenLifecycleContext;
  +import org.apache.maven.lifecycle.MavenLifecycleManager;
   import org.apache.maven.plugin.descriptor.GoalDescriptor;
   import org.apache.maven.plugin.descriptor.PluginDescriptor;
   import org.apache.maven.plugin.manager.PluginManagerManager;
   import org.apache.maven.project.MavenProject;
   import org.apache.maven.project.MavenProjectBuilder;
   import org.apache.maven.project.ProjectBuildingException;
  +import org.codehaus.plexus.PlexusConstants;
  +import org.codehaus.plexus.PlexusContainer;
  +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
  +import org.codehaus.plexus.context.Context;
  +import org.codehaus.plexus.context.ContextException;
   import org.codehaus.plexus.i18n.I18N;
   
   import java.io.File;
  @@ -30,15 +36,15 @@
   import java.util.Map;
   
   public class DefaultMaven
  -    implements Maven
  +    implements Maven, Contextualizable
   {
       // ----------------------------------------------------------------------
       //
       // ----------------------------------------------------------------------
   
  -    private String mavenHome;
  +    private PlexusContainer container;
   
  -    private String mavenLocalHome;
  +    private String mavenHome;
   
       // ----------------------------------------------------------------------
       // Components
  @@ -46,6 +52,8 @@
   
       private PluginManagerManager pluginManagerManager;
   
  +    private MavenLifecycleManager lifecycleManager;
  +
       private MavenProjectBuilder projectBuilder;
   
       private I18N i18n;
  @@ -54,19 +62,19 @@
       // Goal attainment
       // ----------------------------------------------------------------------
   
  -    public void attainGoal( String goal )
  +    public void execute( String goal )
           throws GoalNotFoundException
       {
  -        attainGoal( (MavenProject) null, goal );
  +        execute( (MavenProject) null, goal );
       }
   
  -    public void attainGoal( File projectFile, String goal )
  +    public void execute( File projectFile, String goal )
           throws ProjectBuildingException,GoalNotFoundException
       {
  -        attainGoal( getProject( projectFile ), goal );
  +        execute( getProject( projectFile ), goal );
       }
   
  -    public void attainGoal( MavenProject project, String goal )
  +    public void execute( MavenProject project, String goal )
           throws GoalNotFoundException
       {
           if ( !getGoalDescriptors().containsKey( goal ) )
  @@ -74,11 +82,13 @@
               throw new GoalNotFoundException( goal );
           }
   
  -        PluginExecutionResponse response = pluginManagerManager.attainGoal( 
project, goal );
  -
  -        if ( response.exceptionOccurred() )
  +        try
  +        {
  +            lifecycleManager.execute( new MavenLifecycleContext( container, 
project, goal ) );
  +        }
  +        catch ( Exception e )
           {
  -            response.getException().printStackTrace();
  +            e.printStackTrace();
           }
       }
   
  @@ -153,6 +163,16 @@
           }
   
           return mavenHome;
  +    }
  +
  +    // ----------------------------------------------------------------------
  +    // Lifecylce Management
  +    // ----------------------------------------------------------------------
  +
  +    public void contextualize( Context context )
  +        throws ContextException
  +    {
  +        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
       }
   }
   
  
  
  
  1.7       +5 -5      
maven-components/maven-core/src/main/java/org/apache/maven/Maven.java
  
  Index: Maven.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/Maven.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Maven.java        4 Apr 2004 17:23:44 -0000       1.6
  +++ Maven.java        5 Apr 2004 16:28:24 -0000       1.7
  @@ -37,16 +37,16 @@
       static String ROLE = Maven.class.getName();
   
       // ----------------------------------------------------------------------
  -    // Goal attainment
  +    // Execution
       // ----------------------------------------------------------------------
   
  -    void attainGoal( String goal )
  +    void execute( String goal )
           throws GoalNotFoundException;
   
  -    void attainGoal( MavenProject project, String goal )
  +    void execute( MavenProject project, String goal )
           throws GoalNotFoundException;
   
  -    void attainGoal( File project, String goal )
  +    void execute( File project, String goal )
           throws ProjectBuildingException,GoalNotFoundException;
   
       // ----------------------------------------------------------------------
  
  
  
  1.2       +2 -2      
maven-components/maven-core/src/main/java/org/apache/maven/MavenCommandLineFrontEnd.java
  
  Index: MavenCommandLineFrontEnd.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenCommandLineFrontEnd.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MavenCommandLineFrontEnd.java     4 Apr 2004 17:23:44 -0000       1.1
  +++ MavenCommandLineFrontEnd.java     5 Apr 2004 16:28:24 -0000       1.2
  @@ -85,7 +85,7 @@
   
           for ( Iterator i = commandLine.getArgList().iterator(); i.hasNext(); )
           {
  -            maven.attainGoal( projectFile, (String) i.next() );
  +            maven.execute( projectFile, (String) i.next() );
           }
       }
   
  
  
  
  1.3       +7 -6      
maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java
  
  Index: MavenLifecycleContext.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MavenLifecycleContext.java        5 Apr 2004 16:01:31 -0000       1.2
  +++ MavenLifecycleContext.java        5 Apr 2004 16:28:24 -0000       1.3
  @@ -2,6 +2,7 @@
   
   import org.apache.maven.Maven;
   import org.apache.maven.project.MavenProject;
  +import org.codehaus.plexus.PlexusContainer;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  @@ -9,24 +10,24 @@
    */
   public class MavenLifecycleContext
   {
  -    private Maven maven;
  +    private PlexusContainer container;
   
       private MavenProject project;
   
       private String goal;
   
  -    public MavenLifecycleContext( Maven maven, MavenProject project, String goal )
  +    public MavenLifecycleContext( PlexusContainer container, MavenProject project, 
String goal )
       {
  -        this.maven = maven;
  +        this.container = container;
   
           this.project = project;
   
           this.goal = goal;
       }
   
  -    public Maven getMaven()
  +    public PlexusContainer getContainer()
       {
  -        return maven;
  +        return container;
       }
   
       public MavenProject getProject()
  
  
  
  1.2       +11 -1     
maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalAttainmentPhase.java
  
  Index: GoalAttainmentPhase.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalAttainmentPhase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GoalAttainmentPhase.java  5 Apr 2004 15:41:46 -0000       1.1
  +++ GoalAttainmentPhase.java  5 Apr 2004 16:28:24 -0000       1.2
  @@ -2,6 +2,8 @@
   
   import org.apache.maven.lifecycle.AbstractMavenLifecyclePhase;
   import org.apache.maven.lifecycle.MavenLifecycleContext;
  +import org.apache.maven.plugin.PluginExecutionResponse;
  +import org.apache.maven.plugin.manager.PluginManagerManager;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  @@ -13,5 +15,13 @@
       public void execute( MavenLifecycleContext context )
           throws Exception
       {
  +        PluginManagerManager pmm = (PluginManagerManager) 
context.getContainer().lookup( PluginManagerManager.ROLE );
  +
  +        PluginExecutionResponse response = pmm.attainGoal( context.getProject(), 
context.getGoal() );
  +
  +        if ( response.exceptionOccurred() )
  +        {
  +            response.getException().printStackTrace();
  +        }
       }
   }
  
  
  
  1.6       +3 -0      
maven-components/maven-core/src/main/resources/org/apache/maven/plexus.xml
  
  Index: plexus.xml
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/main/resources/org/apache/maven/plexus.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- plexus.xml        5 Apr 2004 15:41:46 -0000       1.5
  +++ plexus.xml        5 Apr 2004 16:28:24 -0000       1.6
  @@ -34,6 +34,9 @@
           <requirement>
             <role>org.codehaus.plexus.i18n.I18N</role>
           </requirement>
  +        <requirement>
  +          <role>org.apache.maven.lifecycle.MavenLifecycleManager</role>
  +        </requirement>
         </requirements>
       </component>
       <component>
  
  
  
  1.4       +5 -5      
maven-components/maven-core/src/test/java/org/apache/maven/plugin/PluginTest.java
  
  Index: PluginTest.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/plugin/PluginTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginTest.java   5 Apr 2004 15:41:46 -0000       1.3
  +++ PluginTest.java   5 Apr 2004 16:28:25 -0000       1.4
  @@ -72,7 +72,7 @@
   
           Maven maven = (Maven) lookup( Maven.ROLE );
   
  -        maven.attainGoal( new File( System.getProperty( "user.dir"), "project.xml" 
), "integrated-execute" );
  +        maven.execute( new File( System.getProperty( "user.dir"), "project.xml" ), 
"integrated-execute" );
   
           IntegratedPlugin integratedPlugin = (IntegratedPlugin) 
getContainer().lookup( Plugin.ROLE, "integrated-plugin" );
   
  @@ -92,7 +92,7 @@
   
           Maven maven = (Maven) lookup( Maven.ROLE );
   
  -        maven.attainGoal( new File( System.getProperty( "user.dir"), "project.xml" 
), "singleton-execute" );
  +        maven.execute( new File( System.getProperty( "user.dir"), "project.xml" ), 
"singleton-execute" );
   
           SingletonPlugin singletonPlugin = (SingletonPlugin) getContainer().lookup( 
Plugin.ROLE, "singleton-plugin" );
   
  @@ -112,7 +112,7 @@
   
           Maven maven = (Maven) lookup( Maven.ROLE );
   
  -        maven.attainGoal( new File( System.getProperty( "user.dir"), "project.xml" 
), "setter-execute" );
  +        maven.execute( new File( System.getProperty( "user.dir"), "project.xml" ), 
"setter-execute" );
   
           // Now the goal has been attain, but because the instantiation strategy is 
per-lookup
           // We can't get the plugin object that executed. So we've made a little 
class called
  @@ -135,7 +135,7 @@
   
           Maven maven = (Maven) lookup( Maven.ROLE );
   
  -        maven.attainGoal( new File( System.getProperty( "user.dir"), "project.xml" 
), "field-execute" );
  +        maven.execute( new File( System.getProperty( "user.dir"), "project.xml" ), 
"field-execute" );
   
           // Now the goal has been attain, but because the instantiation strategy is 
per-lookup
           // We can't get the plugin object that executed. So we've made a little 
class called
  
  
  

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

Reply via email to