PR: MNG-1499

Submitted By: David Jackman
Reviewed By: John Casey

Applied. Thanks, David.

This patch makes the ordering of plugins deterministic after they are merged via inheritance or other mechanism.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@345312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-11-17 19:30:44 +00:00
parent 5d95af5f30
commit 9584088c44
2 changed files with 118 additions and 10 deletions

View File

@ -65,6 +65,8 @@ public final class ModelUtils
return; return;
} }
List mergedPlugins = new ArrayList();
List parentPlugins = parentContainer.getPlugins(); List parentPlugins = parentContainer.getPlugins();
if ( parentPlugins != null && !parentPlugins.isEmpty() ) if ( parentPlugins != null && !parentPlugins.isEmpty() )
@ -99,7 +101,7 @@ public final class ModelUtils
assembledPlugin.unsetInheritanceApplied(); assembledPlugin.unsetInheritanceApplied();
} }
assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin ); mergedPlugins.add(assembledPlugin);
} }
} }
@ -109,11 +111,11 @@ public final class ModelUtils
if ( !assembledPlugins.containsKey( childPlugin.getKey() ) ) if ( !assembledPlugins.containsKey( childPlugin.getKey() ) )
{ {
assembledPlugins.put( childPlugin.getKey(), childPlugin ); mergedPlugins.add(childPlugin);
} }
} }
childContainer.setPlugins( new ArrayList( assembledPlugins.values() ) ); childContainer.setPlugins(mergedPlugins);
childContainer.flushPluginMap(); childContainer.flushPluginMap();
} }
@ -215,6 +217,8 @@ public final class ModelUtils
if ( parentExecutions != null && !parentExecutions.isEmpty() ) if ( parentExecutions != null && !parentExecutions.isEmpty() )
{ {
List mergedExecutions = new ArrayList();
Map assembledExecutions = new TreeMap(); Map assembledExecutions = new TreeMap();
Map childExecutions = child.getExecutionsAsMap(); Map childExecutions = child.getExecutionsAsMap();
@ -241,22 +245,21 @@ public final class ModelUtils
} }
assembledExecutions.put( assembled.getId(), assembled ); assembledExecutions.put( assembled.getId(), assembled );
mergedExecutions.add(assembled);
} }
} }
for ( Iterator it = childExecutions.entrySet().iterator(); it.hasNext(); ) for ( Iterator it = child.getExecutions().iterator(); it.hasNext(); )
{ {
Map.Entry entry = (Map.Entry) it.next(); PluginExecution childExecution = (PluginExecution)it.next();
String id = (String) entry.getKey(); if ( !assembledExecutions.containsKey( childExecution.getId() ) )
if ( !assembledExecutions.containsKey( id ) )
{ {
assembledExecutions.put( id, entry.getValue() ); mergedExecutions.add(childExecution);
} }
} }
child.setExecutions( new ArrayList( assembledExecutions.values() ) ); child.setExecutions(mergedExecutions);
child.flushExecutionMap(); child.flushExecutionMap();
} }

View File

@ -3,6 +3,7 @@ package org.apache.maven.project;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
/* /*
@ -96,4 +97,108 @@ public class ModelUtilsTest
assertEquals( 0, child.getExecutions().size() ); assertEquals( 0, child.getExecutions().size() );
} }
/**
* Verifies MNG-1499: The order of the merged list should be the plugins specified by the parent followed by the
* child list.
*/
public void testShouldKeepOriginalPluginOrdering()
{
Plugin parentPlugin1 = new Plugin();
parentPlugin1.setArtifactId( "testArtifact" );
parentPlugin1.setGroupId( "zzz" ); // This will put this plugin last in the sorted map
parentPlugin1.setVersion( "1.0" );
PluginExecution parentExecution1 = new PluginExecution();
parentExecution1.setId( "testExecution" );
parentPlugin1.addExecution( parentExecution1 );
Plugin parentPlugin2 = new Plugin();
parentPlugin2.setArtifactId( "testArtifact" );
parentPlugin2.setGroupId( "yyy" );
parentPlugin2.setVersion( "1.0" );
PluginExecution parentExecution2 = new PluginExecution();
parentExecution2.setId( "testExecution" );
parentPlugin2.addExecution( parentExecution2 );
PluginContainer parentContainer = new PluginContainer();
parentContainer.addPlugin(parentPlugin1);
parentContainer.addPlugin(parentPlugin2);
Plugin childPlugin1 = new Plugin();
childPlugin1.setArtifactId( "testArtifact" );
childPlugin1.setGroupId( "bbb" );
childPlugin1.setVersion( "1.0" );
PluginExecution childExecution1 = new PluginExecution();
childExecution1.setId( "testExecution" );
childPlugin1.addExecution( childExecution1 );
Plugin childPlugin2 = new Plugin();
childPlugin2.setArtifactId( "testArtifact" );
childPlugin2.setGroupId( "aaa" );
childPlugin2.setVersion( "1.0" );
PluginExecution childExecution2 = new PluginExecution();
childExecution2.setId( "testExecution" );
childPlugin2.addExecution( childExecution2 );
PluginContainer childContainer = new PluginContainer();
childContainer.addPlugin(childPlugin1);
childContainer.addPlugin(childPlugin2);
ModelUtils.mergePluginLists(childContainer, parentContainer, true);
assertEquals( 4, childContainer.getPlugins().size() );
assertSame(parentPlugin1, childContainer.getPlugins().get(0));
assertSame(parentPlugin2, childContainer.getPlugins().get(1));
assertSame(childPlugin1, childContainer.getPlugins().get(2));
assertSame(childPlugin2, childContainer.getPlugins().get(3));
}
/**
* Verifies MNG-1499: The ordering of plugin executions should also be in the specified order.
*/
public void testShouldKeepOriginalPluginExecutionOrdering()
{
Plugin parent = new Plugin();
parent.setArtifactId( "testArtifact" );
parent.setGroupId( "testGroup" );
parent.setVersion( "1.0" );
PluginExecution parentExecution1 = new PluginExecution();
parentExecution1.setId( "zzz" ); // Will show up last in the sorted map
PluginExecution parentExecution2 = new PluginExecution();
parentExecution2.setId( "yyy" ); // Will show up last in the sorted map
parent.addExecution( parentExecution1 );
parent.addExecution( parentExecution2 );
Plugin child = new Plugin();
child.setArtifactId( "testArtifact" );
child.setGroupId( "testGroup" );
child.setVersion( "1.0" );
PluginExecution childExecution1 = new PluginExecution();
childExecution1.setId( "bbb" );
PluginExecution childExecution2 = new PluginExecution();
childExecution2.setId( "aaa" );
child.addExecution( childExecution1 );
child.addExecution( childExecution2 );
ModelUtils.mergePluginDefinitions( child, parent, false );
assertEquals( 4, child.getExecutions().size() );
assertSame(parentExecution1, child.getExecutions().get(0));
assertSame(parentExecution2, child.getExecutions().get(1));
assertSame(childExecution1, child.getExecutions().get(2));
assertSame(childExecution2, child.getExecutions().get(3));
}
} }