mirror of https://github.com/apache/maven.git
[MNG-2221] Fixing caching of merged plugins to prevent them from appearing/executing twice in the resulting child POM. See two new unit tests in ModelUtilsTest for proof.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@421309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
864fbd29e2
commit
cc859f5cfb
|
@ -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 <inherited/> flag is not set
|
||||
// 3. the parent's <inherited/> 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 <inherited/> 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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue