return false; if (expected.hasChildren()) { for (final PluginElement pluginElem : expected.getChildren()) { if (pluginElem instanceof ConfigurationElement) { final ConfigurationElement elem = ConfigurationElement.class.cast(pluginElem); ConfigurationElement child; int i; for (i = 0; i < given.getChildren().size(); i++) { child = ConfigurationElement.class.cast(given.getChildren().get(i)); if (child.getName().equals(elem.getName()) && isMatchingElement(child, elem)) { return true; if (i == given.getChildren().size()) return false; return expected.getText().equals(given.getText());
private void convertWarSrcPlaceholder(final String warSrcDirectory) { final List<PluginElement> includes = configurations.iterator().next().getChildByName("includes").getChildren(); for (final PluginElement include : includes) { final ConfigurationElementBuilder includeAsBuilder = (ConfigurationElementBuilder) include; includeAsBuilder.setText(includeAsBuilder.getText().replace(WAR_SRC_PLACEHOLDER, warSrcDirectory)); } } }
if (!prev.hasChildren()) { return configElem; final ConfigurationElementBuilder retVal = ConfigurationElementBuilder.create(); for (final PluginElement child : prev.getChildren()) { if (!(child instanceof ConfigurationElement)) { if (!configElem.hasChildByName(oldChild.getName(), true)) retVal.addChild(oldChild); for (final PluginElement child : configElem.getChildren()) { if (!(child instanceof ConfigurationElement)) { throw new IllegalArgumentException("Cannot merge PluginElement of type " + child.getClass().getName()); if (prev.hasChildByName(newChild.getName(), true)) { retVal.addChild(merge(prev.getChildByName(newChild.getName(), true), newChild));
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()); } }
builder.mainClass(mainClassElem.getText()); propertiesElem.getChildren().stream() .filter(ConfigurationElement.class::isInstance) .map(ConfigurationElement.class::cast) .forEach(elem -> properties.put(elem.getName(), elem.getText())); builder.properties(properties);
@Override public ConfigurationElement getConfigurationElement(final String configElement) { for (ConfigurationElement configurationElement : configurationElements) { if (configurationElement.getName().equals(configElement)) { return configurationElement; } } return null; }
private boolean processorConfigured(MetaModelProvider provider) { CoordinateBuilder dependency = createProcessorCoordinate().setVersion(null); MavenPluginFacet pluginFacet = getFaceted().getFacet(MavenPluginFacet.class); if (pluginFacet.hasPlugin(dependency)) { MavenPlugin plugin = pluginFacet.getPlugin(dependency); if (plugin.listExecutions().size() > 0) { Configuration config = plugin.listExecutions().get(0).getConfig(); if (config.hasConfigurationElement("processors")) { ConfigurationElement element = config.getConfigurationElement("processors").getChildByName("processor"); return element.getText().equals(provider.getProcessor()); } } } return false; }
public static String getWarSourceDirectory(final Project project) { final MavenPluginFacet pluginFacet = project.getFacet(MavenPluginFacet.class); final CoordinateBuilder warPluginCoordinate = CoordinateBuilder.create().setGroupId(War.getGroupId()) .setArtifactId(War.getArtifactId()); if (pluginFacet.hasPlugin(warPluginCoordinate)) { final Configuration warConfig = pluginFacet.getPlugin(warPluginCoordinate).getConfig(); if (warConfig.hasConfigurationElement(WarSourceDirectory.getValueName())) { return warConfig.getConfigurationElement(WarSourceDirectory.getValueName()).getText(); } } return WarSourceDirectory.getDefaultValue(); }
public static ConfigurationElement findChildByName(ConfigurationElement element, String name) { try { return element.getChildByName(name); } catch (Exception e) { return null; } }
@Override protected void init() { final Execution execution = executions.iterator().next(); final ConfigurationElement artifactItems = execution.getConfig().getConfigurationElement("artifactItems"); final ConfigurationElementBuilder artifactItem = (ConfigurationElementBuilder) artifactItems.getChildren().get(0); final VersionFacet versionFacet = getProject().getFacet(VersionFacet.class); artifactItem.addChild(ConfigurationElementBuilder.create().setName("version") .setText(versionFacet.resolveVersion(WildflyDist))); }
@Override public boolean hasConfigurationElement(final String configElement) { for (ConfigurationElement configurationElement : configurationElements) { if (configurationElement.getName().equals(configElement)) { return true; } } return false; }
@Override public DirectoryResource getWebRootDirectory() { Project project = getFaceted(); MavenPluginFacet mavenPluginFacet = project.getFacet(MavenPluginFacet.class); final String webappFolderName; Coordinate mvnWarPluginDep = CoordinateBuilder.create("org.apache.maven.plugins:maven-war-plugin"); if (mavenPluginFacet.hasPlugin(mvnWarPluginDep)) { MavenPlugin warPlugin = mavenPluginFacet.getPlugin(mvnWarPluginDep); Configuration config = warPlugin.getConfig(); if (config.hasConfigurationElement("warSourceDirectory")) { webappFolderName = config.getConfigurationElement("warSourceDirectory").getText(); } else { webappFolderName = "src" + File.separator + "main" + File.separator + "webapp"; } } else { webappFolderName = "src" + File.separator + "main" + File.separator + "webapp"; } DirectoryResource projectRoot = project.getRoot().reify(DirectoryResource.class); return projectRoot.getChildDirectory(webappFolderName); }
private void addGwtModuleInclude(final String moduleName) { ((ConfigurationElementBuilder) configurations.iterator().next().getChildByName("includes")) .addChild(ConfigurationElementBuilder.create().setName("include") .setText(WAR_SRC_PLACEHOLDER + "/" + moduleName + "/")); }
private ConfigurationElement getConfigElementRecursiveByContent(ConfigurationElement parent, String filter, FilterType filterType, boolean directChildsOnly) List<PluginElement> children = parent.getChildren(); for (PluginElement child : children) if (filterType.equals(FilterType.CONTENT) && filter.equals(element.getText())) else if (filterType.equals(FilterType.NAME) && filter.equals(element.getName())) if (!directChildsOnly && element.hasChildren()) + parent.getName());
@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)); } }
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());