mirror of https://github.com/apache/maven.git
Clean up of the lifecycle executor, simplify configuration and push back into the plugin manager.
This fixed a couple of bugs along the way. One change that this has brought to bear from the document is you now must specify a goal for it to be bound to the LC (see it0008) git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191285 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dedfacf69a
commit
a9f174c834
|
@ -19,6 +19,11 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-core-it-plugin</artifactId>
|
<artifactId>maven-core-it-plugin</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<goals>
|
||||||
|
<goal>
|
||||||
|
<id>touch</id>
|
||||||
|
</goal>
|
||||||
|
</goals>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.lifecycle;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.execution.MavenExecutionResponse;
|
import org.apache.maven.execution.MavenExecutionResponse;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
|
@ -24,7 +25,7 @@ import org.apache.maven.model.Goal;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginExecution;
|
import org.apache.maven.model.PluginExecution;
|
||||||
import org.apache.maven.model.PluginManagement;
|
import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.plugin.GoalInstance;
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.PluginManager;
|
import org.apache.maven.plugin.PluginManager;
|
||||||
import org.apache.maven.plugin.PluginManagerException;
|
import org.apache.maven.plugin.PluginManagerException;
|
||||||
|
@ -48,11 +49,10 @@ import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
|
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||||
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
|
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
|
||||||
* jdcasey Exp $
|
* jdcasey Exp $
|
||||||
* @todo this is structured somewhat confusingly. Attempt to "flatten out" to reduce the number of paths through by
|
|
||||||
* compiling the list of plugins/tasks first.
|
|
||||||
*/
|
*/
|
||||||
public class DefaultLifecycleExecutor
|
public class DefaultLifecycleExecutor
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
|
@ -75,7 +75,7 @@ public class DefaultLifecycleExecutor
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a list of tasks. Each task may be a phase in the lifecycle or the
|
* Execute a task. Each task may be a phase in the lifecycle or the
|
||||||
* execution of a mojo.
|
* execution of a mojo.
|
||||||
*
|
*
|
||||||
* @param tasks
|
* @param tasks
|
||||||
|
@ -90,7 +90,11 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
processGoals( session, tasks );
|
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
String task = (String) i.next();
|
||||||
|
executeGoal( task, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( MojoExecutionException e )
|
catch ( MojoExecutionException e )
|
||||||
{
|
{
|
||||||
|
@ -108,14 +112,12 @@ public class DefaultLifecycleExecutor
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processGoals( MavenSession session, List tasks )
|
private void executeGoal( String task, MavenSession session )
|
||||||
throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException,
|
throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, ArtifactResolutionException
|
||||||
ArtifactResolutionException
|
|
||||||
{
|
{
|
||||||
Map phaseMap = new HashMap();
|
Map phaseMap = new HashMap();
|
||||||
Map goalInstanceMap = new HashMap();
|
|
||||||
|
|
||||||
String maxPhase = null;
|
String selectedPhase = null;
|
||||||
|
|
||||||
for ( Iterator i = phases.iterator(); i.hasNext(); )
|
for ( Iterator i = phases.iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
|
@ -124,192 +126,111 @@ public class DefaultLifecycleExecutor
|
||||||
// Make a copy of the phase as we will modify it
|
// Make a copy of the phase as we will modify it
|
||||||
phaseMap.put( p, new ArrayList() );
|
phaseMap.put( p, new ArrayList() );
|
||||||
|
|
||||||
if ( tasks.contains( p ) )
|
if ( task.equals( p ) )
|
||||||
{
|
{
|
||||||
maxPhase = p;
|
selectedPhase = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MavenProject project = session.getProject();
|
List goals;
|
||||||
|
|
||||||
if ( maxPhase != null )
|
// Need to verify all the plugins up front, as standalone goals should use the version from the POM.
|
||||||
{
|
for ( Iterator i = session.getProject().getBuildPlugins().iterator(); i.hasNext(); )
|
||||||
Map mappings;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, project.getPackaging() );
|
|
||||||
mappings = m.getPhases();
|
|
||||||
}
|
|
||||||
catch ( ComponentLookupException e )
|
|
||||||
{
|
|
||||||
getLogger().error( "No lifecycle mapping for type '" + project.getPackaging() + "': using defaults" );
|
|
||||||
mappings = defaultPhases;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator i = phases.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
String phase = (String) i.next();
|
|
||||||
|
|
||||||
String phaseTasks = (String) mappings.get( phase );
|
|
||||||
|
|
||||||
if ( phaseTasks != null )
|
|
||||||
{
|
|
||||||
for ( StringTokenizer tok = new StringTokenizer( phaseTasks, "," ); tok.hasMoreTokens(); )
|
|
||||||
{
|
|
||||||
String task = tok.nextToken().trim();
|
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
|
|
||||||
|
|
||||||
addToPhaseMap( phaseMap, phase, mojoDescriptor );
|
|
||||||
|
|
||||||
List matchingGoalInstances = findMatchingGoalInstances( mojoDescriptor, project );
|
|
||||||
|
|
||||||
for ( Iterator instanceIterator = matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
|
|
||||||
{
|
|
||||||
GoalInstance goalInstance = (GoalInstance) instanceIterator.next();
|
|
||||||
|
|
||||||
addToGoalInstanceMap( goalInstanceMap, goalInstance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( phase.equals( maxPhase ) )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processPluginConfiguration( project, session, phaseMap, goalInstanceMap );
|
|
||||||
|
|
||||||
for ( Iterator i = tasks.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
String task = (String) i.next();
|
|
||||||
|
|
||||||
// verify that all loose-leaf goals have had GoalInstance(s) configured for them...
|
|
||||||
// we only need to do this if the current task is not a phase name.
|
|
||||||
if ( !phaseMap.containsKey( task ) )
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session );
|
|
||||||
|
|
||||||
if ( mojoDescriptor != null && !goalInstanceMap.containsKey( mojoDescriptor ) )
|
|
||||||
{
|
|
||||||
List matchingGoalInstances = findMatchingGoalInstances( mojoDescriptor, project );
|
|
||||||
|
|
||||||
for ( Iterator instanceIterator = matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
|
|
||||||
{
|
|
||||||
GoalInstance goalInstance = (GoalInstance) instanceIterator.next();
|
|
||||||
|
|
||||||
addToGoalInstanceMap( goalInstanceMap, goalInstance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we can proceed to actually load up the list of goals we're interested in.
|
|
||||||
List goals = processGoalChain( task, session, phaseMap );
|
|
||||||
|
|
||||||
for ( Iterator j = goals.iterator(); j.hasNext(); )
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
|
||||||
|
|
||||||
List instances = (List) goalInstanceMap.get( mojoDescriptor );
|
|
||||||
|
|
||||||
if ( instances != null )
|
|
||||||
{
|
|
||||||
for ( Iterator instanceIterator = instances.iterator(); instanceIterator.hasNext(); )
|
|
||||||
{
|
|
||||||
GoalInstance instance = (GoalInstance) instanceIterator.next();
|
|
||||||
|
|
||||||
String executePhase = mojoDescriptor.getExecutePhase();
|
|
||||||
|
|
||||||
if ( executePhase != null )
|
|
||||||
{
|
|
||||||
// TODO: is this too broad to execute?
|
|
||||||
execute( Collections.singletonList( executePhase ), session );
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pluginManager.executeMojo( session, instance );
|
|
||||||
}
|
|
||||||
catch ( PluginManagerException e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "This goal has not been configured: "
|
|
||||||
+ mojoDescriptor.getGoal() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToGoalInstanceMap( Map goalInstanceMap, GoalInstance goalInstance )
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = goalInstance.getMojoDescriptor();
|
|
||||||
|
|
||||||
List instances = (List) goalInstanceMap.get( mojoDescriptor );
|
|
||||||
|
|
||||||
if ( instances == null )
|
|
||||||
{
|
|
||||||
instances = new ArrayList();
|
|
||||||
|
|
||||||
goalInstanceMap.put( mojoDescriptor, instances );
|
|
||||||
}
|
|
||||||
|
|
||||||
int idx = instances.indexOf( goalInstance );
|
|
||||||
|
|
||||||
if ( idx > -1 )
|
|
||||||
{
|
|
||||||
GoalInstance cached = (GoalInstance) instances.get( idx );
|
|
||||||
|
|
||||||
cached.incorporate( goalInstance );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instances.add( goalInstance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId,
|
|
||||||
String version )
|
|
||||||
{
|
|
||||||
String key = Plugin.constructKey( groupId, artifactId );
|
|
||||||
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
|
|
||||||
|
|
||||||
if ( plugin == null )
|
|
||||||
{
|
|
||||||
plugin = new Plugin();
|
|
||||||
plugin.setGroupId( groupId );
|
|
||||||
plugin.setArtifactId( artifactId );
|
|
||||||
plugin.setVersion( version );
|
|
||||||
|
|
||||||
PluginManagement pluginManagement = project.getPluginManagement();
|
|
||||||
if ( pluginManagement != null )
|
|
||||||
{
|
|
||||||
Plugin def = (Plugin) pluginManagement.getPluginsAsMap().get( key );
|
|
||||||
if ( def != null )
|
|
||||||
{
|
|
||||||
modelDefaultsInjector.mergePluginWithDefaults( plugin, def );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.addPlugin( plugin );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession, Map phaseMap,
|
|
||||||
Map goalInstanceMap )
|
|
||||||
throws LifecycleExecutionException, ArtifactResolutionException
|
|
||||||
{
|
|
||||||
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
|
|
||||||
{
|
{
|
||||||
Plugin plugin = (Plugin) i.next();
|
Plugin plugin = (Plugin) i.next();
|
||||||
|
|
||||||
processPluginPhases( plugin, mavenSession, phaseMap, goalInstanceMap );
|
verifyPlugin( plugin, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( selectedPhase != null )
|
||||||
|
{
|
||||||
|
// we have a lifecycle phase, so lets bind all the necessary goals
|
||||||
|
constructLifecyclePhaseMap( session, phaseMap, selectedPhase );
|
||||||
|
|
||||||
|
goals = processGoalChain( selectedPhase, phaseMap );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session );
|
||||||
|
goals = Collections.singletonList( new MojoExecution( mojoDescriptor ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
MojoExecution mojoExecution = (MojoExecution) i.next();
|
||||||
|
|
||||||
|
String executePhase = mojoExecution.getMojoDescriptor().getExecutePhase();
|
||||||
|
|
||||||
|
if ( executePhase != null )
|
||||||
|
{
|
||||||
|
// TODO: with introduction of cloned lifecyle, we want to avoid reconstructing some things - narrow
|
||||||
|
executeGoal( executePhase, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pluginManager.executeMojo( mojoExecution, session );
|
||||||
|
}
|
||||||
|
catch ( PluginManagerException e )
|
||||||
|
{
|
||||||
|
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void constructLifecyclePhaseMap( MavenSession session, Map phaseMap, String selectedPhase )
|
||||||
|
throws ArtifactResolutionException, LifecycleExecutionException
|
||||||
|
{
|
||||||
|
// first, bind those associated with the packaging
|
||||||
|
bindLifecycleForPackaging( session, phaseMap, selectedPhase );
|
||||||
|
|
||||||
|
// next, loop over plugins and for any that have a phase, bind it
|
||||||
|
for ( Iterator i = session.getProject().getBuildPlugins().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Plugin plugin = (Plugin) i.next();
|
||||||
|
|
||||||
|
bindPluginToLifecycle( plugin, session, phaseMap );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindLifecycleForPackaging( MavenSession session, Map phaseMap, String selectedPhase )
|
||||||
|
throws ArtifactResolutionException, LifecycleExecutionException
|
||||||
|
{
|
||||||
|
Map mappings;
|
||||||
|
String packaging = session.getProject().getPackaging();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
|
||||||
|
mappings = m.getPhases();
|
||||||
|
}
|
||||||
|
catch ( ComponentLookupException e )
|
||||||
|
{
|
||||||
|
getLogger().error( "No lifecycle mapping for type '" + packaging + "': using defaults" );
|
||||||
|
mappings = defaultPhases;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean finished = false;
|
||||||
|
for ( Iterator i = phases.iterator(); i.hasNext() && !finished; )
|
||||||
|
{
|
||||||
|
String phase = (String) i.next();
|
||||||
|
|
||||||
|
String phaseTasks = (String) mappings.get( phase );
|
||||||
|
|
||||||
|
if ( phaseTasks != null )
|
||||||
|
{
|
||||||
|
for ( StringTokenizer tok = new StringTokenizer( phaseTasks, "," ); tok.hasMoreTokens(); )
|
||||||
|
{
|
||||||
|
String goal = tok.nextToken().trim();
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session );
|
||||||
|
addToPhaseMap( phaseMap, phase, new MojoExecution( mojoDescriptor ), session.getSettings() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( phase.equals( selectedPhase ) )
|
||||||
|
{
|
||||||
|
finished = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,10 +240,45 @@ public class DefaultLifecycleExecutor
|
||||||
* to execute for that given phase.
|
* to execute for that given phase.
|
||||||
*
|
*
|
||||||
* @param session
|
* @param session
|
||||||
* @param goalInstanceMap
|
|
||||||
*/
|
*/
|
||||||
private void processPluginPhases( Plugin plugin, MavenSession session, Map phaseMap, Map goalInstanceMap )
|
private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap )
|
||||||
throws LifecycleExecutionException, ArtifactResolutionException
|
throws LifecycleExecutionException, ArtifactResolutionException
|
||||||
|
{
|
||||||
|
if ( plugin.getGoals() != null && !plugin.getGoals().isEmpty() )
|
||||||
|
{
|
||||||
|
getLogger().warn(
|
||||||
|
"DEPRECATED: goal definitions for plugin '" + plugin.getKey() + "' must be in an executions element" );
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginDescriptor pluginDescriptor;
|
||||||
|
Settings settings = session.getSettings();
|
||||||
|
|
||||||
|
pluginDescriptor = verifyPlugin( plugin, session );
|
||||||
|
|
||||||
|
if ( pluginDescriptor.getMojos() != null && !pluginDescriptor.getMojos().isEmpty() )
|
||||||
|
{
|
||||||
|
// use the plugin if inherit was true in a base class, or it is in the current POM, otherwise use the default inheritence setting
|
||||||
|
if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
|
||||||
|
{
|
||||||
|
bindGoalMapToLifecycle( pluginDescriptor, plugin.getGoalsAsMap(), phaseMap, settings );
|
||||||
|
|
||||||
|
List executions = plugin.getExecutions();
|
||||||
|
|
||||||
|
if ( executions != null )
|
||||||
|
{
|
||||||
|
for ( Iterator it = executions.iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
PluginExecution execution = (PluginExecution) it.next();
|
||||||
|
|
||||||
|
bindExecutionToLifecycle( pluginDescriptor, phaseMap, execution, settings );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session )
|
||||||
|
throws ArtifactResolutionException, LifecycleExecutionException
|
||||||
{
|
{
|
||||||
String groupId = plugin.getGroupId();
|
String groupId = plugin.getGroupId();
|
||||||
|
|
||||||
|
@ -333,8 +289,10 @@ public class DefaultLifecycleExecutor
|
||||||
PluginDescriptor pluginDescriptor;
|
PluginDescriptor pluginDescriptor;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(), session
|
MavenProject project = session.getProject();
|
||||||
.getSettings(), session.getLocalRepository() );
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project, session.getSettings(),
|
||||||
|
localRepository );
|
||||||
}
|
}
|
||||||
catch ( PluginManagerException e )
|
catch ( PluginManagerException e )
|
||||||
{
|
{
|
||||||
|
@ -344,87 +302,80 @@ public class DefaultLifecycleExecutor
|
||||||
{
|
{
|
||||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||||
}
|
}
|
||||||
|
return pluginDescriptor;
|
||||||
if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
|
|
||||||
{
|
|
||||||
processGoalContainerPhases( plugin, null, pluginDescriptor, session, plugin.getGoalsAsMap(), phaseMap,
|
|
||||||
goalInstanceMap );
|
|
||||||
|
|
||||||
List executions = plugin.getExecutions();
|
|
||||||
|
|
||||||
if ( executions != null )
|
|
||||||
{
|
|
||||||
for ( Iterator it = executions.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
PluginExecution execution = (PluginExecution) it.next();
|
|
||||||
|
|
||||||
if ( execution.isInheritanceApplied() )
|
|
||||||
{
|
|
||||||
processGoalContainerPhases( plugin, execution, pluginDescriptor, session, execution
|
|
||||||
.getGoalsAsMap(), phaseMap, goalInstanceMap );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processGoalContainerPhases( Plugin plugin, PluginExecution execution,
|
|
||||||
PluginDescriptor pluginDescriptor, MavenSession session, Map goalMap,
|
|
||||||
Map phaseMap, Map goalInstanceMap )
|
|
||||||
throws LifecycleExecutionException
|
|
||||||
{
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Look to see if the plugin configuration specifies particular mojos
|
|
||||||
// within the plugin. If this is the case then simply configure the
|
|
||||||
// mojos the user has specified and ignore the rest.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
if ( pluginDescriptor.getMojos() != null )
|
|
||||||
{
|
|
||||||
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
|
||||||
|
|
||||||
// TODO: remove later
|
|
||||||
if ( mojoDescriptor.getGoal() == null )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getId()
|
|
||||||
+ " was built with an older version of Maven" );
|
|
||||||
}
|
|
||||||
|
|
||||||
Goal goal = (Goal) goalMap.get( mojoDescriptor.getGoal() );
|
|
||||||
|
|
||||||
if ( goalMap.isEmpty() )
|
|
||||||
{
|
|
||||||
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
|
|
||||||
|
|
||||||
addToGoalInstanceMap( goalInstanceMap, new GoalInstance( plugin, execution, goal, mojoDescriptor ) );
|
|
||||||
}
|
|
||||||
else if ( goal != null )
|
|
||||||
{
|
|
||||||
// We have to check to see that the inheritance rules have been applied before binding this mojo.
|
|
||||||
if ( goal.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
|
|
||||||
{
|
|
||||||
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
|
|
||||||
|
|
||||||
addToGoalInstanceMap( goalInstanceMap, new GoalInstance( plugin, execution, goal,
|
|
||||||
mojoDescriptor ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take a look at a mojo contained within a plugin, look to see whether it contributes to a
|
* @deprecated
|
||||||
* phase in the lifecycle and if it does place it at the end of the list of goals
|
|
||||||
* to execute for the stated phase.
|
|
||||||
*
|
|
||||||
* @param mojoDescriptor
|
|
||||||
*/
|
*/
|
||||||
private void configureMojoPhaseBinding( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings )
|
private void bindGoalMapToLifecycle( PluginDescriptor pluginDescriptor, Map goalMap, Map phaseMap,
|
||||||
|
Settings settings )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
|
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next();
|
||||||
|
|
||||||
|
Goal goal = (Goal) goalMap.get( mojoDescriptor.getGoal() );
|
||||||
|
|
||||||
|
if ( goal != null )
|
||||||
|
{
|
||||||
|
// We have to check to see that the inheritance rules have been applied before binding this mojo.
|
||||||
|
if ( mojoDescriptor.isInheritedByDefault() )
|
||||||
|
{
|
||||||
|
if ( mojoDescriptor.getPhase() != null )
|
||||||
|
{
|
||||||
|
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
|
||||||
|
addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindExecutionToLifecycle( PluginDescriptor pluginDescriptor, Map phaseMap, PluginExecution execution,
|
||||||
|
Settings settings )
|
||||||
|
throws LifecycleExecutionException
|
||||||
|
{
|
||||||
|
for ( Iterator i = execution.getGoals().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
String goal = (String) i.next();
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
|
||||||
|
if ( mojoDescriptor == null )
|
||||||
|
{
|
||||||
|
throw new LifecycleExecutionException( "Goal from the POM '" + goal + "' was not found in the plugin" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have to check to see that the inheritance rules have been applied before binding this mojo.
|
||||||
|
if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
|
||||||
|
{
|
||||||
|
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
|
||||||
|
if ( execution.getPhase() != null )
|
||||||
|
{
|
||||||
|
addToPhaseMap( phaseMap, execution.getPhase(), mojoExecution, settings );
|
||||||
|
}
|
||||||
|
else if ( mojoDescriptor.getPhase() != null )
|
||||||
|
{
|
||||||
|
// if the phase was not in the configuration, use the phase in the descriptor
|
||||||
|
addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToPhaseMap( Map phaseMap, String phase, MojoExecution mojoExecution, Settings settings )
|
||||||
|
throws LifecycleExecutionException
|
||||||
|
{
|
||||||
|
List goals = (List) phaseMap.get( phase );
|
||||||
|
|
||||||
|
if ( goals == null )
|
||||||
|
{
|
||||||
|
String message = "Required phase '" + phase + "' not found";
|
||||||
|
throw new LifecycleExecutionException( message );
|
||||||
|
}
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||||
if ( settings.isOffline() && mojoDescriptor.isOnlineRequired() )
|
if ( settings.isOffline() && mojoDescriptor.isOnlineRequired() )
|
||||||
{
|
{
|
||||||
String goal = mojoDescriptor.getGoal();
|
String goal = mojoDescriptor.getGoal();
|
||||||
|
@ -432,130 +383,31 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( mojoDescriptor.getPhase() != null )
|
goals.add( mojoExecution );
|
||||||
{
|
|
||||||
addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoDescriptor );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToPhaseMap( Map phaseMap, String phase, MojoDescriptor mojoDescriptor )
|
private List processGoalChain( String task, Map phaseMap )
|
||||||
throws LifecycleExecutionException
|
|
||||||
{
|
|
||||||
if ( phase != null )
|
|
||||||
{
|
|
||||||
List goals = (List) phaseMap.get( phase );
|
|
||||||
|
|
||||||
if ( goals == null )
|
|
||||||
{
|
|
||||||
String message = "Required phase '" + phase + "' not found";
|
|
||||||
throw new LifecycleExecutionException( message );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !goals.contains( mojoDescriptor ) )
|
|
||||||
{
|
|
||||||
goals.add( mojoDescriptor );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List processGoalChain( String task, MavenSession session, Map phaseMap )
|
|
||||||
throws LifecycleExecutionException, ArtifactResolutionException
|
|
||||||
{
|
{
|
||||||
List goals = new ArrayList();
|
List goals = new ArrayList();
|
||||||
|
|
||||||
if ( phaseMap.containsKey( task ) )
|
// only execute up to the given phase
|
||||||
|
int index = phases.indexOf( task );
|
||||||
|
|
||||||
|
for ( int i = 0; i <= index; i++ )
|
||||||
{
|
{
|
||||||
// only execute up to the given phase
|
String p = (String) phases.get( i );
|
||||||
int index = phases.indexOf( task );
|
|
||||||
|
|
||||||
for ( int j = 0; j <= index; j++ )
|
List phaseGoals = (List) phaseMap.get( p );
|
||||||
|
|
||||||
|
if ( phaseGoals != null )
|
||||||
{
|
{
|
||||||
String p = (String) phases.get( j );
|
goals.addAll( phaseGoals );
|
||||||
|
|
||||||
List phaseGoals = (List) phaseMap.get( p );
|
|
||||||
|
|
||||||
if ( phaseGoals != null )
|
|
||||||
{
|
|
||||||
goals.addAll( phaseGoals );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
|
|
||||||
|
|
||||||
goals.add( mojoDescriptor );
|
|
||||||
}
|
|
||||||
|
|
||||||
return goals;
|
return goals;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MojoDescriptor configureMojo( String task, MavenSession session, Map phaseMap )
|
|
||||||
throws LifecycleExecutionException, ArtifactResolutionException
|
|
||||||
{
|
|
||||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session );
|
|
||||||
|
|
||||||
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
|
|
||||||
|
|
||||||
return mojoDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List findMatchingGoalInstances( MojoDescriptor mojoDescriptor, MavenProject project )
|
|
||||||
{
|
|
||||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
|
||||||
|
|
||||||
List plugins = project.getBuildPlugins();
|
|
||||||
|
|
||||||
List matchingSteps = new ArrayList();
|
|
||||||
|
|
||||||
Plugin plugin = null;
|
|
||||||
|
|
||||||
for ( Iterator it = plugins.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
plugin = (Plugin) it.next();
|
|
||||||
|
|
||||||
if ( pluginDescriptor.getPluginLookupKey().equals( plugin.getKey() ) )
|
|
||||||
{
|
|
||||||
String mojoGoal = mojoDescriptor.getGoal();
|
|
||||||
|
|
||||||
Goal unattached = (Goal) plugin.getGoalsAsMap().get( mojoDescriptor.getGoal() );
|
|
||||||
|
|
||||||
if ( unattached != null )
|
|
||||||
{
|
|
||||||
matchingSteps.add( new GoalInstance( plugin, unattached, mojoDescriptor ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
List executions = plugin.getExecutions();
|
|
||||||
|
|
||||||
if ( executions != null )
|
|
||||||
{
|
|
||||||
for ( Iterator executionIterator = executions.iterator(); executionIterator.hasNext(); )
|
|
||||||
{
|
|
||||||
PluginExecution execution = (PluginExecution) executionIterator.next();
|
|
||||||
|
|
||||||
Goal attached = (Goal) execution.getGoalsAsMap().get( mojoDescriptor.getGoal() );
|
|
||||||
|
|
||||||
if ( attached != null )
|
|
||||||
{
|
|
||||||
matchingSteps.add( new GoalInstance( plugin, execution, attached, mojoDescriptor ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if nothing is configured, then we need to add a "fully detached" step...
|
|
||||||
if ( matchingSteps.isEmpty() )
|
|
||||||
{
|
|
||||||
matchingSteps.add( new GoalInstance( mojoDescriptor ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchingSteps;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MojoDescriptor getMojoDescriptor( String task, MavenSession session )
|
private MojoDescriptor getMojoDescriptor( String task, MavenSession session )
|
||||||
throws ArtifactResolutionException, LifecycleExecutionException
|
throws ArtifactResolutionException, LifecycleExecutionException
|
||||||
{
|
{
|
||||||
|
@ -590,18 +442,17 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or"
|
String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or" +
|
||||||
+ " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
|
" a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
|
||||||
throw new LifecycleExecutionException( message );
|
throw new LifecycleExecutionException( message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MavenProject project = session.getProject();
|
||||||
if ( pluginDescriptor == null )
|
if ( pluginDescriptor == null )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId, version );
|
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project,
|
||||||
|
|
||||||
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(),
|
|
||||||
session.getSettings(), session.getLocalRepository() );
|
session.getSettings(), session.getLocalRepository() );
|
||||||
}
|
}
|
||||||
catch ( PluginManagerException e )
|
catch ( PluginManagerException e )
|
||||||
|
@ -613,33 +464,11 @@ public class DefaultLifecycleExecutor
|
||||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
injectHandlerPluginConfiguration( session.getProject(), pluginDescriptor.getGroupId(), pluginDescriptor
|
|
||||||
.getArtifactId(), pluginDescriptor.getVersion() );
|
|
||||||
}
|
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = null;
|
injectHandlerPluginConfiguration( project, pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(),
|
||||||
|
pluginDescriptor.getVersion() );
|
||||||
if ( pluginDescriptor.getMojos() != null )
|
|
||||||
{
|
|
||||||
// TODO: should be able to create a Map from this
|
|
||||||
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext() && mojoDescriptor == null; )
|
|
||||||
{
|
|
||||||
MojoDescriptor desc = (MojoDescriptor) i.next();
|
|
||||||
if ( desc.getGoal().equals( goal ) )
|
|
||||||
{
|
|
||||||
mojoDescriptor = desc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getGroupId() + ":"
|
|
||||||
+ pluginDescriptor.getArtifactId() + ":" + pluginDescriptor.getVersion()
|
|
||||||
+ " doesn't contain any mojo. Check if it isn't corrupted." );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
|
||||||
if ( mojoDescriptor == null )
|
if ( mojoDescriptor == null )
|
||||||
{
|
{
|
||||||
throw new LifecycleExecutionException( "Required goal not found: " + task );
|
throw new LifecycleExecutionException( "Required goal not found: " + task );
|
||||||
|
@ -648,9 +477,30 @@ public class DefaultLifecycleExecutor
|
||||||
return mojoDescriptor;
|
return mojoDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getPhases()
|
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId,
|
||||||
|
String version )
|
||||||
{
|
{
|
||||||
return phases;
|
String key = Plugin.constructKey( groupId, artifactId );
|
||||||
}
|
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
|
||||||
|
|
||||||
|
if ( plugin == null )
|
||||||
|
{
|
||||||
|
plugin = new Plugin();
|
||||||
|
plugin.setGroupId( groupId );
|
||||||
|
plugin.setArtifactId( artifactId );
|
||||||
|
plugin.setVersion( version );
|
||||||
|
|
||||||
|
PluginManagement pluginManagement = project.getPluginManagement();
|
||||||
|
if ( pluginManagement != null )
|
||||||
|
{
|
||||||
|
Plugin def = (Plugin) pluginManagement.getPluginsAsMap().get( key );
|
||||||
|
if ( def != null )
|
||||||
|
{
|
||||||
|
modelDefaultsInjector.mergePluginWithDefaults( plugin, def );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.addPlugin( plugin );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,4 @@ public interface LifecycleExecutor
|
||||||
MavenExecutionResponse execute( List tasks, MavenSession session )
|
MavenExecutionResponse execute( List tasks, MavenSession session )
|
||||||
throws LifecycleExecutionException;
|
throws LifecycleExecutionException;
|
||||||
|
|
||||||
List getPhases();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,12 +346,12 @@ public class DefaultPluginManager
|
||||||
// Mojo execution
|
// Mojo execution
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public void executeMojo( MavenSession session, GoalInstance goalInstance )
|
public void executeMojo( MojoExecution mojoExecution, MavenSession session )
|
||||||
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
|
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
|
||||||
{
|
{
|
||||||
PlexusContainer pluginContainer = null;
|
PlexusContainer pluginContainer = null;
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = goalInstance.getMojoDescriptor();
|
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||||
|
|
||||||
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
||||||
{
|
{
|
||||||
|
@ -409,11 +409,13 @@ public class DefaultPluginManager
|
||||||
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
|
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
|
||||||
plugin.setLog( mojoLogger );
|
plugin.setLog( mojoLogger );
|
||||||
|
|
||||||
String goalId = goalInstance.getGoalId();
|
|
||||||
|
|
||||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||||
|
|
||||||
Xpp3Dom dom = goalInstance.getCalculatedConfiguration();
|
String goalId = mojoDescriptor.getGoal();
|
||||||
|
String groupId = pluginDescriptor.getGroupId();
|
||||||
|
String artifactId = pluginDescriptor.getArtifactId();
|
||||||
|
String executionId = mojoExecution.getExecutionId();
|
||||||
|
Xpp3Dom dom = session.getProject().getGoalConfiguration( groupId, artifactId, executionId, goalId );
|
||||||
|
|
||||||
PlexusConfiguration pomConfiguration;
|
PlexusConfiguration pomConfiguration;
|
||||||
if ( dom == null )
|
if ( dom == null )
|
||||||
|
@ -451,9 +453,9 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
String goalExecId = goalName;
|
String goalExecId = goalName;
|
||||||
|
|
||||||
if ( goalInstance.getExecutionId() != null )
|
if ( mojoExecution.getExecutionId() != null )
|
||||||
{
|
{
|
||||||
goalExecId += " {execution: " + goalInstance.getExecutionId() + "}";
|
goalExecId += " {execution: " + mojoExecution.getExecutionId() + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcher.dispatchStart( event, goalExecId );
|
dispatcher.dispatchStart( event, goalExecId );
|
||||||
|
|
|
@ -1,205 +0,0 @@
|
||||||
package org.apache.maven.plugin;
|
|
||||||
|
|
||||||
import org.apache.maven.model.Goal;
|
|
||||||
import org.apache.maven.model.Plugin;
|
|
||||||
import org.apache.maven.model.PluginExecution;
|
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2001-2005 The Apache Software Foundation.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class GoalInstance
|
|
||||||
{
|
|
||||||
|
|
||||||
private final MojoDescriptor mojoDescriptor;
|
|
||||||
|
|
||||||
private String pluginKey;
|
|
||||||
|
|
||||||
private String executionId;
|
|
||||||
|
|
||||||
private Xpp3Dom calculatedConfiguration;
|
|
||||||
|
|
||||||
public GoalInstance( Plugin plugin, PluginExecution pluginExecution, Goal goal, MojoDescriptor mojoDescriptor )
|
|
||||||
{
|
|
||||||
if ( plugin != null )
|
|
||||||
{
|
|
||||||
this.pluginKey = plugin.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pluginExecution != null )
|
|
||||||
{
|
|
||||||
this.executionId = pluginExecution.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mojoDescriptor = mojoDescriptor;
|
|
||||||
|
|
||||||
calculateConfiguration( plugin, pluginExecution, goal );
|
|
||||||
}
|
|
||||||
|
|
||||||
public GoalInstance( Plugin plugin, Goal goal, MojoDescriptor mojoDescriptor )
|
|
||||||
{
|
|
||||||
this( plugin, null, goal, mojoDescriptor );
|
|
||||||
}
|
|
||||||
|
|
||||||
public GoalInstance( MojoDescriptor mojoDescriptor )
|
|
||||||
{
|
|
||||||
this( null, null, null, mojoDescriptor );
|
|
||||||
}
|
|
||||||
|
|
||||||
public MojoDescriptor getMojoDescriptor()
|
|
||||||
{
|
|
||||||
return mojoDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMojoExecutePhase()
|
|
||||||
{
|
|
||||||
return mojoDescriptor.getExecutePhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPluginKey()
|
|
||||||
{
|
|
||||||
return pluginKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExecutionId()
|
|
||||||
{
|
|
||||||
return executionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGoalId()
|
|
||||||
{
|
|
||||||
return mojoDescriptor.getGoal();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Xpp3Dom calculateConfiguration( Plugin plugin, PluginExecution pluginExecution, Goal goal )
|
|
||||||
{
|
|
||||||
calculatedConfiguration = new Xpp3Dom( "configuration" );
|
|
||||||
|
|
||||||
if ( plugin != null )
|
|
||||||
{
|
|
||||||
Xpp3Dom pluginConfig = (Xpp3Dom) plugin.getConfiguration();
|
|
||||||
|
|
||||||
if ( pluginConfig != null )
|
|
||||||
{
|
|
||||||
calculatedConfiguration = Xpp3Dom.mergeXpp3Dom( pluginConfig, calculatedConfiguration );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pluginExecution != null )
|
|
||||||
{
|
|
||||||
Xpp3Dom executionConfig = (Xpp3Dom) pluginExecution.getConfiguration();
|
|
||||||
|
|
||||||
if ( executionConfig != null )
|
|
||||||
{
|
|
||||||
calculatedConfiguration = Xpp3Dom.mergeXpp3Dom( executionConfig, calculatedConfiguration );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( goal != null )
|
|
||||||
{
|
|
||||||
Xpp3Dom goalConfig = (Xpp3Dom) goal.getConfiguration();
|
|
||||||
|
|
||||||
if ( goalConfig != null )
|
|
||||||
{
|
|
||||||
calculatedConfiguration = Xpp3Dom.mergeXpp3Dom( goalConfig, calculatedConfiguration );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
calculatedConfiguration = new Xpp3Dom( calculatedConfiguration );
|
|
||||||
|
|
||||||
return calculatedConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals( Object object )
|
|
||||||
{
|
|
||||||
if ( object == this )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( object instanceof GoalInstance )
|
|
||||||
{
|
|
||||||
GoalInstance other = (GoalInstance) object;
|
|
||||||
|
|
||||||
if ( !getMojoDescriptor().equals( other.getMojoDescriptor() ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String execId = getExecutionId();
|
|
||||||
|
|
||||||
String otherExecId = other.getExecutionId();
|
|
||||||
|
|
||||||
if ( execId == otherExecId )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( execId == null && otherExecId != null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( execId != null && otherExecId == null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return execId.equals( otherExecId );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
int result = 2;
|
|
||||||
|
|
||||||
// this should NEVER be null...
|
|
||||||
result += getMojoDescriptor().hashCode();
|
|
||||||
|
|
||||||
String execId = getExecutionId();
|
|
||||||
|
|
||||||
if ( execId != null )
|
|
||||||
{
|
|
||||||
result -= execId.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "goal instance {goal: " + getGoalId() + ", execution-id: " + getExecutionId() + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Xpp3Dom getCalculatedConfiguration()
|
|
||||||
{
|
|
||||||
return new Xpp3Dom( calculatedConfiguration );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incorporate( GoalInstance other )
|
|
||||||
{
|
|
||||||
Xpp3Dom otherConfig = (Xpp3Dom) other.getCalculatedConfiguration();
|
|
||||||
|
|
||||||
if ( otherConfig != null )
|
|
||||||
{
|
|
||||||
calculatedConfiguration = new Xpp3Dom( Xpp3Dom.mergeXpp3Dom( otherConfig, calculatedConfiguration ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.apache.maven.plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes a single mojo invocation.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class MojoExecution
|
||||||
|
{
|
||||||
|
private final String executionId;
|
||||||
|
|
||||||
|
private final MojoDescriptor mojoDescriptor;
|
||||||
|
|
||||||
|
public MojoExecution( MojoDescriptor mojoDescriptor )
|
||||||
|
{
|
||||||
|
this.mojoDescriptor = mojoDescriptor;
|
||||||
|
this.executionId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MojoExecution( MojoDescriptor mojoDescriptor, String executionId )
|
||||||
|
{
|
||||||
|
this.mojoDescriptor = mojoDescriptor;
|
||||||
|
this.executionId = executionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExecutionId()
|
||||||
|
{
|
||||||
|
return executionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MojoDescriptor getMojoDescriptor()
|
||||||
|
{
|
||||||
|
return mojoDescriptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ public interface PluginManager
|
||||||
{
|
{
|
||||||
String ROLE = PluginManager.class.getName();
|
String ROLE = PluginManager.class.getName();
|
||||||
|
|
||||||
void executeMojo( MavenSession session, GoalInstance buildStep )
|
void executeMojo( MojoExecution execution, MavenSession session )
|
||||||
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
|
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
|
||||||
|
|
||||||
PluginDescriptor verifyPlugin( String prefix );
|
PluginDescriptor verifyPlugin( String prefix );
|
||||||
|
|
|
@ -145,7 +145,12 @@ public class DefaultPluginVersionManager
|
||||||
|
|
||||||
// determines what should be done if we're in non-interactive mode.
|
// determines what should be done if we're in non-interactive mode.
|
||||||
// if true, then just update the registry with the new versions.
|
// if true, then just update the registry with the new versions.
|
||||||
boolean autoUpdate = Boolean.valueOf( pluginRegistry.getAutoUpdate() ).booleanValue();
|
String s = getPluginRegistry( groupId, artifactId ).getAutoUpdate();
|
||||||
|
boolean autoUpdate = true;
|
||||||
|
if ( s != null )
|
||||||
|
{
|
||||||
|
autoUpdate = Boolean.valueOf( s ).booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
// We should persist by default if:
|
// We should persist by default if:
|
||||||
// 1. we detected a change in the plugin version from what was in the registry, or
|
// 1. we detected a change in the plugin version from what was in the registry, or
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package org.apache.maven.lifecycle;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2001-2005 The Apache Software Foundation.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
|
||||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LifecycleExecutorTest
|
|
||||||
extends PlexusTestCase
|
|
||||||
{
|
|
||||||
public void testLifecycleExecutor()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
LifecycleExecutor le = (LifecycleExecutor) lookup( LifecycleExecutor.ROLE );
|
|
||||||
|
|
||||||
LifecycleMapping m = (LifecycleMapping) lookup( LifecycleMapping.ROLE, "pom" );
|
|
||||||
|
|
||||||
assertEquals( 18, le.getPhases().size() );
|
|
||||||
|
|
||||||
//le.execute( "test", createGoalExecutionContext().getSession() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -624,6 +624,14 @@
|
||||||
</association>
|
</association>
|
||||||
<comment>These should ultimately only be compile time dependencies when transitive dependencies come into play.</comment>
|
<comment>These should ultimately only be compile time dependencies when transitive dependencies come into play.</comment>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>reports</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<description><![CDATA[
|
||||||
|
NOT A VALID ELEMENT. LISTED TO ALLOW LEGACY REPOSITORY POMs TO PARSE.
|
||||||
|
]]></description>
|
||||||
|
<type>DOM</type>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>reporting</name>
|
<name>reporting</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
@ -2013,7 +2021,7 @@
|
||||||
</codeSegment>
|
</codeSegment>
|
||||||
</codeSegments>
|
</codeSegments>
|
||||||
</class>
|
</class>
|
||||||
<!--@todo find better solution for managment of site deployments -->
|
<!--@todo find better solution for management of site deployments -->
|
||||||
<class>
|
<class>
|
||||||
<name>Site</name>
|
<name>Site</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
@ -2049,40 +2057,8 @@
|
||||||
</fields>
|
</fields>
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
A sketch of what a plugin configuration might look like where
|
|
||||||
we have plugin wide parameters that apply to all goals/mojos
|
|
||||||
and goal/mojo specific parameters that will override any
|
|
||||||
of the plugin wide definitions.
|
|
||||||
|
|
||||||
At first the configuration element will be a flat set of properties
|
|
||||||
but i would like the configuration to actually be an arbiitrary
|
|
||||||
data model or a simple DOM like structure so that mojos can
|
|
||||||
be arbitrarily configured in the same fashion plexus plugins
|
|
||||||
are configured.
|
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<id>plexus</id>
|
|
||||||
<configuration>
|
|
||||||
<key>value</key>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>
|
|
||||||
<id></id>
|
|
||||||
<configuration>
|
|
||||||
<key>value</key>
|
|
||||||
</configuration>
|
|
||||||
</goal>
|
|
||||||
</goals>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<class>
|
<class>
|
||||||
<name>GoalContainer</name>
|
<name>ConfigurationContainer</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
|
@ -2095,20 +2071,11 @@
|
||||||
<name>configuration</name>
|
<name>configuration</name>
|
||||||
<type>DOM</type>
|
<type>DOM</type>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
|
||||||
<name>goals</name>
|
|
||||||
<version>4.0.0</version>
|
|
||||||
<association>
|
|
||||||
<type>Goal</type>
|
|
||||||
<multiplicity>*</multiplicity>
|
|
||||||
</association>
|
|
||||||
</field>
|
|
||||||
</fields>
|
</fields>
|
||||||
<codeSegments>
|
<codeSegments>
|
||||||
<codeSegment>
|
<codeSegment>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
private Map goalMap = null;
|
|
||||||
private boolean inheritanceApplied = true;
|
private boolean inheritanceApplied = true;
|
||||||
|
|
||||||
public void unsetInheritanceApplied()
|
public void unsetInheritanceApplied()
|
||||||
|
@ -2120,28 +2087,6 @@
|
||||||
{
|
{
|
||||||
return inheritanceApplied;
|
return inheritanceApplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flushGoalMap()
|
|
||||||
{
|
|
||||||
this.goalMap = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map getGoalsAsMap()
|
|
||||||
{
|
|
||||||
if ( goalMap == null )
|
|
||||||
{
|
|
||||||
goalMap = new HashMap();
|
|
||||||
if ( goals != null )
|
|
||||||
{
|
|
||||||
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
Goal g = (Goal) i.next();
|
|
||||||
goalMap.put( g.getId(), g );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return goalMap;
|
|
||||||
}
|
|
||||||
]]></code>
|
]]></code>
|
||||||
</codeSegment>
|
</codeSegment>
|
||||||
</codeSegments>
|
</codeSegments>
|
||||||
|
@ -2149,7 +2094,7 @@
|
||||||
<class>
|
<class>
|
||||||
<name>Plugin</name>
|
<name>Plugin</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<superClass>GoalContainer</superClass>
|
<superClass>ConfigurationContainer</superClass>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
<name>groupId</name>
|
<name>groupId</name>
|
||||||
|
@ -2179,6 +2124,15 @@
|
||||||
<multiplicity>*</multiplicity>
|
<multiplicity>*</multiplicity>
|
||||||
</association>
|
</association>
|
||||||
</field>
|
</field>
|
||||||
|
<!-- TODO: this is deprecated -->
|
||||||
|
<field>
|
||||||
|
<name>goals</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<association>
|
||||||
|
<type>Goal</type>
|
||||||
|
<multiplicity>*</multiplicity>
|
||||||
|
</association>
|
||||||
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
<codeSegments>
|
<codeSegments>
|
||||||
<codeSegment>
|
<codeSegment>
|
||||||
|
@ -2218,6 +2172,32 @@
|
||||||
{
|
{
|
||||||
return groupId + ":" + artifactId;
|
return groupId + ":" + artifactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
private Map goalMap = null;
|
||||||
|
/** @deprecated */
|
||||||
|
public void flushGoalMap()
|
||||||
|
{
|
||||||
|
this.goalMap = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
public Map getGoalsAsMap()
|
||||||
|
{
|
||||||
|
if ( goalMap == null )
|
||||||
|
{
|
||||||
|
goalMap = new HashMap();
|
||||||
|
if ( goals != null )
|
||||||
|
{
|
||||||
|
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Goal g = (Goal) i.next();
|
||||||
|
goalMap.put( g.getId(), g );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return goalMap;
|
||||||
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</codeSegment>
|
</codeSegment>
|
||||||
</codeSegments>
|
</codeSegments>
|
||||||
|
@ -2225,7 +2205,7 @@
|
||||||
<class>
|
<class>
|
||||||
<name>PluginExecution</name>
|
<name>PluginExecution</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<superClass>GoalContainer</superClass>
|
<superClass>ConfigurationContainer</superClass>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
<name>id</name>
|
<name>id</name>
|
||||||
|
@ -2233,8 +2213,22 @@
|
||||||
<required>true</required>
|
<required>true</required>
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>phase</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<type>String</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>goals</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<association>
|
||||||
|
<type>String</type>
|
||||||
|
<multiplicity>*</multiplicity>
|
||||||
|
</association>
|
||||||
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
</class>
|
</class>
|
||||||
|
<!-- TODO: deprecated -->
|
||||||
<class>
|
<class>
|
||||||
<name>Goal</name>
|
<name>Goal</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
@ -2244,34 +2238,11 @@
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
|
||||||
<name>inherited</name>
|
|
||||||
<version>4.0.0</version>
|
|
||||||
<description><![CDATA[Whether this goal configuration should be propagated to child POMs.]]></description>
|
|
||||||
<type>String</type>
|
|
||||||
</field>
|
|
||||||
<field>
|
<field>
|
||||||
<name>configuration</name>
|
<name>configuration</name>
|
||||||
<type>DOM</type>
|
<type>DOM</type>
|
||||||
</field>
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
<codeSegments>
|
|
||||||
<codeSegment>
|
|
||||||
<code><![CDATA[
|
|
||||||
private boolean inheritanceApplied = true;
|
|
||||||
|
|
||||||
public void unsetInheritanceApplied()
|
|
||||||
{
|
|
||||||
this.inheritanceApplied = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInheritanceApplied()
|
|
||||||
{
|
|
||||||
return inheritanceApplied;
|
|
||||||
}
|
|
||||||
]]></code>
|
|
||||||
</codeSegment>
|
|
||||||
</codeSegments>
|
|
||||||
</class>
|
</class>
|
||||||
<class>
|
<class>
|
||||||
<name>DependencyManagement</name>
|
<name>DependencyManagement</name>
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.modello</groupId>
|
<groupId>org.codehaus.modello</groupId>
|
||||||
<artifactId>modello-maven-plugin</artifactId>
|
<artifactId>modello-maven-plugin</artifactId>
|
||||||
<version>1.0-alpha-2</version>
|
<version>1.0-alpha-3-SNAPSHOT</version>
|
||||||
<!-- version>1.0-alpha-3-SNAPSHOT</version -->
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<model>maven.mdo</model>
|
<model>maven.mdo</model>
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.plugin.descriptor;
|
||||||
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
|
@ -40,7 +41,7 @@ public class PluginDescriptor
|
||||||
private String source;
|
private String source;
|
||||||
|
|
||||||
private boolean inheritedByDefault = true;
|
private boolean inheritedByDefault = true;
|
||||||
|
|
||||||
private List artifacts;
|
private List artifacts;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -55,7 +56,8 @@ public class PluginDescriptor
|
||||||
public void addMojo( MojoDescriptor mojoDescriptor )
|
public void addMojo( MojoDescriptor mojoDescriptor )
|
||||||
throws DuplicateMojoDescriptorException
|
throws DuplicateMojoDescriptorException
|
||||||
{
|
{
|
||||||
// this relies heavily on the equals() and hashCode() for ComponentDescriptor,
|
MojoDescriptor existing = null;
|
||||||
|
// this relies heavily on the equals() and hashCode() for ComponentDescriptor,
|
||||||
// which uses role:roleHint for identity...and roleHint == goalPrefix:goal.
|
// which uses role:roleHint for identity...and roleHint == goalPrefix:goal.
|
||||||
// role does not vary for Mojos.
|
// role does not vary for Mojos.
|
||||||
List mojos = getComponents();
|
List mojos = getComponents();
|
||||||
|
@ -64,8 +66,11 @@ public class PluginDescriptor
|
||||||
{
|
{
|
||||||
int indexOf = mojos.indexOf( mojoDescriptor );
|
int indexOf = mojos.indexOf( mojoDescriptor );
|
||||||
|
|
||||||
MojoDescriptor existing = (MojoDescriptor) mojos.get( indexOf );
|
existing = (MojoDescriptor) mojos.get( indexOf );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( existing != null )
|
||||||
|
{
|
||||||
throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing
|
throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing
|
||||||
.getImplementation(), mojoDescriptor.getImplementation() );
|
.getImplementation(), mojoDescriptor.getImplementation() );
|
||||||
}
|
}
|
||||||
|
@ -191,7 +196,7 @@ public class PluginDescriptor
|
||||||
{
|
{
|
||||||
this.inheritedByDefault = inheritedByDefault;
|
this.inheritedByDefault = inheritedByDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getArtifacts()
|
public List getArtifacts()
|
||||||
{
|
{
|
||||||
return artifacts;
|
return artifacts;
|
||||||
|
@ -216,4 +221,21 @@ public class PluginDescriptor
|
||||||
{
|
{
|
||||||
return 10 + getId().hashCode();
|
return 10 + getId().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MojoDescriptor getMojo( String goal )
|
||||||
|
{
|
||||||
|
// TODO: could we use a map? Maybe if the parent did that for components too, as this is too vulnerable to
|
||||||
|
// changes above not being propogated to the map
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = null;
|
||||||
|
for ( Iterator i = getMojos().iterator(); i.hasNext() && mojoDescriptor == null; )
|
||||||
|
{
|
||||||
|
MojoDescriptor desc = (MojoDescriptor) i.next();
|
||||||
|
if ( goal.equals( desc.getGoal() ) )
|
||||||
|
{
|
||||||
|
mojoDescriptor = desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mojoDescriptor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.DependencyManagement;
|
import org.apache.maven.model.DependencyManagement;
|
||||||
import org.apache.maven.model.Developer;
|
import org.apache.maven.model.Developer;
|
||||||
import org.apache.maven.model.DistributionManagement;
|
import org.apache.maven.model.DistributionManagement;
|
||||||
|
import org.apache.maven.model.Goal;
|
||||||
import org.apache.maven.model.IssueManagement;
|
import org.apache.maven.model.IssueManagement;
|
||||||
import org.apache.maven.model.License;
|
import org.apache.maven.model.License;
|
||||||
import org.apache.maven.model.MailingList;
|
import org.apache.maven.model.MailingList;
|
||||||
|
@ -36,6 +37,8 @@ import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginManagement;
|
import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.model.Reporting;
|
import org.apache.maven.model.Reporting;
|
||||||
import org.apache.maven.model.Scm;
|
import org.apache.maven.model.Scm;
|
||||||
|
import org.apache.maven.model.PluginExecution;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -878,4 +881,67 @@ public class MavenProject
|
||||||
}
|
}
|
||||||
return attachedArtifacts;
|
return attachedArtifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String executionId,
|
||||||
|
String goalId )
|
||||||
|
{
|
||||||
|
Xpp3Dom dom = null;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// I would like to be able to lookup the Mojo object using a key but
|
||||||
|
// we have a limitation in modello that will be remedied shortly. So
|
||||||
|
// for now I have to iterate through and see what we have.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
if ( getBuildPlugins() != null )
|
||||||
|
{
|
||||||
|
for ( Iterator iterator = getBuildPlugins().iterator(); iterator.hasNext(); )
|
||||||
|
{
|
||||||
|
Plugin plugin = (Plugin) iterator.next();
|
||||||
|
|
||||||
|
if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
|
||||||
|
{
|
||||||
|
dom = (Xpp3Dom) plugin.getConfiguration();
|
||||||
|
|
||||||
|
// TODO: this part is deprecated
|
||||||
|
if ( goalId != null )
|
||||||
|
{
|
||||||
|
Goal goal = (Goal) plugin.getGoalsAsMap().get( goalId );
|
||||||
|
if ( goal != null )
|
||||||
|
{
|
||||||
|
Xpp3Dom goalConfiguration = (Xpp3Dom) goal.getConfiguration();
|
||||||
|
if ( goalConfiguration != null )
|
||||||
|
{
|
||||||
|
Xpp3Dom newDom = new Xpp3Dom( goalConfiguration );
|
||||||
|
dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( executionId != null )
|
||||||
|
{
|
||||||
|
PluginExecution execution = (PluginExecution) plugin.getExecutionsAsMap().get( executionId );
|
||||||
|
if ( execution != null )
|
||||||
|
{
|
||||||
|
Xpp3Dom executionConfiguration = (Xpp3Dom) execution.getConfiguration();
|
||||||
|
if ( executionConfiguration != null )
|
||||||
|
{
|
||||||
|
Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
|
||||||
|
dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dom != null )
|
||||||
|
{
|
||||||
|
// make a copy so the original in the POM doesn't get messed with
|
||||||
|
dom = new Xpp3Dom( dom );
|
||||||
|
}
|
||||||
|
|
||||||
|
return dom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.apache.maven.project;
|
package org.apache.maven.project;
|
||||||
|
|
||||||
import org.apache.maven.model.Goal;
|
import org.apache.maven.model.Goal;
|
||||||
import org.apache.maven.model.GoalContainer;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginContainer;
|
import org.apache.maven.model.PluginContainer;
|
||||||
import org.apache.maven.model.PluginExecution;
|
import org.apache.maven.model.PluginExecution;
|
||||||
|
@ -31,9 +30,8 @@ import java.util.TreeMap;
|
||||||
|
|
||||||
public final class ModelUtils
|
public final class ModelUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
|
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
|
||||||
boolean handleAsInheritance )
|
boolean handleAsInheritance )
|
||||||
{
|
{
|
||||||
if ( childContainer == null || parentContainer == null )
|
if ( childContainer == null || parentContainer == null )
|
||||||
{
|
{
|
||||||
|
@ -55,8 +53,8 @@ public final class ModelUtils
|
||||||
|
|
||||||
String parentInherited = parentPlugin.getInherited();
|
String parentInherited = parentPlugin.getInherited();
|
||||||
|
|
||||||
if ( !handleAsInheritance || parentInherited == null
|
if ( !handleAsInheritance || parentInherited == null ||
|
||||||
|| Boolean.valueOf( parentInherited ).booleanValue() )
|
Boolean.valueOf( parentInherited ).booleanValue() )
|
||||||
{
|
{
|
||||||
|
|
||||||
Plugin assembledPlugin = parentPlugin;
|
Plugin assembledPlugin = parentPlugin;
|
||||||
|
@ -109,7 +107,7 @@ public final class ModelUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge the lists of goals that are not attached to an <execution/>
|
// merge the lists of goals that are not attached to an <execution/>
|
||||||
ModelUtils.mergeGoalContainerDefinitions( child, parent, handleAsInheritance );
|
ModelUtils.mergeGoalContainerDefinitions( child, parent );
|
||||||
|
|
||||||
// from here to the end of the method is dealing with merging of the <executions/> section.
|
// from here to the end of the method is dealing with merging of the <executions/> section.
|
||||||
String parentInherited = parent.getInherited();
|
String parentInherited = parent.getInherited();
|
||||||
|
@ -136,7 +134,7 @@ public final class ModelUtils
|
||||||
|
|
||||||
if ( childExecution != null )
|
if ( childExecution != null )
|
||||||
{
|
{
|
||||||
ModelUtils.mergeGoalContainerDefinitions( childExecution, parentExecution, handleAsInheritance );
|
ModelUtils.mergePluginExecutionDefinitions( childExecution, parentExecution );
|
||||||
|
|
||||||
assembled = childExecution;
|
assembled = childExecution;
|
||||||
}
|
}
|
||||||
|
@ -168,8 +166,12 @@ public final class ModelUtils
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mergeGoalContainerDefinitions( GoalContainer child, GoalContainer parent,
|
/**
|
||||||
boolean handleAsInheritance )
|
* @param child
|
||||||
|
* @param parent
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
private static void mergeGoalContainerDefinitions( Plugin child, Plugin parent )
|
||||||
{
|
{
|
||||||
List parentGoals = parent.getGoals();
|
List parentGoals = parent.getGoals();
|
||||||
|
|
||||||
|
@ -186,33 +188,23 @@ public final class ModelUtils
|
||||||
{
|
{
|
||||||
Goal parentGoal = (Goal) it.next();
|
Goal parentGoal = (Goal) it.next();
|
||||||
|
|
||||||
String parentInherited = parentGoal.getInherited();
|
Goal assembledGoal = parentGoal;
|
||||||
|
|
||||||
if ( !handleAsInheritance || parentInherited == null
|
Goal childGoal = (Goal) childGoals.get( parentGoal.getId() );
|
||||||
|| Boolean.valueOf( parentInherited ).booleanValue() )
|
|
||||||
|
if ( childGoal != null )
|
||||||
{
|
{
|
||||||
Goal assembledGoal = parentGoal;
|
Xpp3Dom childGoalConfig = (Xpp3Dom) childGoal.getConfiguration();
|
||||||
|
Xpp3Dom parentGoalConfig = (Xpp3Dom) parentGoal.getConfiguration();
|
||||||
|
|
||||||
Goal childGoal = (Goal) childGoals.get( parentGoal.getId() );
|
childGoalConfig = Xpp3Dom.mergeXpp3Dom( childGoalConfig, parentGoalConfig );
|
||||||
|
|
||||||
if ( childGoal != null )
|
childGoal.setConfiguration( childGoalConfig );
|
||||||
{
|
|
||||||
Xpp3Dom childGoalConfig = (Xpp3Dom) childGoal.getConfiguration();
|
|
||||||
Xpp3Dom parentGoalConfig = (Xpp3Dom) parentGoal.getConfiguration();
|
|
||||||
|
|
||||||
childGoalConfig = Xpp3Dom.mergeXpp3Dom( childGoalConfig, parentGoalConfig );
|
assembledGoal = childGoal;
|
||||||
|
|
||||||
childGoal.setConfiguration( childGoalConfig );
|
|
||||||
|
|
||||||
assembledGoal = childGoal;
|
|
||||||
}
|
|
||||||
else if ( handleAsInheritance && parentInherited == null )
|
|
||||||
{
|
|
||||||
assembledGoal.unsetInheritanceApplied();
|
|
||||||
}
|
|
||||||
|
|
||||||
assembledGoals.put( assembledGoal.getId(), assembledGoal );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assembledGoals.put( assembledGoal.getId(), assembledGoal );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Iterator it = childGoals.entrySet().iterator(); it.hasNext(); )
|
for ( Iterator it = childGoals.entrySet().iterator(); it.hasNext(); )
|
||||||
|
@ -242,4 +234,27 @@ public final class ModelUtils
|
||||||
child.setConfiguration( childConfiguration );
|
child.setConfiguration( childConfiguration );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void mergePluginExecutionDefinitions( PluginExecution child, PluginExecution parent )
|
||||||
|
{
|
||||||
|
List parentGoals = parent.getGoals();
|
||||||
|
|
||||||
|
// if the supplemental goals are non-existent, then nothing related to goals changes.
|
||||||
|
if ( parentGoals != null && !parentGoals.isEmpty() )
|
||||||
|
{
|
||||||
|
List goals = new ArrayList( parentGoals );
|
||||||
|
if ( child.getGoals() != null )
|
||||||
|
{
|
||||||
|
goals.addAll( child.getGoals() );
|
||||||
|
}
|
||||||
|
|
||||||
|
child.setGoals( goals );
|
||||||
|
}
|
||||||
|
|
||||||
|
Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
|
||||||
|
Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
|
||||||
|
|
||||||
|
childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
|
||||||
|
|
||||||
|
child.setConfiguration( childConfiguration );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class DefaultModelInheritanceAssembler
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group id
|
// Group id
|
||||||
if ( child.getGroupId() == null )
|
if ( child.getGroupId() == null )
|
||||||
{
|
{
|
||||||
|
@ -156,7 +156,7 @@ public class DefaultModelInheritanceAssembler
|
||||||
public void mergeProfileWithModel( Model model, Profile profile )
|
public void mergeProfileWithModel( Model model, Profile profile )
|
||||||
{
|
{
|
||||||
assembleModelBaseInheritance( model, profile );
|
assembleModelBaseInheritance( model, profile );
|
||||||
|
|
||||||
assembleBuildBaseInheritance( model.getBuild(), profile.getBuild() );
|
assembleBuildBaseInheritance( model.getBuild(), profile.getBuild() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,10 +262,10 @@ public class DefaultModelInheritanceAssembler
|
||||||
}
|
}
|
||||||
|
|
||||||
childReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
|
childReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
|
||||||
|
|
||||||
childReporting.flushReportPluginMap();
|
childReporting.flushReportPluginMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
assembleDependencyManagementInheritance( child, parent );
|
assembleDependencyManagementInheritance( child, parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ public class DefaultModelInheritanceAssembler
|
||||||
}
|
}
|
||||||
|
|
||||||
dominant.setReportSets( new ArrayList( mergedReportSets.values() ) );
|
dominant.setReportSets( new ArrayList( mergedReportSets.values() ) );
|
||||||
|
|
||||||
dominant.flushReportSetMap();
|
dominant.flushReportSetMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ public class DefaultModelInheritanceAssembler
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Build childBuild = child.getBuild();
|
Build childBuild = child.getBuild();
|
||||||
|
|
||||||
if ( parentBuild != null )
|
if ( parentBuild != null )
|
||||||
|
@ -408,9 +408,9 @@ public class DefaultModelInheritanceAssembler
|
||||||
childBuild = new Build();
|
childBuild = new Build();
|
||||||
child.setBuild( childBuild );
|
child.setBuild( childBuild );
|
||||||
}
|
}
|
||||||
|
|
||||||
// The build has been set but we want to step in here and fill in
|
// The build has been set but we want to step in here and fill in
|
||||||
// values
|
// values that have not been set by the child.
|
||||||
// that have not been set by the child.
|
|
||||||
|
|
||||||
if ( childBuild.getDirectory() == null )
|
if ( childBuild.getDirectory() == null )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue