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:
John Dennis Casey 2005-06-13 02:47:57 +00:00
parent 0d8c115acf
commit d2e1f3c975
28 changed files with 1010 additions and 161 deletions

View File

@ -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 it0023: Test profile inclusion from settings.xml (this one is activated by an id
in the activeProfiles section). 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 - generated sources

View File

@ -22,3 +22,5 @@ it0020
it0021 it0021
it0022 it0022
it0023 it0023
it0024
it0025

View File

@ -0,0 +1 @@
target/classes/org/apache/maven/it0001/Person.class

View File

@ -0,0 +1 @@
test

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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() );
}
}

View File

@ -0,0 +1,2 @@
target/test.txt
target/test2.txt

View File

@ -0,0 +1 @@
core-it:touch

View File

@ -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>

View File

@ -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;
}
}

View File

@ -22,7 +22,9 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Goal; 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.PluginManagement; import org.apache.maven.model.PluginManagement;
import org.apache.maven.plugin.GoalInstance;
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;
@ -110,6 +112,7 @@ public class DefaultLifecycleExecutor
ArtifactResolutionException ArtifactResolutionException
{ {
Map phaseMap = new HashMap(); Map phaseMap = new HashMap();
Map goalInstanceMap = new HashMap();
for ( Iterator i = phases.iterator(); i.hasNext(); ) for ( Iterator i = phases.iterator(); i.hasNext(); )
{ {
@ -136,47 +139,119 @@ public class DefaultLifecycleExecutor
for ( Iterator i = mappings.keySet().iterator(); i.hasNext(); ) for ( Iterator i = mappings.keySet().iterator(); i.hasNext(); )
{ {
String phase = (String) i.next(); String phase = (String) i.next();
String task = (String) mappings.get( phase ); String task = (String) mappings.get( phase );
MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap ); 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(); ) for ( Iterator i = tasks.iterator(); i.hasNext(); )
{ {
String task = (String) i.next(); 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 ); List goals = processGoalChain( task, session, phaseMap );
for ( Iterator j = goals.iterator(); j.hasNext(); ) for ( Iterator j = goals.iterator(); j.hasNext(); )
{ {
MojoDescriptor mojo = (MojoDescriptor) j.next(); MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
if ( mojo.getExecutePhase() != null ) List instances = (List) goalInstanceMap.get( mojoDescriptor );
{
// TODO: is this too broad to execute?
execute( Collections.singletonList( mojo.getExecutePhase() ), session );
}
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, private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId,
String version ) String version )
{ {
String key = Plugin.constructKey( groupId, artifactId ); String key = Plugin.constructKey( groupId, artifactId );
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key ); 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 throws LifecycleExecutionException, ArtifactResolutionException
{ {
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{ {
Plugin plugin = (Plugin) i.next(); 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. * to execute for that given phase.
* *
* @param session * @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 throws LifecycleExecutionException, ArtifactResolutionException
{ {
String groupId = plugin.getGroupId(); String groupId = plugin.getGroupId();
@ -232,8 +309,8 @@ public class DefaultLifecycleExecutor
PluginDescriptor pluginDescriptor; PluginDescriptor pluginDescriptor;
try try
{ {
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(), pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, session.getProject(), session
session.getLocalRepository() ); .getLocalRepository() );
} }
catch ( PluginManagerException e ) catch ( PluginManagerException e )
{ {
@ -242,40 +319,68 @@ public class DefaultLifecycleExecutor
if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() ) if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
{ {
// ---------------------------------------------------------------------- processGoalContainerPhases( plugin, null, pluginDescriptor, session, plugin.getGoalsAsMap(), phaseMap,
// Look to see if the plugin configuration specifies particular mojos goalInstanceMap );
// within the plugin. If this is the case then simply configure the
// mojos the user has specified and ignore the rest.
// ----------------------------------------------------------------------
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 ( execution.isInheritanceApplied() )
if ( mojoDescriptor.getGoal() == null )
{ {
throw new LifecycleExecutionException( processGoalContainerPhases( plugin, execution, pluginDescriptor, session, execution
"The plugin " + artifactId + " was built with an older version of Maven" ); .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() ); configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
else if ( goal != null ) addToGoalInstanceMap( goalInstanceMap, new GoalInstance( plugin, execution, goal,
{ mojoDescriptor ) );
// 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() );
}
} }
} }
} }
@ -301,17 +406,27 @@ public class DefaultLifecycleExecutor
{ {
if ( mojoDescriptor.getPhase() != null ) if ( mojoDescriptor.getPhase() != null )
{ {
List goals = (List) phaseMap.get( mojoDescriptor.getPhase() ); addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoDescriptor );
}
}
}
if ( goals == null ) private void addToPhaseMap( Map phaseMap, String phase, MojoDescriptor mojoDescriptor )
{ throws LifecycleExecutionException
String message = "Required phase '" + mojoDescriptor.getPhase() + "' not found"; {
throw new LifecycleExecutionException( message ); if ( phase != null )
} {
if ( !goals.contains( mojoDescriptor.getId() ) ) List goals = (List) phaseMap.get( phase );
{
goals.add( mojoDescriptor.getId() ); 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 ) if ( phaseGoals != null )
{ {
for ( Iterator k = phaseGoals.iterator(); k.hasNext(); ) goals.addAll( phaseGoals );
{
String goal = (String) k.next();
goals.add( configureMojo( goal, session, phaseMap ) );
}
} }
} }
} }
else else
{ {
goals.add( configureMojo( task, session, phaseMap ) ); MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
goals.add( mojoDescriptor );
} }
return goals; return goals;
} }
@ -361,6 +473,61 @@ public class DefaultLifecycleExecutor
return mojoDescriptor; 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
{ {
@ -395,8 +562,8 @@ 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 );
} }
@ -416,8 +583,8 @@ public class DefaultLifecycleExecutor
} }
else else
{ {
injectHandlerPluginConfiguration( session.getProject(), pluginDescriptor.getGroupId(), injectHandlerPluginConfiguration( session.getProject(), pluginDescriptor.getGroupId(), pluginDescriptor
pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion() ); .getArtifactId(), pluginDescriptor.getVersion() );
} }
MojoDescriptor mojoDescriptor = null; MojoDescriptor mojoDescriptor = null;
@ -436,10 +603,9 @@ public class DefaultLifecycleExecutor
} }
else else
{ {
throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getGroupId() + ":" + throw new LifecycleExecutionException( "The plugin " + pluginDescriptor.getGroupId() + ":"
pluginDescriptor.getArtifactId() + ":" + + pluginDescriptor.getArtifactId() + ":" + pluginDescriptor.getVersion()
pluginDescriptor.getVersion() + + " doesn't contain any mojo. Check if it isn't corrupted." );
" doesn't contain any mojo. Check if it isn't corrupted." );
} }
if ( mojoDescriptor == null ) if ( mojoDescriptor == null )

