mirror of https://github.com/apache/maven.git
OPEN - issue MNG-2591: Plugins are merged incorrectly
http://jira.codehaus.org/browse/MNG-2591 Added tests to verify the XML attribute that switches merge-mode from replace/merge to append for children...then, fixed append semantics to force the dominant children (those given by the child POM, in this case) to be appended to those of the recessive/parent-POM configuration. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@545315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7db88ddfaf
commit
8ec3ac8a97
|
@ -26,7 +26,11 @@ 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 org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -402,4 +406,59 @@ public class ModelUtilsTest
|
|||
Dependency dep2 = (Dependency) child.getDependencies().get( 0 );
|
||||
assertEquals( dep.getManagementKey(), dep2.getManagementKey() );
|
||||
}
|
||||
|
||||
public void testShouldOverwritePluginConfigurationSubItemsByDefault()
|
||||
throws XmlPullParserException, IOException
|
||||
{
|
||||
String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>";
|
||||
Xpp3Dom parentConfig = Xpp3DomBuilder.build( new StringReader( parentConfigStr ) );
|
||||
|
||||
Plugin parentPlugin = createPlugin( "group", "artifact", "1", null );
|
||||
parentPlugin.setConfiguration( parentConfig );
|
||||
|
||||
String childConfigStr = "<configuration><items><item>three</item></items></configuration>";
|
||||
Xpp3Dom childConfig = Xpp3DomBuilder.build( new StringReader( childConfigStr ) );
|
||||
|
||||
Plugin childPlugin = createPlugin( "group", "artifact", "1", null );
|
||||
childPlugin.setConfiguration( childConfig );
|
||||
|
||||
ModelUtils.mergePluginDefinitions( childPlugin, parentPlugin, true );
|
||||
|
||||
Xpp3Dom result = (Xpp3Dom) childPlugin.getConfiguration();
|
||||
Xpp3Dom items = result.getChild( "items" );
|
||||
|
||||
assertEquals( 1, items.getChildCount() );
|
||||
|
||||
Xpp3Dom item = items.getChild( 0 );
|
||||
assertEquals( "three", item.getValue() );
|
||||
}
|
||||
|
||||
public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet()
|
||||
throws XmlPullParserException, IOException
|
||||
{
|
||||
String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>";
|
||||
Xpp3Dom parentConfig = Xpp3DomBuilder.build( new StringReader( parentConfigStr ) );
|
||||
|
||||
Plugin parentPlugin = createPlugin( "group", "artifact", "1", null );
|
||||
parentPlugin.setConfiguration( parentConfig );
|
||||
|
||||
String childConfigStr = "<configuration><items combine.children=\"append\"><item>three</item></items></configuration>";
|
||||
Xpp3Dom childConfig = Xpp3DomBuilder.build( new StringReader( childConfigStr ) );
|
||||
|
||||
Plugin childPlugin = createPlugin( "group", "artifact", "1", null );
|
||||
childPlugin.setConfiguration( childConfig );
|
||||
|
||||
ModelUtils.mergePluginDefinitions( childPlugin, parentPlugin, true );
|
||||
|
||||
Xpp3Dom result = (Xpp3Dom) childPlugin.getConfiguration();
|
||||
Xpp3Dom items = result.getChild( "items" );
|
||||
|
||||
assertEquals( 3, items.getChildCount() );
|
||||
|
||||
Xpp3Dom[] item = items.getChildren();
|
||||
|
||||
assertEquals( "one", item[0].getValue() );
|
||||
assertEquals( "two", item[1].getValue() );
|
||||
assertEquals( "three", item[2].getValue() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue