in src/main/java/org/apache/maven/plugin/resources/remote/ModelUtils.java [51:119]
public static void mergePluginLists(
PluginContainer childContainer, PluginContainer parentContainer, boolean handleAsInheritance) {
if ((childContainer == null) || (parentContainer == null)) {
// nothing to do.
return;
}
List<Plugin> parentPlugins = parentContainer.getPlugins();
if ((parentPlugins != null) && !parentPlugins.isEmpty()) {
parentPlugins = new ArrayList<>(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.parseBoolean(inherited)) {
it.remove();
}
}
}
List<Plugin> assembledPlugins = new ArrayList<>();
Map<String, Plugin> childPlugins = childContainer.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.parseBoolean(parentInherited)) {
Plugin childPlugin = 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, childContainer.getPlugins());
childContainer.setPlugins(results);
childContainer.flushPluginMap();
}
}
}