View File

@ -116,7 +116,7 @@ public class DefaultPluginManager
{ {
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor; PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
// String key = pluginDescriptor.getId(); // String key = pluginDescriptor.getId();
// TODO: see comment in getPluginDescriptor // TODO: see comment in getPluginDescriptor
String key = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId(); String key = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId();
@ -141,7 +141,7 @@ public class DefaultPluginManager
private PluginDescriptor getPluginDescriptor( String groupId, String artifactId, String version ) 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 // 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 // at that point. Instead, move the duplication check to the artifact container, or store it locally based on
// the unresolved version? // the unresolved version?
@ -156,7 +156,7 @@ public class DefaultPluginManager
private boolean isPluginInstalled( String pluginKey ) private boolean isPluginInstalled( String pluginKey )
{ {
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version ); // String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
// TODO: see comment in getPluginDescriptor // TODO: see comment in getPluginDescriptor
return pluginDescriptors.containsKey( pluginKey ); return pluginDescriptors.containsKey( pluginKey );
} }
@ -176,7 +176,7 @@ public class DefaultPluginManager
} }
public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project, public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException throws ArtifactResolutionException, PluginManagerException
{ {
@ -243,13 +243,14 @@ public class DefaultPluginManager
} }
catch ( PlexusContainerException e ) catch ( PlexusContainerException e )
{ {
throw new PluginManagerException( "Error occurred in the artifact container attempting to download plugin " + throw new PluginManagerException(
groupId + ":" + artifactId, e ); "Error occurred in the artifact container attempting to download plugin "
+ groupId + ":" + artifactId, e );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() )
version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) ) && version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
{ {
throw new PluginNotFoundException( e ); throw new PluginNotFoundException( e );
} }
@ -260,15 +261,15 @@ public class DefaultPluginManager
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" + throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":"
artifactId, e ); + artifactId, e );
} }
} }
return getPluginDescriptor( groupId, artifactId, version ); return getPluginDescriptor( groupId, artifactId, version );
} }
protected void addPlugin( String pluginKey, Artifact pluginArtifact, MavenProject project, protected void addPlugin( String pluginKey, Artifact pluginArtifact, MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, ComponentLookupException, PlexusContainerException throws ArtifactResolutionException, ComponentLookupException, PlexusContainerException
{ {
ArtifactResolver artifactResolver = null; ArtifactResolver artifactResolver = null;
@ -282,9 +283,9 @@ public class DefaultPluginManager
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder ); MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections
Collections.singleton( pluginArtifact ), project.getRemoteArtifactRepositories(), localRepository, .singleton( pluginArtifact ), project.getRemoteArtifactRepositories(), localRepository, metadataSource,
metadataSource, artifactFilter ); artifactFilter );
Map resolved = result.getArtifacts(); Map resolved = result.getArtifacts();
@ -328,11 +329,13 @@ public class DefaultPluginManager
// Mojo execution // Mojo execution
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor ) public void executeMojo( MavenSession session, GoalInstance goalInstance )
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
{ {
PlexusContainer pluginContainer = null; PlexusContainer pluginContainer = null;
MojoDescriptor mojoDescriptor = goalInstance.getMojoDescriptor();
if ( mojoDescriptor.isDependencyResolutionRequired() != null ) if ( mojoDescriptor.isDependencyResolutionRequired() != null )
{ {
@ -344,8 +347,8 @@ public class DefaultPluginManager
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE ); artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, mojoDescriptor
mojoDescriptor.isDependencyResolutionRequired() ); .isDependencyResolutionRequired() );
downloadDependencies( session, artifactResolver ); downloadDependencies( session, artifactResolver );
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
@ -383,11 +386,11 @@ 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 = mojoDescriptor.getGoal(); String goalId = goalInstance.getGoalId();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = session.getProject().getGoalConfiguration( pluginDescriptor.getGroupId(),
pluginDescriptor.getArtifactId(), goalId ); Xpp3Dom dom = goalInstance.getCalculatedConfiguration();
PlexusConfiguration pomConfiguration; PlexusConfiguration pomConfiguration;
if ( dom == null ) if ( dom == null )
@ -403,12 +406,12 @@ public class DefaultPluginManager
// override in the POM. // override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration ); validatePomConfiguration( mojoDescriptor, pomConfiguration );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor
mojoDescriptor.getMojoConfiguration() ); .getMojoConfiguration() );
// TODO: plexus // TODO: plexus
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, // PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
// mojoDescriptor.getConfiguration() ); // mojoDescriptor.getConfiguration() );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator, ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator,
getLogger() ); getLogger() );
@ -420,17 +423,25 @@ public class DefaultPluginManager
// Event monitoring. // Event monitoring.
String event = MavenEvents.MOJO_EXECUTION; String event = MavenEvents.MOJO_EXECUTION;
EventDispatcher dispatcher = session.getEventDispatcher(); EventDispatcher dispatcher = session.getEventDispatcher();
String goalExecId = goalName;
if ( goalInstance.getExecutionId() != null )
{
goalExecId += " {execution: " + goalInstance.getExecutionId() + "}";
}
dispatcher.dispatchStart( event, goalName ); dispatcher.dispatchStart( event, goalExecId );
try try
{ {
plugin.execute(); plugin.execute();
dispatcher.dispatchEnd( event, goalName ); dispatcher.dispatchEnd( event, goalExecId );
} }
catch ( MojoExecutionException e ) catch ( MojoExecutionException e )
{ {
session.getEventDispatcher().dispatchError( event, goalName, e ); session.getEventDispatcher().dispatchError( event, goalExecId, e );
throw e; throw e;
} }
// End event monitoring. // End event monitoring.
@ -462,7 +473,7 @@ public class DefaultPluginManager
} }
private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration, private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator, Mojo plugin ) ExpressionEvaluator expressionEvaluator, Mojo plugin )
throws PluginConfigurationException throws PluginConfigurationException
{ {
// TODO: this should be built in to the configurator, as we presently double process the expressions // 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 ) if ( fieldValue != null )
{ {
getLogger().warn( "DEPRECATED: using default-value to set the default value of field '" + getLogger().warn(
parameter.getName() + "'" ); "DEPRECATED: using default-value to set the default value of field '"
+ parameter.getName() + "'" );
} }
} }
catch ( NoSuchFieldException e ) 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 // Make sure the parameter is either editable/configurable, or else is NOT specified in the POM
if ( !parameter.isEditable() ) if ( !parameter.isEditable() )
{ {
StringBuffer errorMessage = new StringBuffer().append( StringBuffer errorMessage = new StringBuffer()
"ERROR: Cannot override read-only parameter: " ); .append( "ERROR: Cannot override read-only parameter: " );
errorMessage.append( key ); errorMessage.append( key );
errorMessage.append( " in goal: " ).append( goal.getFullGoalName() ); errorMessage.append( " in goal: " ).append( goal.getFullGoalName() );
@ -651,7 +663,7 @@ public class DefaultPluginManager
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration,
PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator ) PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator )
throws PluginConfigurationException throws PluginConfigurationException
{ {
ComponentConfigurator configurator = null; 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? // TODO: should this be known to the component factory instead? And if so, should configuration be part of lookup?
if ( StringUtils.isNotEmpty( configuratorId ) ) if ( StringUtils.isNotEmpty( configuratorId ) )
{ {
configurator = configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE,
(ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configuratorId ); configuratorId );
} }
else else
{ {
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE ); configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE );
} }
configurator.configureComponent( plugin, configuration, expressionEvaluator, configurator.configureComponent( plugin, configuration, expressionEvaluator, pluginContainer
pluginContainer.getContainerRealm() ); .getContainerRealm() );
} }
catch ( ComponentConfigurationException e ) catch ( ComponentConfigurationException e )
{ {
@ -681,7 +693,8 @@ public class DefaultPluginManager
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginConfigurationException( throw new PluginConfigurationException(
"Unable to retrieve component configurator for plugin configuration", e ); "Unable to retrieve component configurator for plugin configuration",
e );
} }
finally finally
{ {
@ -720,7 +733,7 @@ public class DefaultPluginManager
} }
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter, public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
String expression ) String expression )
{ {
StringBuffer message = new StringBuffer(); StringBuffer message = new StringBuffer();
@ -776,12 +789,22 @@ public class DefaultPluginManager
public void initialize() public void initialize()
{ {
// TODO: configure this from bootstrap or scan lib // TODO: configure this from bootstrap or scan lib
artifactFilter = new ExclusionSetFilter( new String[]{"classworlds", "maven-artifact", "maven-core", artifactFilter = new ExclusionSetFilter( new String[] {
"maven-model", "maven-monitor", "maven-plugin-api", "classworlds",
"maven-plugin-descriptor", "maven-project", "maven-artifact",
"maven-settings", "plexus-container-default", "maven-core",
"plexus-utils", "wagon-provider-api", "wagon-ssh", "maven-model",
"wagon-http-lightweight", "wagon-file"} ); "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, private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder, String scope ) MavenProjectBuilder mavenProjectBuilder, String scope )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
MavenProject project = context.getProject(); MavenProject project = context.getProject();
@ -800,10 +823,8 @@ public class DefaultPluginManager
boolean systemOnline = !context.getSettings().isOffline(); boolean systemOnline = !context.getSettings().isOffline();
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), context
context.getRemoteRepositories(), .getRemoteRepositories(), context.getLocalRepository(), sourceReader, filter );
context.getLocalRepository(),
sourceReader, filter );
project.addArtifacts( result.getArtifacts().values(), artifactFactory ); project.addArtifacts( result.getArtifacts().values(), artifactFactory );
} }
@ -834,8 +855,8 @@ public class DefaultPluginManager
} }
context.getProject().setPluginArtifacts( pluginArtifacts ); context.getProject().setPluginArtifacts( pluginArtifacts );
artifactResolver.resolve( context.getProject().getParentArtifact(), context.getRemoteRepositories(), artifactResolver.resolve( context.getProject().getParentArtifact(), context.getRemoteRepositories(), context
context.getLocalRepository() ); .getLocalRepository() );
} }
} }

