@Override public Plugin map(Element element) { return new Plugin(element); } }
/** * Sets configuration property value as {@literal <name>value</name>}. * * <p>If element doesn't have configuration element it will be created as well. <b>Note: it should * not be used with nested configuration elements</b> * * @param name property name to set * @param value property value to set * @return this plugin instance * @throws NullPointerException when {@code name} or {@code value} is {@code null} */ public Plugin setConfigProperty(String name, String value) { requireNonNull(name, "Configuration property name should not be null"); requireNonNull(value, "Configuration property value should not be null"); if (!isNew()) { addConfigPropertyToXML(name, value); } configuration().put(name, value); return this; }
@Override public String toString() { return getId(); }
/** * Sets new configuration with new configuration * * @param configuration new plugin configuration, if new configuration is {@code null} or * <i>empty</i> and plugin element related with xml element then <i>configuration</i> element * will be removed from xml as well as from plugin model * @return this plugin instance */ public Plugin setConfiguration(Map<String, String> configuration) { if (configuration == null || configuration.isEmpty()) { removeConfiguration(); } else { setConfiguration0(configuration); } return this; }
/** * Removes configuration property. If configuration has nested element with removal {@code name} * it will be removed with all related children. * * @param name configuration property which indicated element that should be removed * @return this plugin instance * @throws NullPointerException when {@code name} is null */ public Plugin removeConfigProperty(String name) { requireNonNull(name, "Configuration property name should ne null"); if (configuration().remove(name) != null && !isNew()) { removeConfigPropertyFromXML(name); } return this; }
private void removeConfiguration() { if (!isNew()) { pluginElement.removeChild("properties"); } configuration = null; }
private NewElement newPluginsElement(Collection<? extends Plugin> plugins) { final NewElement xmlPlugins = createElement("plugins"); for (Plugin plugin : plugins) { xmlPlugins.appendChild(plugin.asXMLElement()); } return xmlPlugins; }
private void addConfigPropertyToXML(String name, String value) { if (configuration().containsKey(name)) { pluginElement.getSingleChild("configuration").getSingleChild(name).setText(value); } else if (configuration.isEmpty()) { pluginElement.appendChild(createElement("configuration", createElement(name, value))); } else { pluginElement.getSingleChild("configuration").appendChild(createElement(name, value)); } }
Plugin(Element element) { pluginElement = element; if (element.hasSingleChild("artifactId")) { artifactId = element.getChildText("artifactId"); } if (element.hasSingleChild("groupId")) { groupId = element.getChildText("groupId"); } if (element.hasSingleChild("version")) { groupId = element.getChildText("version"); } if (element.hasSingleChild("configuration")) { configuration = fetchConfiguration(element.getSingleChild("configuration")); } }
private void setConfiguration0(Map<String, String> configuration) { this.configuration = new HashMap<>(configuration); if (isNew()) return; if (pluginElement.hasSingleChild("configuration")) { final Element confElement = pluginElement.getSingleChild("configuration"); // remove all configuration properties from element for (Element property : confElement.getChildren()) { property.remove(); } // append each new property to "configuration" element for (Map.Entry<String, String> property : configuration.entrySet()) { confElement.appendChild(createElement(property.getKey(), property.getValue())); } } else { final NewElement newConfiguration = createElement("configuration"); for (Map.Entry<String, String> entry : configuration.entrySet()) { newConfiguration.appendChild(createElement(entry.getKey(), entry.getValue())); } // insert new configuration to xml pluginElement.appendChild(newConfiguration); } }
private void setPlugins0(Collection<? extends Plugin> plugins) { this.plugins = new ArrayList<>(plugins); if (isNew()) return; // if plugins element exists we should replace it children // with new set of plugins, otherwise create element for it if (buildElement.hasSingleChild("plugins")) { // remove "plugins" element children final Element pluginsElement = buildElement.getSingleChild("plugins"); for (Element plugin : pluginsElement.getChildren()) { plugin.remove(); } // append each new plugin to "plugins" element for (Plugin plugin : plugins) { pluginsElement.appendChild(plugin.asXMLElement()); } } else { buildElement.appendChild(newPluginsElement(plugins)); } }
/** * Sets plugin group identifier * * @param groupId new group identifier, if new group id is {@code null} and current plugin element * related with xml element then <i>groupId</i> element will be removed from xml as well as * from plugin model * @return this plugin instance */ public Plugin setGroupId(String groupId) { this.groupId = groupId; if (!isNew()) { if (groupId == null) { pluginElement.removeChild("groupId"); } else if (pluginElement.hasSingleChild("groupId")) { pluginElement.getSingleChild("groupId").setText(groupId); } else { pluginElement.insertChild(createElement("groupId", groupId), inTheBegin()); } } return this; }
/** * Returns build plugins mapped as {@code plugin.getId() -> plugin} * * @return mapped plugins or empty map if build doesn't have plugins * @see Plugin#getId() */ public Map<String, Plugin> getPluginsAsMap() { final Map<String, Plugin> pluginsMap = new HashMap<>(); for (Plugin plugin : plugins()) { pluginsMap.put(plugin.getId(), plugin); } return pluginsMap; }
/** Sets plugin version. */ public Plugin setVersion(String version) { this.version = version; if (!isNew()) { if (version == null) { pluginElement.removeChild("version"); } else if (pluginElement.hasSingleChild("version")) { pluginElement.getSingleChild("version").setText(version); } else { pluginElement.insertChild( createElement("version", version), after("artifactId").or(inTheBegin())); } } return this; }
/** * Sets plugin artifact identifier * * @param artifactId new artifact identifier, if new artifact id is {@code null} and current * plugin element related with xml element then <i>artifactId</i> element will be removed from * xml as well as from plugin model * @return this plugin instance */ public Plugin setArtifactId(String artifactId) { this.artifactId = artifactId; if (!isNew()) { if (artifactId == null) { pluginElement.removeChild("artifactId"); } else if (pluginElement.hasSingleChild("artifactId")) { pluginElement.getSingleChild("artifactId").setText(artifactId); } else { pluginElement.insertChild( createElement("artifactId", artifactId), after("groupId").or(inTheBegin())); } } return this; }