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 


git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-24 17:45:00 +00:00
parent ace03b781b
commit 52c9295a42
4 changed files with 88 additions and 33 deletions

View File

@ -188,14 +188,53 @@ public class DefaultLifecycleExecutor
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 );
@ -263,38 +302,22 @@ public class DefaultLifecycleExecutor
}
}
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 @@ public class DefaultLifecycleExecutor
project.addPlugin( plugin );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
return mojoDescriptor;
}

View File

@ -25,6 +25,7 @@ import org.apache.maven.BuildFailureException;
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 @@ public interface LifecycleExecutor
{
List<String> getLifecyclePhases();
List<MojoDescriptor> calculateLifecyclePlan( String task, MavenSession session )
throws LifecycleExecutionException;
void execute( MavenSession session )
throws LifecycleExecutionException, BuildFailureException;
}

View File

@ -172,9 +172,6 @@ public class DefaultPluginManager
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 )

View File

@ -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;
@ -74,6 +73,37 @@ public class LifecycleExecutorTest
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()