@Override public ConfigurationElement getConfigurationElement(final String configElement) { for (ConfigurationElement configurationElement : configurationElements) { if (configurationElement.getName().equals(configElement)) { return configurationElement; } } return null; }
@Override public boolean hasConfigurationElement(final String configElement) { for (ConfigurationElement configurationElement : configurationElements) { if (configurationElement.getName().equals(configElement)) { return true; } } return false; }
@Override public void removeConfigurationElement(final String elementName) { for (ConfigurationElement configurationElement : configurationElements) { if (configurationElement.getName().equals(elementName)) { configurationElements.remove(configurationElement); break; } } }
@Override protected void init() { for (final ConfigurationElement elem : configurations) { if (elem.getName().equals("hostedWebapp")) { ConfigurationElementBuilder.class.cast(elem).setText(WarPluginFacet.getWarSourceDirectory(getProject())); break; } } } }
/** * Check that a {@link Configuration} is consistent with a collection of * {@link ConfigurationElement ConfigurationElements}. * * A configuration is consistent with a collection if for any element in the * collection, {@code elem}, there exists an element in the configuration, * {@code other}, such that * {@link AbstractPluginFacet#isMatchingElement(ConfigurationElement, ConfigurationElement) * isMatchingElement}{@code (elem, matching)} is {@code true}. * * @param config * A Maven plugin configuration. * @param elements * A set of configuration elements for a Maven plugin. * @return True iff the given configuration is consistent with the given * collection of configuration elements. */ protected static boolean isMatchingConfiguration(final Configuration config, final Collection<ConfigurationElement> elements) { for (final ConfigurationElement elem : elements) { if (!config.hasConfigurationElement(elem.getName()) || !isMatchingElement(config.getConfigurationElement(elem.getName()), elem)) return false; } return true; }
/** * Merge a {@link ConfigurationElement} into a {@link Configuration}. If there * is no element in the given configuration with a name matching the given * element, the element is simply added. Otherwise, the two elements will be * recursively merged, with any conflicting values in the configuration being * overwritten. * * @param config * A Maven plugin configuration. * @param configElem * A Maven plugin configuration element. */ protected void mergeConfigurationElement(final Configuration config, final ConfigurationElement configElem) { if (!config.hasConfigurationElement(configElem.getName())) { config.addConfigurationElement(configElem); } else { final ConfigurationElement prev = config.getConfigurationElement(configElem.getName()); config.removeConfigurationElement(configElem.getName()); config.addConfigurationElement(merge(prev, configElem)); } }
.filter(ConfigurationElement.class::isInstance) .map(ConfigurationElement.class::cast) .forEach(elem -> properties.put(elem.getName(), elem.getText())); builder.properties(properties);
public static ConfigurationElementBuilder createFromExisting(ConfigurationElement element) { if (element instanceof ConfigurationElementBuilder) { ConfigurationElementBuilder elementBuilder = (ConfigurationElementBuilder) element; ConfigurationElementBuilder builder = new ConfigurationElementBuilder(elementBuilder); builder.configurationElement.setName(element.getName()); builder.configurationElement.setText(element.getText()); builder.configurationElement.setChildren(element.getChildren()); builder.configurationElement.getMutableAttributes().putAll(element.getAttributes()); return builder; } else if (element instanceof ConfigurationElementImpl) { ConfigurationElementBuilder builder = new ConfigurationElementBuilder(); builder.configurationElement = (ConfigurationElementImpl) element; return builder; } else { throw new IllegalArgumentException("Unsupported type: " + element.getClass()); } }
cfgElmtsRefMap.put(e.getName(), e.toString()); if (cfgElmtsRefMap.containsKey(e.getName())) if (Strings.compare(cfgElmtsRefMap.get(e.getName()), e.toString())) mergedConfiguration.removeConfigurationElement(e.getName()); cfgExecElmtsRefMap.put(e.getName(), e.toString()); if (cfgExecElmtsRefMap.containsKey(e.getName())) if (Strings.compare(cfgExecElmtsRefMap.get(e.getName()), e.toString())) pluginExecutionMergedCfg.removeConfigurationElement(e.getName());