View File

@ -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 ) );
}
}
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.plugin;
import org.apache.maven.artifact.repository.ArtifactRepository; 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.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
@ -31,7 +30,7 @@ public interface PluginManager
{ {
String ROLE = PluginManager.class.getName(); String ROLE = PluginManager.class.getName();
void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor ) void executeMojo( MavenSession session, GoalInstance buildStep )
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException; throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
PluginDescriptor verifyPlugin( String prefix ); PluginDescriptor verifyPlugin( String prefix );

View File

@ -2081,32 +2081,13 @@
--> -->
<class> <class>
<name>Plugin</name> <name>GoalContainer</name>
<version>4.0.0</version> <version>4.0.0</version>
<fields> <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> <field>
<name>inherited</name> <name>inherited</name>
<version>4.0.0</version> <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> <type>String</type>
</field> </field>
<field> <field>
@ -2131,7 +2112,7 @@
public void unsetInheritanceApplied() public void unsetInheritanceApplied()
{ {
this.inheritanceApplied = true; this.inheritanceApplied = false;
} }
public boolean isInheritanceApplied() public boolean isInheritanceApplied()
@ -2160,7 +2141,73 @@
} }
return goalMap; 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() public String getKey()
{ {
return constructKey( groupId, artifactId ); return constructKey( groupId, artifactId );
@ -2174,6 +2221,19 @@
</codeSegment> </codeSegment>
</codeSegments> </codeSegments>
</class> </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> <class>
<name>Goal</name> <name>Goal</name>
<version>4.0.0</version> <version>4.0.0</version>
@ -2201,7 +2261,7 @@
public void unsetInheritanceApplied() public void unsetInheritanceApplied()
{ {
this.inheritanceApplied = true; this.inheritanceApplied = false;
} }
public boolean isInheritanceApplied() public boolean isInheritanceApplied()

View File

@ -60,7 +60,7 @@ public class MojoDescriptor
private String executePhase; private String executePhase;
private String deprecated; private String deprecated;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -121,7 +121,7 @@ public class MojoDescriptor
addParameter( parameter ); addParameter( parameter );
} }
} }
public void addParameter( Parameter parameter ) public void addParameter( Parameter parameter )
throws DuplicateParameterException throws DuplicateParameterException
{ {
@ -312,4 +312,67 @@ public class MojoDescriptor
{ {
this.inheritedByDefault = inheritedByDefault; 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;
}
} }

View File

@ -64,7 +64,8 @@ public class PluginDescriptor
MojoDescriptor existing = (MojoDescriptor) mojos.get( indexOf ); 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 else
{ {
@ -100,12 +101,12 @@ public class PluginDescriptor
{ {
return groupId + ":" + artifactId + ":" + version; return groupId + ":" + artifactId + ":" + version;
} }
public String getPluginLookupKey() public String getPluginLookupKey()
{ {
return groupId + ":" + artifactId; return groupId + ":" + artifactId;
} }
public String getId() public String getId()
{ {
String id = constructPluginKey( groupId, artifactId, version ); String id = constructPluginKey( groupId, artifactId, version );
@ -188,4 +189,19 @@ public class PluginDescriptor
{ {
this.inheritedByDefault = inheritedByDefault; 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();
}
} }

View File

@ -20,6 +20,7 @@ import java.util.List;
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$ * @version $Id$
* @goal compile * @goal compile
* @phase compile
* @requiresDependencyResolution compile * @requiresDependencyResolution compile
* @description Compiles application sources * @description Compiles application sources
* @todo change debug parameter type to Boolean * @todo change debug parameter type to Boolean

View File

@ -22,6 +22,7 @@ import java.util.List;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal testCompile * @goal testCompile
* @phase test-compile
* @description Compiles test sources * @description Compiles test sources
* @requiresDependencyResolution test * @requiresDependencyResolution test
*/ */

View File

@ -35,6 +35,7 @@ import java.io.File;
* @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a> * @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a>
* @version $Id$ * @version $Id$
* @goal deploy * @goal deploy
* @phase deploy
*/ */
public class DeployMojo public class DeployMojo
extends AbstractMojo extends AbstractMojo

View File

@ -31,6 +31,7 @@ import java.io.File;
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$ * @version $Id$
* @goal install * @goal install
* @phase install
*/ */
public class InstallMojo public class InstallMojo
extends AbstractInstallMojo extends AbstractInstallMojo

View File

@ -29,6 +29,7 @@ import java.io.File;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal descriptor * @goal descriptor
* @phase generate-resources
*/ */
public class DescriptorGeneratorMojo public class DescriptorGeneratorMojo
extends AbstractGeneratorMojo extends AbstractGeneratorMojo

View File

@ -34,6 +34,7 @@ import java.util.TreeMap;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal resources * @goal resources
* @phase process-resources
* @description copy application resources * @description copy application resources
*/ */
public class ResourcesMojo public class ResourcesMojo

View File

@ -25,6 +25,7 @@ import java.util.List;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal testResources * @goal testResources
* @phase process-test-resources
* @description copy test resources * @description copy test resources
*/ */
public class TestResourcesMojo public class TestResourcesMojo

View File

@ -37,6 +37,7 @@ 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>
* @version $Id$ * @version $Id$
* @goal test * @goal test
* @phase test
* @description Run tests using surefire * @description Run tests using surefire
* @todo make version of junit and surefire configurable * @todo make version of junit and surefire configurable
* @todo make report to be produced configurable * @todo make report to be produced configurable

View File

@ -1,8 +1,10 @@
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.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,12 +35,12 @@ 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 )
{ {
// nothing to do. // nothing to do.
return; return;
} }
List parentPlugins = parentContainer.getPlugins(); List parentPlugins = parentContainer.getPlugins();
if ( parentPlugins != null && !parentPlugins.isEmpty() ) if ( parentPlugins != null && !parentPlugins.isEmpty() )
@ -50,13 +52,13 @@ public final class ModelUtils
for ( Iterator it = parentPlugins.iterator(); it.hasNext(); ) for ( Iterator it = parentPlugins.iterator(); it.hasNext(); )
{ {
Plugin parentPlugin = (Plugin) it.next(); Plugin parentPlugin = (Plugin) it.next();
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;
Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() ); Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() );
@ -88,24 +90,87 @@ public final class ModelUtils
} }
childContainer.setPlugins( new ArrayList( assembledPlugins.values() ) ); childContainer.setPlugins( new ArrayList( assembledPlugins.values() ) );
childContainer.flushPluginMap(); childContainer.flushPluginMap();
} }
} }
public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance ) public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance )
{ {
if( child == null || parent == null ) if ( child == null || parent == null )
{ {
// nothing to do. // nothing to do.
return; return;
} }
if ( child.getVersion() == null && parent.getVersion() != null ) if ( child.getVersion() == null && parent.getVersion() != null )
{ {
child.setVersion( parent.getVersion() ); 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(); List parentGoals = parent.getGoals();
// if the supplemental goals are non-existent, then nothing related to goals changes. // if the supplemental goals are non-existent, then nothing related to goals changes.
@ -141,8 +206,7 @@ public final class ModelUtils
assembledGoal = childGoal; assembledGoal = childGoal;
} }
else if ( handleAsInheritance && parentInherited == null )
if ( handleAsInheritance && parentInherited == null )
{ {
assembledGoal.unsetInheritanceApplied(); assembledGoal.unsetInheritanceApplied();
} }

View File

@ -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() );
}
}