mirror of https://github.com/apache/maven.git
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:
parent
b9c5816ba9
commit
db17a2494b
|
@ -57,6 +57,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
|||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -496,9 +497,9 @@ public class DefaultLifecycleExecutor
|
|||
if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
|
||||
{
|
||||
forkEntryPoints.push( mojoDescriptor );
|
||||
|
||||
|
||||
forkLifecycle( mojoDescriptor, forkEntryPoints, session, project );
|
||||
|
||||
|
||||
forkEntryPoints.pop();
|
||||
}
|
||||
|
||||
|
@ -516,9 +517,9 @@ public class DefaultLifecycleExecutor
|
|||
if ( descriptor.getExecutePhase() != null )
|
||||
{
|
||||
forkEntryPoints.push( descriptor );
|
||||
|
||||
|
||||
forkLifecycle( descriptor, forkEntryPoints, session, project );
|
||||
|
||||
|
||||
forkEntryPoints.pop();
|
||||
}
|
||||
}
|
||||
|
@ -733,7 +734,7 @@ public class DefaultLifecycleExecutor
|
|||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||
{
|
||||
forkEntryPoints.push( mojoDescriptor );
|
||||
|
||||
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
|
||||
String targetPhase = mojoDescriptor.getExecutePhase();
|
||||
|
@ -780,11 +781,67 @@ public class DefaultLifecycleExecutor
|
|||
for ( Iterator k = e.getGoals().iterator(); k.hasNext(); )
|
||||
{
|
||||
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() );
|
||||
addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution,
|
||||
session.getSettings() );
|
||||
addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution, session.getSettings() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -849,23 +906,23 @@ public class DefaultLifecycleExecutor
|
|||
for ( Iterator it = lifecycleForkers.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
|
||||
|
||||
|
||||
for ( Iterator lifecycleIterator = lifecycleMappings.values().iterator(); lifecycleIterator.hasNext(); )
|
||||
{
|
||||
List tasks = (List) lifecycleIterator.next();
|
||||
|
||||
|
||||
boolean removed = false;
|
||||
for ( Iterator taskIterator = tasks.iterator(); taskIterator.hasNext(); )
|
||||
{
|
||||
MojoExecution execution = (MojoExecution) taskIterator.next();
|
||||
|
||||
|
||||
if ( mojoDescriptor.equals( execution.getMojoDescriptor() ) )
|
||||
{
|
||||
taskIterator.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( removed )
|
||||
{
|
||||
getLogger().warn(
|
||||
|
@ -1230,8 +1287,7 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution,
|
||||
Settings settings )
|
||||
private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution, Settings settings )
|
||||
{
|
||||
List goals = (List) lifecycleMappings.get( phase );
|
||||
|
||||
|
@ -1374,7 +1430,7 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
|
||||
project.injectPluginManagementInfo( plugin );
|
||||
|
||||
|
||||
if ( pluginDescriptor == null )
|
||||
{
|
||||
pluginDescriptor = verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() );
|
||||
|
|
|
@ -137,6 +137,24 @@ public class DefaultPluginManager
|
|||
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 )
|
||||
{
|
||||
// TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other
|
||||
|
@ -240,7 +258,8 @@ public class DefaultPluginManager
|
|||
* @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
|
||||
*/
|
||||
private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
|
||||
private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List
|
||||
remoteRepositories )
|
||||
throws PluginVersionResolutionException, InvalidPluginException
|
||||
{
|
||||
try
|
||||
|
@ -303,18 +322,18 @@ public class DefaultPluginManager
|
|||
// We need to look for a Plugin instance there, in case the instance we're using didn't come from
|
||||
// the project.
|
||||
Plugin projectPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( plugin.getKey() );
|
||||
|
||||
|
||||
if ( projectPlugin == null )
|
||||
{
|
||||
projectPlugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
Set artifacts =
|
||||
MavenMetadataSource.createArtifacts( artifactFactory, projectPlugin.getDependencies(), null, null, project );
|
||||
|
||||
// Set artifacts =
|
||||
// MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null, project );
|
||||
|
||||
|
||||
addedPlugin.setIntroducedDependencyArtifacts( artifacts );
|
||||
}
|
||||
catch ( InvalidDependencyVersionException e )
|
||||
|
|
|
@ -52,6 +52,14 @@ public interface PluginManager
|
|||
|
||||
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 );
|
||||
|
||||
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||
|
|
Loading…
Reference in New Issue