private void removeExclusions() { if (!isNew()) { dependencyElement.removeChild("exclusions"); } this.exclusions = null; }
public void remove() { if (!isNew()) { dependencyElement.remove(); dependencyElement = null; } }
/** * Sets list of artifacts that should be excluded from this dependency's artifact list when it * comes to calculating transitive dependencies. * * <p>If {@code exclusions} is {@code null} or <i>empty</i> and this dependency instance is * associated with xml element then {@code exclusions} be removed from model as well as from xml. * * @param exclusions new dependency exclusions * @return this dependency instance */ public Dependency setExclusions(Collection<? extends Exclusion> exclusions) { if (exclusions == null || exclusions.isEmpty()) { removeExclusions(); } else if (isNew()) { this.exclusions = new ArrayList<>(exclusions); } else { setExclusions0(exclusions); } return this; }
/** * Removes exclusion from the dependency exclusions. * * <p>If last exclusion has been removed removes exclusions element as well. * * @param exclusion exclusion which should be removed * @return this dependency instance * @throws NullPointerException when {@code exclusion} is {@code null} */ public Dependency removeExclusion(Exclusion exclusion) { requireNonNull(exclusion, "Required not null exclusion"); exclusions().remove(exclusion); // remove dependency from xml if (!isNew() && exclusions.isEmpty()) { dependencyElement.removeChild("exclusions"); exclusion.exclusionElement = null; } else { exclusion.remove(); } return this; }
/** * Adds new exclusion to the list of dependency exclusions. * * <p>If dependency doesn't have exclusions then it will be added to xml. * * @param exclusion new exclusion which will be added * @return this dependency instance * @throws NullPointerException when {@code exclusion} is {@code null} */ public Dependency addExclusion(Exclusion exclusion) { requireNonNull(exclusion, "Required not null exclusion"); exclusions().add(exclusion); // add exclusion to xml tree if (!isNew()) { if (dependencyElement.hasSingleChild("exclusions")) { dependencyElement.getSingleChild("exclusions").appendChild(exclusion.asXMLElement()); } else { dependencyElement.appendChild(createElement("exclusions", exclusion.asXMLElement())); } exclusion.exclusionElement = dependencyElement.getSingleChild("exclusions").getLastChild(); } return this; }
/** * Sets the type of dependency. * * <p>This defaults to <code>jar</code>. While it usually represents the extension on the filename * of the dependency, that is not always the case. A type can be mapped to a different extension * and a classifier. The type often corresponds to the packaging used, though this is also not * always the case. Some examples are {@code jar, war, ejb-client}. New types can be defined by * plugins that set {@code extensions} to {@code true}, so this is not a complete list. * * <p>If {@code type} is {@code null} and this dependency instance is associated with xml element * then {@code type} will be removed from model as well as from xml. * * @param type new dependency type * @return this dependency instance */ public Dependency setType(String type) { this.type = type; if (!isNew()) { if (type == null) { dependencyElement.removeChild("type"); } else if (dependencyElement.hasSingleChild("type")) { dependencyElement.getSingleChild("type").setText(type); } else { dependencyElement.appendChild(createElement("type", type)); } } return this; }
/** * Sets the project group that produced the dependency, e.g. <i>org.apache.maven</i>. * * <p>If {@code groupId} is {@code null} and this dependency instance is associated with xml * element then {@code groupId} will be removed from model as well as from xml. * * @param groupId new dependency groupId * @return this dependency instance */ public Dependency setGroupId(String groupId) { this.groupId = groupId; if (!isNew()) { if (groupId == null) { dependencyElement.removeChild("groupId"); } else if (dependencyElement.hasSingleChild("groupId")) { dependencyElement.getSingleChild("groupId").setText(groupId); } else { dependencyElement.insertChild(createElement("groupId", groupId), inTheBegin()); } } return this; }
/** * Sets indicates the dependency is optional for use of this library. * * <p>If {@code optional} is {@code null} and this dependency instance is associated with xml * element then {@code optional} will be removed from model as well as from xml. * * @param optional new dependency optional parameter * @return this dependency instance * @see #setOptional(boolean) */ public Dependency setOptional(String optional) { this.optional = optional; if (!isNew()) { if (optional == null) { dependencyElement.removeChild("optional"); } else if (dependencyElement.hasSingleChild("optional")) { dependencyElement.getSingleChild("optional").setText(optional); } else { dependencyElement.insertChild(createElement("optional", optional), inTheBegin()); } } return this; }
if (!isNew()) { if (scope == null) { dependencyElement.removeChild("scope");
/** * Sets the unique id for an artifact produced by the project group, e.g. {@code maven-artifact}. * * <p>If {@code artifactId} is {@code null} and this dependency instance is associated with xml * element then {@code artifactId} will be removed from model as well as from xml. */ public Dependency setArtifactId(String artifactId) { this.artifactId = artifactId; if (!isNew()) { if (artifactId == null) { dependencyElement.removeChild("artifactId"); } else if (dependencyElement.hasSingleChild("artifactId")) { dependencyElement.getSingleChild("artifactId").setText(artifactId); } else { dependencyElement.insertChild( createElement("artifactId", artifactId), after("groupId").or(inTheBegin())); } } return this; }
/** * Sets the classifier of the dependency. * * <p>If {@code classifier} is {@code null} and this dependency instance is associated with xml * element then {@code classifier} will be removed from model as well as from xml. * * @param classifier new dependency classifier * @return this dependency instance */ public Dependency setClassifier(String classifier) { this.classifier = classifier; if (!isNew()) { if (classifier == null) { dependencyElement.removeChild("classifier"); } else if (dependencyElement.hasSingleChild("classifier")) { dependencyElement.getSingleChild("classifier").setText(classifier); } else { dependencyElement.insertChild( createElement("classifier", classifier), before("exclusions").or(inTheEnd())); } } return this; }
/** * Set the version of the dependency, e.g. <i>3.2.1</i>. In Maven 2, this can also be specified as * a range of versions. * * <p>If {@code version} is {@code null} and this dependency instance is associated with xml * element then {@code version} will be removed from model as well as from xml. * * @param version new dependency version * @return this dependency instance */ public Dependency setVersion(String version) { this.version = version; if (!isNew()) { if (version == null) { dependencyElement.removeChild("version"); } else if (dependencyElement.hasChild("version")) { dependencyElement.getSingleChild("version").setText(version); } else { dependencyElement.insertChild( createElement("version", version), afterAnyOf("artifactId", "groupId").or(inTheBegin())); } } return this; }