mirror of https://github.com/apache/maven.git
o Adding support for <executions/>, which means multiple runs of the same goal/set-of-goals with different configs.
o Adding @phase declarations for those mojos that seem to be part of the main build, just for completeness o Added two ITs, to test that <executions/> doesn't mess up the normal operation, and to test multi-execution for a goal. Should resolve: MNG-172. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d8c115acf
commit
d2e1f3c975
|
@ -76,6 +76,11 @@ it0022: Test profile inclusion from profiles.xml (this one is activated by syste
|
|||
it0023: Test profile inclusion from settings.xml (this one is activated by an id
|
||||
in the activeProfiles section).
|
||||
|
||||
it0024: Test usage of <executions/> inside a plugin rather than <goals/>
|
||||
that are directly inside th plugin.
|
||||
|
||||
it0025: Test multiple goal executions with different execution-level configs.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
- generated sources
|
||||
|
|
|
@ -22,3 +22,5 @@ it0020
|
|||
it0021
|
||||
it0022
|
||||
it0023
|
||||
it0024
|
||||
it0025
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
target/classes/org/apache/maven/it0001/Person.class
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1,41 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0024</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
|
||||
<configuration>
|
||||
<source>1.4</source>
|
||||
<target>1.4</target>
|
||||
</configuration>
|
||||
|
||||
<goals>
|
||||
<goal>
|
||||
<id>compile</id>
|
||||
</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</model>
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.maven.it0001;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
assert true;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
target/test.txt
|
||||
target/test2.txt
|
|
@ -0,0 +1 @@
|
|||
core-it:touch
|
|
@ -0,0 +1,44 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.</groupId>
|
||||
<artifactId>maven-it0025</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-core-it-plugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test1</id>
|
||||
|
||||
<configuration>
|
||||
<pluginItem>test.txt</pluginItem>
|
||||
</configuration>
|
||||
|
||||
<goals>
|
||||
<goal>
|
||||
<id>touch</id>
|
||||
</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test2</id>
|
||||
|
||||
<configuration>
|
||||
<pluginItem>test2.txt</pluginItem>
|
||||
</configuration>
|
||||
|
||||
<goals>
|
||||
<goal>
|
||||
<id>touch</id>
|
||||
</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0023;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,9 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.model.Goal;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.plugin.GoalInstance;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
|
@ -110,6 +112,7 @@ public class DefaultLifecycleExecutor
|
|||
ArtifactResolutionException
|
||||
{
|
||||
Map phaseMap = new HashMap();
|
||||
Map goalInstanceMap = new HashMap();
|
||||
|
||||
for ( Iterator i = phases.iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -136,47 +139,119 @@ public class DefaultLifecycleExecutor
|
|||
for ( Iterator i = mappings.keySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
String phase = (String) i.next();
|
||||
|
||||
String task = (String) mappings.get( phase );
|
||||
|
||||
MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
|
||||
List goals = (List) phaseMap.get( phase );
|
||||
if ( !goals.contains( mojoDescriptor.getId() ) )
|
||||
|
||||
addToPhaseMap( phaseMap, phase, mojoDescriptor );
|
||||
|
||||
List matchingGoalInstances = findMatchingGoalInstances( mojoDescriptor, project );
|
||||
|
||||
for ( Iterator instanceIterator = matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
|
||||
{
|
||||
goals.add( mojoDescriptor.getId() );
|
||||
GoalInstance goalInstance = (GoalInstance) instanceIterator.next();
|
||||
|
||||
addToGoalInstanceMap( goalInstanceMap, goalInstance );
|
||||
}
|
||||
}
|
||||
|
||||
processPluginConfiguration( project, session, phaseMap );
|
||||
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 mojo = (MojoDescriptor) j.next();
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
||||
|
||||
if ( mojo.getExecutePhase() != null )
|
||||
{
|
||||
// TODO: is this too broad to execute?
|
||||
execute( Collections.singletonList( mojo.getExecutePhase() ), session );
|
||||
}
|
||||
List instances = (List) goalInstanceMap.get( mojoDescriptor );
|
||||
|
||||
try
|
||||
if ( instances != null )
|
||||
{
|
||||
pluginManager.executeMojo( session, mojo );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
else
|
||||
{
|
||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||
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 version )
|
||||
{
|
||||
String key = Plugin.constructKey( groupId, artifactId );
|
||||
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
|
||||
|
@ -202,14 +277,15 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession, Map phaseMap )
|
||||
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();
|
||||
|
||||
processPluginPhases( plugin, mavenSession, phaseMap );
|
||||
processPluginPhases( plugin, mavenSession, phaseMap, goalInstanceMap );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,8 +295,9 @@ public class DefaultLifecycleExecutor
|
|||
* to execute for that given phase.
|
||||
*
|
||||
* @param session
|
||||
* @param goalInstanceMap
|
||||
*/
|
||||
private void processPluginPhases( Plugin plugin, MavenSession session, Map phaseMap )
|
||||
private void processPluginPhases( Plugin plugin, MavenSession session, Map phaseMap, Map goalInstanceMap )
|
||||
throws LifecycleExecutionException, ArtifactResolutionException
|
||||
{
|
||||
String groupId = plugin.getGroupId();
|
||||
|
@ -232,8 +309,8 @@ public class DefaultLifecycleExecutor
|
|||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(),
|
||||
session.getLocalRepository() );
|
||||
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(), session
|
||||
.getLocalRepository() );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
|
@ -242,40 +319,68 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// 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.
|
||||
// ----------------------------------------------------------------------
|
||||
processGoalContainerPhases( plugin, null, pluginDescriptor, session, plugin.getGoalsAsMap(), phaseMap,
|
||||
goalInstanceMap );
|
||||
|
||||
Map goalMap = plugin.getGoalsAsMap();
|
||||
List executions = plugin.getExecutions();
|
||||
|
||||
if ( pluginDescriptor.getMojos() != null )
|
||||
if ( executions != null )
|
||||
{
|
||||
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
|
||||
for ( Iterator it = executions.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
||||
PluginExecution execution = (PluginExecution) it.next();
|
||||
|
||||
// TODO: remove later
|
||||
if ( mojoDescriptor.getGoal() == null )
|
||||
if ( execution.isInheritanceApplied() )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
"The plugin " + artifactId + " was built with an older version of Maven" );
|
||||
processGoalContainerPhases( plugin, execution, pluginDescriptor, session, execution
|
||||
.getGoalsAsMap(), phaseMap, goalInstanceMap );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Goal goal = (Goal) goalMap.get( mojoDescriptor.getGoal() );
|
||||
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 ( goalMap.isEmpty() )
|
||||
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() );
|
||||
}
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,17 +406,27 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
if ( mojoDescriptor.getPhase() != null )
|
||||
{
|
||||
List goals = (List) phaseMap.get( mojoDescriptor.getPhase() );
|
||||
addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoDescriptor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( goals == null )
|
||||
{
|
||||
String message = "Required phase '" + mojoDescriptor.getPhase() + "' not found";
|
||||
throw new LifecycleExecutionException( message );
|
||||
}
|
||||
if ( !goals.contains( mojoDescriptor.getId() ) )
|
||||
{
|
||||
goals.add( mojoDescriptor.getId() );
|
||||
}
|
||||
private void addToPhaseMap( Map phaseMap, String phase, MojoDescriptor mojoDescriptor )
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -334,20 +449,17 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( phaseGoals != null )
|
||||
{
|
||||
for ( Iterator k = phaseGoals.iterator(); k.hasNext(); )
|
||||
{
|
||||
String goal = (String) k.next();
|
||||
|
||||
goals.add( configureMojo( goal, session, phaseMap ) );
|
||||
|
||||
}
|
||||
goals.addAll( phaseGoals );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
goals.add( configureMojo( task, session, phaseMap ) );
|
||||
MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
|
||||
|
||||
goals.add( mojoDescriptor );
|
||||
}
|
||||
|
||||
return goals;
|
||||
}
|
||||
|
||||
|
@ -361,6 +473,61 @@ public class DefaultLifecycleExecutor
|
|||
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 )
|
||||
throws ArtifactResolutionException, LifecycleExecutionException
|
||||
{
|
||||
|
@ -395,8 +562,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
else
|
||||
{
|
||||
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";
|
||||
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";
|
||||
throw new LifecycleExecutionException( message );
|
||||
}
|
||||
|
||||
|
@ -416,8 +583,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
else
|
||||
{
|
||||
injectHandlerPluginConfiguration( session.getProject(), pluginDescriptor.getGroupId(),
|
||||
pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion() );
|
||||
injectHandlerPluginConfiguration( session.getProject(), pluginDescriptor.getGroupId(), pluginDescriptor
|
||||
.getArtifactId(), pluginDescriptor.getVersion() );
|
||||
}
|
||||
|
||||
MojoDescriptor mojoDescriptor = null;
|
||||
|
@ -436,10 +603,9 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getGroupId() + ":" +
|
||||
pluginDescriptor.getArtifactId() + ":" +
|
||||
pluginDescriptor.getVersion() +
|
||||
" doesn't contain any mojo. Check if it isn't corrupted." );
|
||||
throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getGroupId() + ":"
|
||||
+ pluginDescriptor.getArtifactId() + ":" + pluginDescriptor.getVersion()
|
||||
+ " doesn't contain any mojo. Check if it isn't corrupted." );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor == null )
|
||||
|
|
|
@ -116,7 +116,7 @@ public class DefaultPluginManager
|
|||
{
|
||||
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
|
||||
|
||||
// String key = pluginDescriptor.getId();
|
||||
// String key = pluginDescriptor.getId();
|
||||
// TODO: see comment in getPluginDescriptor
|
||||
String key = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId();
|
||||
|
||||
|
@ -141,7 +141,7 @@ public class DefaultPluginManager
|
|||
|
||||
private PluginDescriptor getPluginDescriptor( String groupId, String artifactId, String version )
|
||||
{
|
||||
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
|
||||
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
|
||||
// TODO: include version, but can't do this in the plugin manager as it is not resolved to the right version
|
||||
// at that point. Instead, move the duplication check to the artifact container, or store it locally based on
|
||||
// the unresolved version?
|
||||
|
@ -156,7 +156,7 @@ public class DefaultPluginManager
|
|||
|
||||
private boolean isPluginInstalled( String pluginKey )
|
||||
{
|
||||
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
|
||||
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
|
||||
// TODO: see comment in getPluginDescriptor
|
||||
return pluginDescriptors.containsKey( pluginKey );
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project,
|
||||
ArtifactRepository localRepository )
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PluginManagerException
|
||||
{
|
||||
|
||||
|
@ -243,13 +243,14 @@ public class DefaultPluginManager
|
|||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new PluginManagerException( "Error occurred in the artifact container attempting to download plugin " +
|
||||
groupId + ":" + artifactId, e );
|
||||
throw new PluginManagerException(
|
||||
"Error occurred in the artifact container attempting to download plugin "
|
||||
+ groupId + ":" + artifactId, e );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) &&
|
||||
version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
|
||||
if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() )
|
||||
&& version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
|
||||
{
|
||||
throw new PluginNotFoundException( e );
|
||||
}
|
||||
|
@ -260,15 +261,15 @@ public class DefaultPluginManager
|
|||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" +
|
||||
artifactId, e );
|
||||
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":"
|
||||
+ artifactId, e );
|
||||
}
|
||||
}
|
||||
return getPluginDescriptor( groupId, artifactId, version );
|
||||
}
|
||||
|
||||
protected void addPlugin( String pluginKey, Artifact pluginArtifact, MavenProject project,
|
||||
ArtifactRepository localRepository )
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, ComponentLookupException, PlexusContainerException
|
||||
{
|
||||
ArtifactResolver artifactResolver = null;
|
||||
|
@ -282,9 +283,9 @@ public class DefaultPluginManager
|
|||
|
||||
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively(
|
||||
Collections.singleton( pluginArtifact ), project.getRemoteArtifactRepositories(), localRepository,
|
||||
metadataSource, artifactFilter );
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections
|
||||
.singleton( pluginArtifact ), project.getRemoteArtifactRepositories(), localRepository, metadataSource,
|
||||
artifactFilter );
|
||||
|
||||
Map resolved = result.getArtifacts();
|
||||
|
||||
|
@ -328,11 +329,13 @@ public class DefaultPluginManager
|
|||
// Mojo execution
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||
public void executeMojo( MavenSession session, GoalInstance goalInstance )
|
||||
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
|
||||
{
|
||||
PlexusContainer pluginContainer = null;
|
||||
|
||||
MojoDescriptor mojoDescriptor = goalInstance.getMojoDescriptor();
|
||||
|
||||
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
||||
{
|
||||
|
||||
|
@ -344,8 +347,8 @@ public class DefaultPluginManager
|
|||
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder,
|
||||
mojoDescriptor.isDependencyResolutionRequired() );
|
||||
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, mojoDescriptor
|
||||
.isDependencyResolutionRequired() );
|
||||
downloadDependencies( session, artifactResolver );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
|
@ -383,11 +386,11 @@ public class DefaultPluginManager
|
|||
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
|
||||
plugin.setLog( mojoLogger );
|
||||
|
||||
String goalId = mojoDescriptor.getGoal();
|
||||
String goalId = goalInstance.getGoalId();
|
||||
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
Xpp3Dom dom = session.getProject().getGoalConfiguration( pluginDescriptor.getGroupId(),
|
||||
pluginDescriptor.getArtifactId(), goalId );
|
||||
|
||||
Xpp3Dom dom = goalInstance.getCalculatedConfiguration();
|
||||
|
||||
PlexusConfiguration pomConfiguration;
|
||||
if ( dom == null )
|
||||
|
@ -403,12 +406,12 @@ public class DefaultPluginManager
|
|||
// override in the POM.
|
||||
validatePomConfiguration( mojoDescriptor, pomConfiguration );
|
||||
|
||||
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
|
||||
mojoDescriptor.getMojoConfiguration() );
|
||||
|
||||
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor
|
||||
.getMojoConfiguration() );
|
||||
|
||||
// TODO: plexus
|
||||
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
|
||||
// mojoDescriptor.getConfiguration() );
|
||||
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
|
||||
// mojoDescriptor.getConfiguration() );
|
||||
|
||||
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator,
|
||||
getLogger() );
|
||||
|
@ -420,17 +423,25 @@ public class DefaultPluginManager
|
|||
// Event monitoring.
|
||||
String event = MavenEvents.MOJO_EXECUTION;
|
||||
EventDispatcher dispatcher = session.getEventDispatcher();
|
||||
|
||||
String goalExecId = goalName;
|
||||
|
||||
if ( goalInstance.getExecutionId() != null )
|
||||
{
|
||||
goalExecId += " {execution: " + goalInstance.getExecutionId() + "}";
|
||||
}
|
||||
|
||||
dispatcher.dispatchStart( event, goalName );
|
||||
dispatcher.dispatchStart( event, goalExecId );
|
||||
try
|
||||
{
|
||||
plugin.execute();
|
||||
|
||||
dispatcher.dispatchEnd( event, goalName );
|
||||
dispatcher.dispatchEnd( event, goalExecId );
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
session.getEventDispatcher().dispatchError( event, goalName, e );
|
||||
session.getEventDispatcher().dispatchError( event, goalExecId, e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
// End event monitoring.
|
||||
|
@ -462,7 +473,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration,
|
||||
ExpressionEvaluator expressionEvaluator, Mojo plugin )
|
||||
ExpressionEvaluator expressionEvaluator, Mojo plugin )
|
||||
throws PluginConfigurationException
|
||||
{
|
||||
// TODO: this should be built in to the configurator, as we presently double process the expressions
|
||||
|
@ -534,8 +545,9 @@ public class DefaultPluginManager
|
|||
}
|
||||
if ( fieldValue != null )
|
||||
{
|
||||
getLogger().warn( "DEPRECATED: using default-value to set the default value of field '" +
|
||||
parameter.getName() + "'" );
|
||||
getLogger().warn(
|
||||
"DEPRECATED: using default-value to set the default value of field '"
|
||||
+ parameter.getName() + "'" );
|
||||
}
|
||||
}
|
||||
catch ( NoSuchFieldException e )
|
||||
|
@ -587,8 +599,8 @@ public class DefaultPluginManager
|
|||
// Make sure the parameter is either editable/configurable, or else is NOT specified in the POM
|
||||
if ( !parameter.isEditable() )
|
||||
{
|
||||
StringBuffer errorMessage = new StringBuffer().append(
|
||||
"ERROR: Cannot override read-only parameter: " );
|
||||
StringBuffer errorMessage = new StringBuffer()
|
||||
.append( "ERROR: Cannot override read-only parameter: " );
|
||||
errorMessage.append( key );
|
||||
errorMessage.append( " in goal: " ).append( goal.getFullGoalName() );
|
||||
|
||||
|
@ -651,7 +663,7 @@ public class DefaultPluginManager
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration,
|
||||
PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator )
|
||||
PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator )
|
||||
throws PluginConfigurationException
|
||||
{
|
||||
ComponentConfigurator configurator = null;
|
||||
|
@ -663,16 +675,16 @@ public class DefaultPluginManager
|
|||
// TODO: should this be known to the component factory instead? And if so, should configuration be part of lookup?
|
||||
if ( StringUtils.isNotEmpty( configuratorId ) )
|
||||
{
|
||||
configurator =
|
||||
(ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configuratorId );
|
||||
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE,
|
||||
configuratorId );
|
||||
}
|
||||
else
|
||||
{
|
||||
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE );
|
||||
}
|
||||
|
||||
configurator.configureComponent( plugin, configuration, expressionEvaluator,
|
||||
pluginContainer.getContainerRealm() );
|
||||
configurator.configureComponent( plugin, configuration, expressionEvaluator, pluginContainer
|
||||
.getContainerRealm() );
|
||||
}
|
||||
catch ( ComponentConfigurationException e )
|
||||
{
|
||||
|
@ -681,7 +693,8 @@ public class DefaultPluginManager
|
|||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginConfigurationException(
|
||||
"Unable to retrieve component configurator for plugin configuration", e );
|
||||
"Unable to retrieve component configurator for plugin configuration",
|
||||
e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -720,7 +733,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
|
||||
String expression )
|
||||
String expression )
|
||||
{
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
|
@ -776,12 +789,22 @@ public class DefaultPluginManager
|
|||
public void initialize()
|
||||
{
|
||||
// TODO: configure this from bootstrap or scan lib
|
||||
artifactFilter = new ExclusionSetFilter( new String[]{"classworlds", "maven-artifact", "maven-core",
|
||||
"maven-model", "maven-monitor", "maven-plugin-api",
|
||||
"maven-plugin-descriptor", "maven-project",
|
||||
"maven-settings", "plexus-container-default",
|
||||
"plexus-utils", "wagon-provider-api", "wagon-ssh",
|
||||
"wagon-http-lightweight", "wagon-file"} );
|
||||
artifactFilter = new ExclusionSetFilter( new String[] {
|
||||
"classworlds",
|
||||
"maven-artifact",
|
||||
"maven-core",
|
||||
"maven-model",
|
||||
"maven-monitor",
|
||||
"maven-plugin-api",
|
||||
"maven-plugin-descriptor",
|
||||
"maven-project",
|
||||
"maven-settings",
|
||||
"plexus-container-default",
|
||||
"plexus-utils",
|
||||
"wagon-provider-api",
|
||||
"wagon-ssh",
|
||||
"wagon-http-lightweight",
|
||||
"wagon-file" } );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -789,7 +812,7 @@ public class DefaultPluginManager
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
|
||||
MavenProjectBuilder mavenProjectBuilder, String scope )
|
||||
MavenProjectBuilder mavenProjectBuilder, String scope )
|
||||
throws ArtifactResolutionException
|
||||
{
|
||||
MavenProject project = context.getProject();
|
||||
|
@ -800,10 +823,8 @@ public class DefaultPluginManager
|
|||
|
||||
boolean systemOnline = !context.getSettings().isOffline();
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||
context.getRemoteRepositories(),
|
||||
context.getLocalRepository(),
|
||||
sourceReader, filter );
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), context
|
||||
.getRemoteRepositories(), context.getLocalRepository(), sourceReader, filter );
|
||||
|
||||
project.addArtifacts( result.getArtifacts().values(), artifactFactory );
|
||||
}
|
||||
|
@ -834,8 +855,8 @@ public class DefaultPluginManager
|
|||
}
|
||||
context.getProject().setPluginArtifacts( pluginArtifacts );
|
||||
|
||||
artifactResolver.resolve( context.getProject().getParentArtifact(), context.getRemoteRepositories(),
|
||||
context.getLocalRepository() );
|
||||
artifactResolver.resolve( context.getProject().getParentArtifact(), context.getRemoteRepositories(), context
|
||||
.getLocalRepository() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,6 @@ package org.apache.maven.plugin;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
|
@ -31,7 +30,7 @@ public interface PluginManager
|
|||
{
|
||||
String ROLE = PluginManager.class.getName();
|
||||
|
||||
void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
|
||||
void executeMojo( MavenSession session, GoalInstance buildStep )
|
||||
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
|
||||
|
||||
PluginDescriptor verifyPlugin( String prefix );
|
||||
|
|
|
@ -2081,32 +2081,13 @@
|
|||
-->
|
||||
|
||||
<class>
|
||||
<name>Plugin</name>
|
||||
<name>GoalContainer</name>
|
||||
<version>4.0.0</version>
|
||||
<fields>
|
||||
<field>
|
||||
<name>groupId</name>
|
||||
<version>4.0.0</version>
|
||||
<type>String</type>
|
||||
<defaultValue>org.apache.maven.plugins</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
<name>artifactId</name>
|
||||
<version>4.0.0</version>
|
||||
<type>String</type>
|
||||
<required>true</required>
|
||||
</field>
|
||||
<field>
|
||||
<name>version</name>
|
||||
<version>4.0.0</version>
|
||||
<required>true</required>
|
||||
<description><![CDATA[The version of the plugin to be used.]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>inherited</name>
|
||||
<version>4.0.0</version>
|
||||
<description><![CDATA[Whether this plugin configuration should be propagated to child POMs.]]></description>
|
||||
<description><![CDATA[Whether this container's configuration should be propagated to child POMs.]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
|
@ -2131,7 +2112,7 @@
|
|||
|
||||
public void unsetInheritanceApplied()
|
||||
{
|
||||
this.inheritanceApplied = true;
|
||||
this.inheritanceApplied = false;
|
||||
}
|
||||
|
||||
public boolean isInheritanceApplied()
|
||||
|
@ -2160,7 +2141,73 @@
|
|||
}
|
||||
return goalMap;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
<class>
|
||||
<name>Plugin</name>
|
||||
<version>4.0.0</version>
|
||||
<superClass>GoalContainer</superClass>
|
||||
<fields>
|
||||
<field>
|
||||
<name>groupId</name>
|
||||
<version>4.0.0</version>
|
||||
<type>String</type>
|
||||
<defaultValue>org.apache.maven.plugins</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
<name>artifactId</name>
|
||||
<version>4.0.0</version>
|
||||
<type>String</type>
|
||||
<required>true</required>
|
||||
</field>
|
||||
<field>
|
||||
<name>version</name>
|
||||
<version>4.0.0</version>
|
||||
<required>true</required>
|
||||
<description><![CDATA[The version of the plugin to be used.]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>executions</name>
|
||||
<version>4.0.0</version>
|
||||
<description>Multiple specifications of a set of goals, each having (possibly) different configuration</description>
|
||||
<association>
|
||||
<type>PluginExecution</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
<codeSegments>
|
||||
<codeSegment>
|
||||
<version>4.0.0</version>
|
||||
<code><![CDATA[
|
||||
private Map executionMap = null;
|
||||
|
||||
public void flushExecutionMap()
|
||||
{
|
||||
this.executionMap = null;
|
||||
}
|
||||
|
||||
public Map getExecutionsAsMap()
|
||||
{
|
||||
if ( executionMap == null )
|
||||
{
|
||||
executionMap = new HashMap();
|
||||
if ( getExecutions() != null )
|
||||
{
|
||||
for ( Iterator i = getExecutions().iterator(); i.hasNext(); )
|
||||
{
|
||||
PluginExecution exec = (PluginExecution) i.next();
|
||||
executionMap.put( exec.getId(), exec );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return executionMap;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return constructKey( groupId, artifactId );
|
||||
|
@ -2174,6 +2221,19 @@
|
|||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
<class>
|
||||
<name>PluginExecution</name>
|
||||
<version>4.0.0</version>
|
||||
<superClass>GoalContainer</superClass>
|
||||
<fields>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<version>4.0.0</version>
|
||||
<required>true</required>
|
||||
<type>String</type>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
<name>Goal</name>
|
||||
<version>4.0.0</version>
|
||||
|
@ -2201,7 +2261,7 @@
|
|||
|
||||
public void unsetInheritanceApplied()
|
||||
{
|
||||
this.inheritanceApplied = true;
|
||||
this.inheritanceApplied = false;
|
||||
}
|
||||
|
||||
public boolean isInheritanceApplied()
|
||||
|
|
|
@ -60,7 +60,7 @@ public class MojoDescriptor
|
|||
private String executePhase;
|
||||
|
||||
private String deprecated;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -121,7 +121,7 @@ public class MojoDescriptor
|
|||
addParameter( parameter );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addParameter( Parameter parameter )
|
||||
throws DuplicateParameterException
|
||||
{
|
||||
|
@ -312,4 +312,67 @@ public class MojoDescriptor
|
|||
{
|
||||
this.inheritedByDefault = inheritedByDefault;
|
||||
}
|
||||
|
||||
public boolean equals( Object object )
|
||||
{
|
||||
if ( this == object )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( object instanceof MojoDescriptor )
|
||||
{
|
||||
MojoDescriptor other = (MojoDescriptor) object;
|
||||
|
||||
if ( !compareObjects( getPluginDescriptor(), other.getPluginDescriptor() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !compareObjects( getGoal(), other.getGoal() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean compareObjects( Object first, Object second )
|
||||
{
|
||||
if ( ( first == null && second != null ) || ( first != null && second == null ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !first.equals( second ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
String goal = getGoal();
|
||||
|
||||
if ( goal != null )
|
||||
{
|
||||
result += goal.hashCode();
|
||||
}
|
||||
|
||||
PluginDescriptor pd = getPluginDescriptor();
|
||||
|
||||
if ( pd != null )
|
||||
{
|
||||
result -= pd.hashCode();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ public class PluginDescriptor
|
|||
|
||||
MojoDescriptor existing = (MojoDescriptor) mojos.get( indexOf );
|
||||
|
||||
throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing.getImplementation(), mojoDescriptor.getImplementation() );
|
||||
throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing
|
||||
.getImplementation(), mojoDescriptor.getImplementation() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -100,12 +101,12 @@ public class PluginDescriptor
|
|||
{
|
||||
return groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
|
||||
|
||||
public String getPluginLookupKey()
|
||||
{
|
||||
return groupId + ":" + artifactId;
|
||||
}
|
||||
|
||||
|
||||
public String getId()
|
||||
{
|
||||
String id = constructPluginKey( groupId, artifactId, version );
|
||||
|
@ -188,4 +189,19 @@ public class PluginDescriptor
|
|||
{
|
||||
this.inheritedByDefault = inheritedByDefault;
|
||||
}
|
||||
|
||||
public boolean equals( Object object )
|
||||
{
|
||||
if ( this == object )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return getId().equals( ( (PluginDescriptor) object ).getId() );
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return 10 + getId().hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
* @version $Id$
|
||||
* @goal compile
|
||||
* @phase compile
|
||||
* @requiresDependencyResolution compile
|
||||
* @description Compiles application sources
|
||||
* @todo change debug parameter type to Boolean
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal testCompile
|
||||
* @phase test-compile
|
||||
* @description Compiles test sources
|
||||
* @requiresDependencyResolution test
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.File;
|
|||
* @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a>
|
||||
* @version $Id$
|
||||
* @goal deploy
|
||||
* @phase deploy
|
||||
*/
|
||||
public class DeployMojo
|
||||
extends AbstractMojo
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.File;
|
|||
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
|
||||
* @version $Id$
|
||||
* @goal install
|
||||
* @phase install
|
||||
*/
|
||||
public class InstallMojo
|
||||
extends AbstractInstallMojo
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.io.File;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal descriptor
|
||||
* @phase generate-resources
|
||||
*/
|
||||
public class DescriptorGeneratorMojo
|
||||
extends AbstractGeneratorMojo
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.TreeMap;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal resources
|
||||
* @phase process-resources
|
||||
* @description copy application resources
|
||||
*/
|
||||
public class ResourcesMojo
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal testResources
|
||||
* @phase process-test-resources
|
||||
* @description copy test resources
|
||||
*/
|
||||
public class TestResourcesMojo
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.StringTokenizer;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal test
|
||||
* @phase test
|
||||
* @description Run tests using surefire
|
||||
* @todo make version of junit and surefire configurable
|
||||
* @todo make report to be produced configurable
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.model.Goal;
|
||||
import org.apache.maven.model.GoalContainer;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginContainer;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,12 +35,12 @@ public final class ModelUtils
|
|||
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
|
||||
boolean handleAsInheritance )
|
||||
{
|
||||
if( childContainer == null || parentContainer == null )
|
||||
if ( childContainer == null || parentContainer == null )
|
||||
{
|
||||
// nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List parentPlugins = parentContainer.getPlugins();
|
||||
|
||||
if ( parentPlugins != null && !parentPlugins.isEmpty() )
|
||||
|
@ -50,13 +52,13 @@ public final class ModelUtils
|
|||
for ( Iterator it = parentPlugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin parentPlugin = (Plugin) it.next();
|
||||
|
||||
|
||||
String parentInherited = parentPlugin.getInherited();
|
||||
|
||||
if ( !handleAsInheritance || parentInherited == null
|
||||
|| Boolean.valueOf( parentInherited ).booleanValue() )
|
||||
{
|
||||
|
||||
|
||||
Plugin assembledPlugin = parentPlugin;
|
||||
|
||||
Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() );
|
||||
|
@ -88,24 +90,87 @@ public final class ModelUtils
|
|||
}
|
||||
|
||||
childContainer.setPlugins( new ArrayList( assembledPlugins.values() ) );
|
||||
|
||||
|
||||
childContainer.flushPluginMap();
|
||||
}
|
||||
}
|
||||
|
||||
public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance )
|
||||
{
|
||||
if( child == null || parent == null )
|
||||
if ( child == null || parent == null )
|
||||
{
|
||||
// nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( child.getVersion() == null && parent.getVersion() != null )
|
||||
{
|
||||
child.setVersion( parent.getVersion() );
|
||||
}
|
||||
|
||||
// merge the lists of goals that are not attached to an <execution/>
|
||||
ModelUtils.mergeGoalContainerDefinitions( child, parent, handleAsInheritance );
|
||||
|
||||
// from here to the end of the method is dealing with merging of the <executions/> section.
|
||||
String parentInherited = parent.getInherited();
|
||||
|
||||
boolean parentIsInherited = parentInherited == null || Boolean.valueOf( parentInherited ).booleanValue();
|
||||
|
||||
List parentExecutions = parent.getExecutions();
|
||||
|
||||
if ( parentExecutions != null && !parentExecutions.isEmpty() )
|
||||
{
|
||||
Map assembledExecutions = new TreeMap();
|
||||
|
||||
Map childExecutions = child.getExecutionsAsMap();
|
||||
|
||||
for ( Iterator it = parentExecutions.iterator(); it.hasNext(); )
|
||||
{
|
||||
PluginExecution parentExecution = (PluginExecution) it.next();
|
||||
|
||||
if ( !handleAsInheritance || parentIsInherited )
|
||||
{
|
||||
PluginExecution assembled = parentExecution;
|
||||
|
||||
PluginExecution childExecution = (PluginExecution) childExecutions.get( parentExecution.getId() );
|
||||
|
||||
if ( childExecution != null )
|
||||
{
|
||||
ModelUtils.mergeGoalContainerDefinitions( childExecution, parentExecution, handleAsInheritance );
|
||||
|
||||
assembled = childExecution;
|
||||
}
|
||||
else if ( handleAsInheritance && parentInherited == null )
|
||||
{
|
||||
parentExecution.unsetInheritanceApplied();
|
||||
}
|
||||
|
||||
assembledExecutions.put( assembled.getId(), assembled );
|
||||
}
|
||||
}
|
||||
|
||||
for ( Iterator it = childExecutions.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
String id = (String) entry.getKey();
|
||||
|
||||
if ( !assembledExecutions.containsKey( id ) )
|
||||
{
|
||||
assembledExecutions.put( id, entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
child.setExecutions( new ArrayList( assembledExecutions.values() ) );
|
||||
|
||||
child.flushExecutionMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void mergeGoalContainerDefinitions( GoalContainer child, GoalContainer parent,
|
||||
boolean handleAsInheritance )
|
||||
{
|
||||
List parentGoals = parent.getGoals();
|
||||
|
||||
// if the supplemental goals are non-existent, then nothing related to goals changes.
|
||||
|
@ -141,8 +206,7 @@ public final class ModelUtils
|
|||
|
||||
assembledGoal = childGoal;
|
||||
}
|
||||
|
||||
if ( handleAsInheritance && parentInherited == null )
|
||||
else if ( handleAsInheritance && parentInherited == null )
|
||||
{
|
||||
assembledGoal.unsetInheritanceApplied();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/*
|
||||
* 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 ModelUtilsTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testShouldInheritOnePluginWithExecution()
|
||||
{
|
||||
Plugin parent = new Plugin();
|
||||
parent.setArtifactId( "testArtifact" );
|
||||
parent.setGroupId( "testGroup" );
|
||||
parent.setVersion( "1.0" );
|
||||
|
||||
PluginExecution parentExecution = new PluginExecution();
|
||||
parentExecution.setId( "testExecution" );
|
||||
|
||||
parent.addExecution( parentExecution );
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "testArtifact" );
|
||||
child.setGroupId( "testGroup" );
|
||||
child.setVersion( "1.0" );
|
||||
|
||||
ModelUtils.mergePluginDefinitions( child, parent, false );
|
||||
|
||||
assertEquals( 1, child.getExecutions().size() );
|
||||
}
|
||||
|
||||
public void testShouldMergeInheritedPluginHavingExecutionWithLocalPlugin()
|
||||
{
|
||||
Plugin parent = new Plugin();
|
||||
parent.setArtifactId( "testArtifact" );
|
||||
parent.setGroupId( "testGroup" );
|
||||
parent.setVersion( "1.0" );
|
||||
|
||||
PluginExecution parentExecution = new PluginExecution();
|
||||
parentExecution.setId( "testExecution" );
|
||||
|
||||
parent.addExecution( parentExecution );
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "testArtifact" );
|
||||
child.setGroupId( "testGroup" );
|
||||
child.setVersion( "1.0" );
|
||||
|
||||
PluginExecution childExecution = new PluginExecution();
|
||||
childExecution.setId( "testExecution2" );
|
||||
|
||||
child.addExecution( childExecution );
|
||||
|
||||
ModelUtils.mergePluginDefinitions( child, parent, false );
|
||||
|
||||
assertEquals( 2, child.getExecutions().size() );
|
||||
}
|
||||
|
||||
public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse()
|
||||
{
|
||||
Plugin parent = new Plugin();
|
||||
parent.setArtifactId( "testArtifact" );
|
||||
parent.setGroupId( "testGroup" );
|
||||
parent.setVersion( "1.0" );
|
||||
parent.setInherited( "false" );
|
||||
|
||||
PluginExecution parentExecution = new PluginExecution();
|
||||
parentExecution.setId( "testExecution" );
|
||||
|
||||
parent.addExecution( parentExecution );
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "testArtifact" );
|
||||
child.setGroupId( "testGroup" );
|
||||
child.setVersion( "1.0" );
|
||||
|
||||
ModelUtils.mergePluginDefinitions( child, parent, true );
|
||||
|
||||
assertEquals( 0, child.getExecutions().size() );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue