{
MavenPluginFacet plugins = project.getFacet(MavenPluginFacet.class);
DependencyFacet deps = project.getFacet(DependencyFacet.class);
Coordinate pluginCoordinates = CoordinateBuilder.create().setGroupId(plugin.getCoordinate().getGroupId())
.setArtifactId(plugin.getCoordinate().getArtifactId());
MavenPlugin managedPlugin = null;
if (plugins.hasManagedPlugin(pluginCoordinates))
{
managedPlugin = plugins.getManagedPlugin(pluginCoordinates);
}
MavenPlugin existing = null;
// existing represents the plugin(management) as it exists currently throughout the entire hierarchy
if (managed && plugins.hasEffectiveManagedPlugin(pluginCoordinates))
{
existing = plugins.getEffectiveManagedPlugin(pluginCoordinates);
}
else if (plugins.hasEffectivePlugin(pluginCoordinates))
{
existing = plugins.getEffectivePlugin(pluginCoordinates);
}
MavenPlugin filteredPlugin = plugin;
// The filtered plugin preserve the hierarchy, by preventing installing properties already defined with the same
// values
if (existing != null && preserveHierarchyPrecedence)
{
filteredPlugin = diff(plugin, existing);
}
// Preserve direct plugin-management inheritance
if (!managed && managedPlugin != null)
{
// The plugin section does not exists but a plugin management section in the direct pom does
filteredPlugin = diff(filteredPlugin, managedPlugin);
}
MavenPlugin mergedPlugin = filteredPlugin;
// merged plugin is a merge with the direct plugin(management)
if (managed && managedPlugin != null)
{
mergedPlugin = plugins.merge(mergedPlugin, managedPlugin);
}
else if (!managed && plugins.hasPlugin(pluginCoordinates))
{
mergedPlugin = plugins.merge(mergedPlugin, plugins.getPlugin(pluginCoordinates));
}
// Resolve version
String versionToInstall = plugin.getCoordinate().getVersion();
if (mergedPlugin.getCoordinate().getVersion() == null)
{
// null version means no version was specified or already defined in the hierarchy
if (versionToInstall == null)
{
versionToInstall = promptVersion(deps, pluginCoordinates, null).getVersion();