in maven-project/src/main/java/org/apache/maven/project/ModelUtils.java [465:543]
public static void mergePluginLists( PluginContainer child, PluginContainer parent,
boolean handleAsInheritance )
{
if ( ( child == null ) || ( parent == null ) )
{
// nothing to do.
return;
}
List<Plugin> parentPlugins = parent.getPlugins();
if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() )
{
parentPlugins = new ArrayList<Plugin>( parentPlugins );
// If we're processing this merge as an inheritance, we have to build up a list of
// plugins that were considered for inheritance.
if ( handleAsInheritance )
{
for ( Iterator<Plugin> it = parentPlugins.iterator(); it.hasNext(); )
{
Plugin plugin = it.next();
String inherited = plugin.getInherited();
if ( ( inherited != null ) && !Boolean.valueOf( inherited ).booleanValue() )
{
it.remove();
}
}
}
List<Plugin> assembledPlugins = new ArrayList<Plugin>();
Map<String, Plugin> childPlugins = child.getPluginsAsMap();
for ( Plugin parentPlugin : parentPlugins )
{
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() )
{
Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() );
if ( ( childPlugin != null ) && !assembledPlugins.contains( childPlugin ) )
{
Plugin assembledPlugin = childPlugin;
mergePluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
// fix for MNG-2221 (assembly cache was not being populated for later reference):
assembledPlugins.add( assembledPlugin );
}
// 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 ) )
{
parentPlugin.unsetInheritanceApplied();
}
}
// very important to use the parentPlugins List, rather than parentContainer.getPlugins()
// since this list is a local one, and may have been modified during processing.
List<Plugin> results = ModelUtils.orderAfterMerge( assembledPlugins, parentPlugins, child.getPlugins() );
child.setPlugins( results );
child.flushPluginMap();
}
}
}