diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
index 66527df427..7e6de40f6a 100644
--- a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
@@ -82,6 +82,11 @@ public final class ModelUtils
String parentInherited = parentPlugin.getInherited();
+ // only merge plugin definition from the parent if at least one
+ // of these is true:
+ // 1. we're not processing the plugins in an inheritance-based merge
+ // 2. the parent's flag is not set
+ // 3. the parent's flag is set to true
if ( !handleAsInheritance || parentInherited == null ||
Boolean.valueOf( parentInherited ).booleanValue() )
{
@@ -97,18 +102,21 @@ public final class ModelUtils
mergePluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
}
+ // if we're processing this as an inheritance-based merge, and
+ // the parent's flag is not set, then we need to
+ // clear the inherited flag in the merge result.
if ( handleAsInheritance && parentInherited == null )
{
assembledPlugin.unsetInheritanceApplied();
}
mergedPlugins.add(assembledPlugin);
+
+ // fix for MNG-2221 (assembly cache was not being populated for later reference):
+ assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin );
}
}
- // FIXME: not sure what's intended here, but this entire
- // loop can be replaced by 'mergedPlugins.addAll( childPlugins.values() );
- // since assembledPlugins is never updated and remains empty.
for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); )
{
Plugin childPlugin = (Plugin) it.next();
diff --git a/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java b/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java
index 60a6a98e92..eb4525196e 100644
--- a/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java
@@ -2,12 +2,14 @@ package org.apache.maven.project;
import junit.framework.TestCase;
+import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Dependency;
import java.util.Collections;
+import java.util.List;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@@ -77,6 +79,80 @@ public class ModelUtilsTest
assertEquals( 2, child.getExecutions().size() );
}
+ public void testShouldMergeOnePluginWithInheritExecutionWithoutDuplicatingPluginInList()
+ {
+ Plugin parent = new Plugin();
+ parent.setArtifactId( "testArtifact" );
+ parent.setGroupId( "testGroup" );
+ parent.setVersion( "1.0" );
+
+ PluginExecution parentExecution = new PluginExecution();
+ parentExecution.setId( "testExecution" );
+
+ parent.addExecution( parentExecution );
+
+ Build parentContainer = new Build();
+ parentContainer.addPlugin( parent );
+
+ Plugin child = new Plugin();
+ child.setArtifactId( "testArtifact" );
+ child.setGroupId( "testGroup" );
+ child.setVersion( "1.0" );
+
+ Build childContainer = new Build();
+ childContainer.addPlugin( child );
+
+ ModelUtils.mergePluginLists( childContainer, parentContainer, true );
+
+ List plugins = childContainer.getPlugins();
+
+ assertEquals( 1, plugins.size() );
+
+ Plugin plugin = (Plugin) plugins.get( 0 );
+
+ assertEquals( 1, plugin.getExecutions().size() );
+ }
+
+ public void testShouldMergePluginWithDifferentExecutionFromParentWithoutDuplicatingPluginInList()
+ {
+ Plugin parent = new Plugin();
+ parent.setArtifactId( "testArtifact" );
+ parent.setGroupId( "testGroup" );
+ parent.setVersion( "1.0" );
+
+ PluginExecution parentExecution = new PluginExecution();
+ parentExecution.setId( "testExecution" );
+
+ parent.addExecution( parentExecution );
+
+ Build parentContainer = new Build();
+ parentContainer.addPlugin( parent );
+
+ Plugin child = new Plugin();
+ child.setArtifactId( "testArtifact" );
+ child.setGroupId( "testGroup" );
+ child.setVersion( "1.0" );
+
+ PluginExecution childExecution = new PluginExecution();
+ childExecution.setId( "testExecution2" );
+
+ child.addExecution( childExecution );
+
+
+ Build childContainer = new Build();
+ childContainer.addPlugin( child );
+
+ ModelUtils.mergePluginLists( childContainer, parentContainer, true );
+
+ List plugins = childContainer.getPlugins();
+
+ assertEquals( 1, plugins.size() );
+
+ Plugin plugin = (Plugin) plugins.get( 0 );
+
+ assertEquals( 2, plugin.getExecutions().size() );
+ }
+
public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse()
{
Plugin parent = new Plugin();