@Test public void keepPluginDependencies() { MavenProject pom = MavenTestUtils.loadPom(getClass(), "keepPluginDependencies.xml"); MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false); assertThat(mavenPlugin).isNotNull(); Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact"); assertThat(plugin).isNotNull(); assertThat(plugin.getVersion()).isEqualTo("0.9"); assertThat(plugin.getDependencies().size()).isEqualTo(1); }
/** * Create plugin descriptors for the given plugins. * * @param plugins The plugins. * @param context The scanner context. * @return The plugin descriptors. */ private List<MavenPluginDescriptor> createMavenPluginDescriptors( List<Plugin> plugins, ScannerContext context) { Store store = context.getStore(); List<MavenPluginDescriptor> pluginDescriptors = new ArrayList<>(); for (Plugin plugin : plugins) { MavenPluginDescriptor mavenPluginDescriptor = store.create(MavenPluginDescriptor.class); MavenArtifactDescriptor artifactDescriptor = getArtifactResolver(context).resolve(new PluginCoordinates(plugin), context); mavenPluginDescriptor.setArtifact(artifactDescriptor); mavenPluginDescriptor.setInherited(plugin.isInherited()); addDependencies( mavenPluginDescriptor, plugin.getDependencies(), PluginDependsOnDescriptor.class, context); addPluginExecutions(mavenPluginDescriptor, plugin, store); addConfiguration(mavenPluginDescriptor, (Xpp3Dom) plugin.getConfiguration(), store); pluginDescriptors.add(mavenPluginDescriptor); } return pluginDescriptors; }
public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance) { if ((child == null) || (parent == null)) { // nothing to do. return; } if (parent.isExtensions()) { child.setExtensions(true); } if ((child.getVersion() == null) && (parent.getVersion() != null)) { child.setVersion(parent.getVersion()); } Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration(); Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration(); childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration, parentConfiguration); child.setConfiguration(childConfiguration); child.setDependencies(mergeDependencyList(child.getDependencies(), parent.getDependencies())); // from here to the end of the method is dealing with merging of the <executions/> section. String parentInherited = parent.getInherited(); boolean parentIsInherited = (parentInherited == null) || Boolean.valueOf(parentInherited).booleanValue(); List parentExecutions = parent.getExecutions(); if ((parentExecutions != null) && !parentExecutions.isEmpty()) { List mergedExecutions = new ArrayList(); Map assembledExecutions = new TreeMap(); Map childExecutions = child.getExecutionsAsMap(); for (Iterator it = parentExecutions.iterator(); it.hasNext(); ) { PluginExecution parentExecution = (PluginExecution) it.next(); String inherited = parentExecution.getInherited(); boolean parentExecInherited = parentIsInherited && ((inherited == null) || Boolean.valueOf(inherited).booleanValue()); if (!handleAsInheritance || parentExecInherited) { PluginExecution assembled = parentExecution; PluginExecution childExecution = (PluginExecution) childExecutions.get(parentExecution.getId()); if (childExecution != null) { mergePluginExecutionDefinitions(childExecution, parentExecution); assembled = childExecution; } else if (handleAsInheritance && (parentInherited == null)) { parentExecution.unsetInheritanceApplied(); } assembledExecutions.put(assembled.getId(), assembled); mergedExecutions.add(assembled); } } for (Iterator it = child.getExecutions().iterator(); it.hasNext(); ) { PluginExecution childExecution = (PluginExecution) it.next(); if (!assembledExecutions.containsKey(childExecution.getId())) { mergedExecutions.add(childExecution); } } child.setExecutions(mergedExecutions); child.flushExecutionMap(); } }