o adding capability to the lifecycle executor to merge in executions which contain

configurations for external plugins. in this particular i've made the adjustments
  so that the corbertura plugin can tell the surefire plugin to fork. not ideal, but
  it will work until we figure out a more elegant solution.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@356065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2005-12-11 23:35:47 +00:00
parent b9c5816ba9
commit db17a2494b
3 changed files with 102 additions and 19 deletions

View File

@ -57,6 +57,7 @@
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.util.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -496,9 +497,9 @@ private void executeGoals( List goals, Stack forkEntryPoints, MavenSession sessi
if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null ) if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
{ {
forkEntryPoints.push( mojoDescriptor ); forkEntryPoints.push( mojoDescriptor );
forkLifecycle( mojoDescriptor, forkEntryPoints, session, project ); forkLifecycle( mojoDescriptor, forkEntryPoints, session, project );
forkEntryPoints.pop(); forkEntryPoints.pop();
} }
@ -516,9 +517,9 @@ private void executeGoals( List goals, Stack forkEntryPoints, MavenSession sessi
if ( descriptor.getExecutePhase() != null ) if ( descriptor.getExecutePhase() != null )
{ {
forkEntryPoints.push( descriptor ); forkEntryPoints.push( descriptor );
forkLifecycle( descriptor, forkEntryPoints, session, project ); forkLifecycle( descriptor, forkEntryPoints, session, project );
forkEntryPoints.pop(); forkEntryPoints.pop();
} }
} }
@ -733,7 +734,7 @@ private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, Stack forkEntr
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{ {
forkEntryPoints.push( mojoDescriptor ); forkEntryPoints.push( mojoDescriptor );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
String targetPhase = mojoDescriptor.getExecutePhase(); String targetPhase = mojoDescriptor.getExecutePhase();
@ -780,11 +781,67 @@ private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, Stack forkEntr
for ( Iterator k = e.getGoals().iterator(); k.hasNext(); ) for ( Iterator k = e.getGoals().iterator(); k.hasNext(); )
{ {
String goal = (String) k.next(); String goal = (String) k.next();
MojoDescriptor desc = getMojoDescriptor( pluginDescriptor, goal );
PluginDescriptor lifecyclePluginDescriptor;
String lifecycleGoal;
// Here we are looking to see if we have a mojo from an external plugin.
// If we do then we need to lookup the plugin descriptor for the externally
// referenced plugin so that we can overly the execution into the lifecycle.
// An example of this is the corbertura plugin that needs to call the surefire
// plugin in forking mode.
//
//<phase>
// <id>test</id>
// <executions>
// <execution>
// <goals>
// <goal>org.apache.maven.plugins:maven-surefire-plugin:test</goal>
// </goals>
// <configuration>
// <classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
// <ignoreFailures>true</ignoreFailures>
// <forkMode>once</forkMode>
// </configuration>
// </execution>
// </executions>
//</phase>
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
if ( goal.indexOf( ":" ) > 0 )
{
String[] s = StringUtils.split( goal, ":" );
String groupId = s[0];
String artifactId = s[1];
String externalGoal = s[2];
lifecycleGoal = externalGoal;
try
{
lifecyclePluginDescriptor = pluginManager.getPluginDescriptor( groupId,
artifactId,
project,
session.getSettings(),
session.getLocalRepository() );
}
catch ( Exception ex )
{
throw new LifecycleExecutionException( ex );
}
}
else
{
lifecyclePluginDescriptor = pluginDescriptor;
lifecycleGoal = goal;
}
MojoDescriptor desc = getMojoDescriptor( lifecyclePluginDescriptor, lifecycleGoal );
MojoExecution mojoExecution = new MojoExecution( desc, (Xpp3Dom) e.getConfiguration() ); MojoExecution mojoExecution = new MojoExecution( desc, (Xpp3Dom) e.getConfiguration() );
addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution, addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution, session.getSettings() );
session.getSettings() );
} }
} }
} }
@ -849,23 +906,23 @@ private void removeFromLifecycle( Stack lifecycleForkers, Map lifecycleMappings
for ( Iterator it = lifecycleForkers.iterator(); it.hasNext(); ) for ( Iterator it = lifecycleForkers.iterator(); it.hasNext(); )
{ {
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next(); MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
for ( Iterator lifecycleIterator = lifecycleMappings.values().iterator(); lifecycleIterator.hasNext(); ) for ( Iterator lifecycleIterator = lifecycleMappings.values().iterator(); lifecycleIterator.hasNext(); )
{ {
List tasks = (List) lifecycleIterator.next(); List tasks = (List) lifecycleIterator.next();
boolean removed = false; boolean removed = false;
for ( Iterator taskIterator = tasks.iterator(); taskIterator.hasNext(); ) for ( Iterator taskIterator = tasks.iterator(); taskIterator.hasNext(); )
{ {
MojoExecution execution = (MojoExecution) taskIterator.next(); MojoExecution execution = (MojoExecution) taskIterator.next();
if ( mojoDescriptor.equals( execution.getMojoDescriptor() ) ) if ( mojoDescriptor.equals( execution.getMojoDescriptor() ) )
{ {
taskIterator.remove(); taskIterator.remove();
removed = true; removed = true;
} }
} }
if ( removed ) if ( removed )
{ {
getLogger().warn( getLogger().warn(
@ -1230,8 +1287,7 @@ private void bindExecutionToLifecycle( PluginDescriptor pluginDescriptor, Map ph
} }
} }
private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution, private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution, Settings settings )
Settings settings )
{ {
List goals = (List) lifecycleMappings.get( phase ); List goals = (List) lifecycleMappings.get( phase );
@ -1374,7 +1430,7 @@ else if ( numTokens == 3 || numTokens == 4 )
} }
project.injectPluginManagementInfo( plugin ); project.injectPluginManagementInfo( plugin );
if ( pluginDescriptor == null ) if ( pluginDescriptor == null )
{ {
pluginDescriptor = verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() ); pluginDescriptor = verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() );

View File

@ -137,6 +137,24 @@ public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
return pluginCollector.getPluginDescriptorForPrefix( prefix ); return pluginCollector.getPluginDescriptorForPrefix( prefix );
} }
public PluginDescriptor getPluginDescriptor( String groupId,
String artifactId,
MavenProject project,
Settings settings,
ArtifactRepository localRepository )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
Plugin plugin = new Plugin();
plugin.setGroupId( groupId );
plugin.setArtifactId( artifactId );
String version = pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings, localRepository );
return pluginCollector.getPluginDescriptor( plugin );
}
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
{ {
// TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other // TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other
@ -240,7 +258,8 @@ else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId
* @todo would be better to store this in the plugin descriptor, but then it won't be available to the version * @todo would be better to store this in the plugin descriptor, but then it won't be available to the version
* manager which executes before the plugin is instantiated * manager which executes before the plugin is instantiated
*/ */
private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List
remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException throws PluginVersionResolutionException, InvalidPluginException
{ {
try try
@ -303,18 +322,18 @@ protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject p
// We need to look for a Plugin instance there, in case the instance we're using didn't come from // We need to look for a Plugin instance there, in case the instance we're using didn't come from
// the project. // the project.
Plugin projectPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( plugin.getKey() ); Plugin projectPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( plugin.getKey() );
if ( projectPlugin == null ) if ( projectPlugin == null )
{ {
projectPlugin = plugin; projectPlugin = plugin;
} }
Set artifacts = Set artifacts =
MavenMetadataSource.createArtifacts( artifactFactory, projectPlugin.getDependencies(), null, null, project ); MavenMetadataSource.createArtifacts( artifactFactory, projectPlugin.getDependencies(), null, null, project );
// Set artifacts = // Set artifacts =
// MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null, project ); // MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null, project );
addedPlugin.setIntroducedDependencyArtifacts( artifacts ); addedPlugin.setIntroducedDependencyArtifacts( artifacts );
} }
catch ( InvalidDependencyVersionException e ) catch ( InvalidDependencyVersionException e )

View File

@ -52,6 +52,14 @@ MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenS
PluginDescriptor getPluginDescriptorForPrefix( String prefix ); PluginDescriptor getPluginDescriptorForPrefix( String prefix );
PluginDescriptor getPluginDescriptor( String groupId,
String artifactId,
MavenProject project,
Settings settings,
ArtifactRepository localRepository )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ); Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project );
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,