mirror of https://github.com/apache/maven.git
OPEN - issue MNG-2784: Multiple executions of the same plugin at the same life cycle phase in a multi-module profile mixed up
http://jira.codehaus.org/browse/MNG-2784 NOT applying this patch, as there is a much simpler solution. The processing is currently in the correct order, so all we need to do is make sure the Map.values() method retains this order. Therefore, I changed the Map implementation for plugin executions to LinkedHashMap. I've also added a test for this issue... git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@543599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
09553c6ff3
commit
5401fb4c64
|
@ -41,10 +41,10 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject profile data into a Model, using the profile as the dominant data source, and
|
* Inject profile data into a Model, using the profile as the dominant data source, and
|
||||||
|
@ -153,7 +153,7 @@ public class DefaultProfileInjector
|
||||||
*/
|
*/
|
||||||
protected void injectPlugins( PluginContainer profileContainer, PluginContainer modelContainer )
|
protected void injectPlugins( PluginContainer profileContainer, PluginContainer modelContainer )
|
||||||
{
|
{
|
||||||
if ( profileContainer == null || modelContainer == null )
|
if ( ( profileContainer == null ) || ( modelContainer == null ) )
|
||||||
{
|
{
|
||||||
// nothing to do...
|
// nothing to do...
|
||||||
return;
|
return;
|
||||||
|
@ -177,7 +177,7 @@ public class DefaultProfileInjector
|
||||||
|
|
||||||
Plugin profilePlugin = (Plugin) profilePlugins.get( modelPlugin.getKey() );
|
Plugin profilePlugin = (Plugin) profilePlugins.get( modelPlugin.getKey() );
|
||||||
|
|
||||||
if ( profilePlugin != null && !mergedPlugins.contains( profilePlugin ) )
|
if ( ( profilePlugin != null ) && !mergedPlugins.contains( profilePlugin ) )
|
||||||
{
|
{
|
||||||
Plugin mergedPlugin = modelPlugin;
|
Plugin mergedPlugin = modelPlugin;
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public class DefaultProfileInjector
|
||||||
|
|
||||||
private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
|
private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
|
||||||
{
|
{
|
||||||
if ( profilePlugin == null || modelPlugin == null )
|
if ( ( profilePlugin == null ) || ( modelPlugin == null ) )
|
||||||
{
|
{
|
||||||
// nothing to do.
|
// nothing to do.
|
||||||
return;
|
return;
|
||||||
|
@ -219,13 +219,13 @@ public class DefaultProfileInjector
|
||||||
// from here to the end of the method is dealing with merging of the <executions/> section.
|
// from here to the end of the method is dealing with merging of the <executions/> section.
|
||||||
List modelExecutions = modelPlugin.getExecutions();
|
List modelExecutions = modelPlugin.getExecutions();
|
||||||
|
|
||||||
if ( modelExecutions == null || modelExecutions.isEmpty() )
|
if ( ( modelExecutions == null ) || modelExecutions.isEmpty() )
|
||||||
{
|
{
|
||||||
modelPlugin.setExecutions( profilePlugin.getExecutions() );
|
modelPlugin.setExecutions( profilePlugin.getExecutions() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Map executions = new TreeMap();
|
Map executions = new LinkedHashMap();
|
||||||
|
|
||||||
Map profileExecutions = profilePlugin.getExecutionsAsMap();
|
Map profileExecutions = profilePlugin.getExecutionsAsMap();
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ public class DefaultProfileInjector
|
||||||
|
|
||||||
List goals = new ArrayList();
|
List goals = new ArrayList();
|
||||||
|
|
||||||
if ( modelGoals != null && !modelGoals.isEmpty() )
|
if ( ( modelGoals != null ) && !modelGoals.isEmpty() )
|
||||||
{
|
{
|
||||||
goals.addAll( modelGoals );
|
goals.addAll( modelGoals );
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ public class DefaultProfileInjector
|
||||||
|
|
||||||
List modelModules = model.getModules();
|
List modelModules = model.getModules();
|
||||||
|
|
||||||
if ( modelModules != null && !modelModules.isEmpty() )
|
if ( ( modelModules != null ) && !modelModules.isEmpty() )
|
||||||
{
|
{
|
||||||
modules.addAll( modelModules );
|
modules.addAll( modelModules );
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,4 +299,75 @@ public class DefaultProfileInjectorTest
|
||||||
assertEquals( "module1", rModules.get( 0 ) );
|
assertEquals( "module1", rModules.get( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: The execution-id's are important, because they are NOT in
|
||||||
|
// alphabetical order. The trunk version of Maven currently injects
|
||||||
|
// profiles into a TreeMap, then calls map.values(), which puts the
|
||||||
|
// executions in alphabetical order...the WRONG order.
|
||||||
|
public void testShouldPreserveOrderingOfProfileInjectedPluginExecutions()
|
||||||
|
{
|
||||||
|
Plugin profilePlugin = new Plugin();
|
||||||
|
profilePlugin.setGroupId( "group" );
|
||||||
|
profilePlugin.setArtifactId( "artifact" );
|
||||||
|
profilePlugin.setVersion( "version" );
|
||||||
|
|
||||||
|
PluginExecution exec1 = new PluginExecution();
|
||||||
|
exec1.setId( "z" );
|
||||||
|
profilePlugin.addExecution( exec1 );
|
||||||
|
|
||||||
|
PluginExecution exec2 = new PluginExecution();
|
||||||
|
exec2.setId( "y" );
|
||||||
|
profilePlugin.addExecution( exec2 );
|
||||||
|
|
||||||
|
BuildBase buildBase = new BuildBase();
|
||||||
|
buildBase.addPlugin( profilePlugin );
|
||||||
|
|
||||||
|
Profile profile = new Profile();
|
||||||
|
profile.setBuild( buildBase );
|
||||||
|
|
||||||
|
Plugin modelPlugin = new Plugin();
|
||||||
|
modelPlugin.setGroupId( "group" );
|
||||||
|
modelPlugin.setArtifactId( "artifact" );
|
||||||
|
modelPlugin.setVersion( "version" );
|
||||||
|
|
||||||
|
PluginExecution exec3 = new PluginExecution();
|
||||||
|
exec3.setId( "w" );
|
||||||
|
modelPlugin.addExecution( exec3 );
|
||||||
|
|
||||||
|
PluginExecution exec4 = new PluginExecution();
|
||||||
|
exec4.setId( "x" );
|
||||||
|
modelPlugin.addExecution( exec4 );
|
||||||
|
|
||||||
|
Build build = new Build();
|
||||||
|
build.addPlugin( modelPlugin );
|
||||||
|
|
||||||
|
Model model = new Model();
|
||||||
|
model.setBuild( build );
|
||||||
|
|
||||||
|
new DefaultProfileInjector().inject( profile, model );
|
||||||
|
|
||||||
|
List plugins = model.getBuild().getPlugins();
|
||||||
|
assertNotNull( plugins );
|
||||||
|
assertEquals( 1, plugins.size() );
|
||||||
|
|
||||||
|
Plugin plugin = (Plugin) plugins.get( 0 );
|
||||||
|
|
||||||
|
List executions = plugin.getExecutions();
|
||||||
|
assertNotNull( executions );
|
||||||
|
assertEquals( 4, executions.size() );
|
||||||
|
|
||||||
|
Iterator it = executions.iterator();
|
||||||
|
|
||||||
|
PluginExecution e = (PluginExecution) it.next();
|
||||||
|
assertEquals( "w", e.getId() );
|
||||||
|
|
||||||
|
e = (PluginExecution) it.next();
|
||||||
|
assertEquals( "x", e.getId() );
|
||||||
|
|
||||||
|
e = (PluginExecution) it.next();
|
||||||
|
assertEquals( "z", e.getId() );
|
||||||
|
|
||||||
|
e = (PluginExecution) it.next();
|
||||||
|
assertEquals( "y", e.getId() );
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue