You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2009/03/24 18:45:03 UTC
svn commit: r757922 - in /maven/components/branches/MNG-2766/maven-core/src:
main/java/org/apache/maven/lifecycle/ main/java/org/apache/maven/plugin/
test/java/org/apache/maven/lifecycle/
Author: jvanzyl
Date: Tue Mar 24 17:45:00 2009
New Revision: 757922
URL: http://svn.apache.org/viewvc?rev=757922&view=rev
Log:
o i can now in a simple way get the lifecycle plan for a particular task
o the tests need to be simplified, possibly use the jxpath technique to make the test more concise
o the API still needs some work, and we still need to be able to adapt the lifecycle in context -- my particular use case is running inside eclipse and essentially disabling all but what is required to run inside eclipse. we don't need to compile, test or package for example
Modified:
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=757922&r1=757921&r2=757922&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Tue Mar 24 17:45:00 2009
@@ -187,15 +187,54 @@
// if NEVER, don't blacklist
return false;
}
+
+ private void executeGoal( String task, MavenSession session, MavenProject project )
+ throws LifecycleExecutionException, BuildFailureException
+ {
+ List<MojoDescriptor> lifecyclePlan = calculateLifecyclePlan( task, session );
+
+ for( MojoDescriptor md : lifecyclePlan )
+ {
+ System.out.println( md.getFullGoalName() );
+ }
+
+ /*
+ for ( MojoExecution mojoExecution : goals )
+ {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+ try
+ {
+ pluginManager.executeMojo( project, mojoExecution, session );
+ }
+ catch ( PluginManagerException e )
+ {
+ throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" + mojoDescriptor.getId() + "': " + e.getMessage(), e );
+ }
+ catch ( MojoFailureException e )
+ {
+ throw new BuildFailureException( e.getMessage(), e );
+ }
+ catch ( PluginConfigurationException e )
+ {
+ throw new LifecycleExecutionException( e.getMessage(), e );
+ }
+ }
+ */
+
+ }
// 1. Find the lifecycle given the phase (default lifecycle when given install)
// 2. Find the lifecycle mapping that corresponds to the project packaging (jar lifecycle mapping given the jar packaging)
// 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle)
// 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle
// 5. Bind mojos specified in the project itself to the lifecycle
- private void executeGoal( String task, MavenSession session, MavenProject project )
- throws LifecycleExecutionException, BuildFailureException
+ public List<MojoDescriptor> calculateLifecyclePlan( String task, MavenSession session )
+ throws LifecycleExecutionException
{
+ // Extract the project from the session
+ MavenProject project = session.getCurrentProject();
+
// 1.
Lifecycle lifecycle = phaseToLifecycleMap.get( task );
@@ -262,39 +301,23 @@
}
}
}
-
+
+ List<MojoDescriptor> lifecyclePlan = new ArrayList<MojoDescriptor>();
+
// We need to turn this into a set of MojoExecutions
for( List<String> mojos : phaseToMojoMapping.values() )
{
for( String mojo : mojos )
{
- System.out.println( ">> " + mojo );
+ // These are bits that look like this:
+ //
+ // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
+ //
+ lifecyclePlan.add( getMojoDescriptor( mojo, session, project ) );
}
- }
+ }
- /*
- for ( MojoExecution mojoExecution : goals )
- {
- MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
-
- try
- {
- pluginManager.executeMojo( project, mojoExecution, session );
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" + mojoDescriptor.getId() + "': " + e.getMessage(), e );
- }
- catch ( MojoFailureException e )
- {
- throw new BuildFailureException( e.getMessage(), e );
- }
- catch ( PluginConfigurationException e )
- {
- throw new LifecycleExecutionException( e.getMessage(), e );
- }
- }
- */
+ return lifecyclePlan;
}
//TODO: which form is most useful. passing in string to parse is not really good.
@@ -392,6 +415,7 @@
project.addPlugin( plugin );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
+
return mojoDescriptor;
}
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=757922&r1=757921&r2=757922&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java Tue Mar 24 17:45:00 2009
@@ -25,6 +25,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.monitor.event.EventDispatcher;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
/**
@@ -34,6 +35,9 @@
{
List<String> getLifecyclePhases();
+ List<MojoDescriptor> calculateLifecyclePlan( String task, MavenSession session )
+ throws LifecycleExecutionException;
+
void execute( MavenSession session )
throws LifecycleExecutionException, BuildFailureException;
}
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=757922&r1=757921&r2=757922&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Tue Mar 24 17:45:00 2009
@@ -172,9 +172,6 @@
project.addPlugin( plugin );
- System.out.println( "AAA loading plugin " + pluginDescriptor.getArtifactId() + ":" + pluginDescriptor.getVersion() );
- System.out.println( "BBB realm: " + pluginDescriptor.getClassRealm() );
-
return pluginDescriptor;
}
catch ( ArtifactResolutionException e )
Modified: maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java?rev=757922&r1=757921&r2=757922&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java Tue Mar 24 17:45:00 2009
@@ -1,7 +1,6 @@
package org.apache.maven.lifecycle;
import java.io.File;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@@ -73,7 +72,38 @@
public void testLifecycleQueryingUsingADefaultLifecyclePhase()
throws Exception
- {
+ {
+ // This stuff all needs to be reduced, reduced, reduced
+ String base = "projects/lifecycle-executor/project-with-additional-lifecycle-elements";
+ File sourceDirectory = new File( getBasedir(), "src/test/" + base );
+ File targetDirectory = new File( getBasedir(), "target/" + base );
+ FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
+ File targetPom = new File( targetDirectory, "pom.xml" );
+ MavenSession session = createMavenSession( targetPom );
+ assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
+ assertEquals( "1.0-SNAPSHOT", session.getCurrentProject().getVersion() );
+ // So this is wrong if we already have the session, which contains a request, which in turn contains
+ // the goals we are trying to run
+
+ List<MojoDescriptor> lifecyclePlan = lifecycleExecutor.calculateLifecyclePlan( "package", session );
+
+ // resources:resources
+ // compiler:compile
+ // plexus-component-metadata:generate-metadata
+ // resources:testResources
+ // compiler:testCompile
+ // plexus-component-metadata:generate-test-metadata
+ // surefire:test
+ // jar:jar
+
+ assertEquals( "resources:resources", lifecyclePlan.get( 0 ).getFullGoalName() );
+ assertEquals( "compiler:compile", lifecyclePlan.get( 1 ).getFullGoalName() );
+ assertEquals( "plexus-component-metadata:generate-metadata", lifecyclePlan.get( 2 ).getFullGoalName() );
+ assertEquals( "resources:testResources", lifecyclePlan.get( 3 ).getFullGoalName() );
+ assertEquals( "compiler:testCompile", lifecyclePlan.get( 4 ).getFullGoalName() );
+ assertEquals( "plexus-component-metadata:generate-test-metadata", lifecyclePlan.get( 5 ).getFullGoalName() );
+ assertEquals( "surefire:test", lifecyclePlan.get( 6 ).getFullGoalName() );
+ assertEquals( "jar:jar", lifecyclePlan.get( 7 ).getFullGoalName() );
}
public void testLifecycleExecutionUsingADefaultLifecyclePhase()