@Override public Dependency map(Element element) { return new Dependency(element); } }
private void setExclusions0(Collection<? extends Exclusion> exclusions) { for (Exclusion exclusion : exclusions()) { exclusion.remove(); } // use addExclusion to add and associate each new exclusion with element this.exclusions = new ArrayList<>(exclusions.size()); for (Exclusion exclusion : exclusions) { addExclusion(exclusion); } }
/** * 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; }
private void removeExclusions() { if (!isNew()) { dependencyElement.removeChild("exclusions"); } this.exclusions = null; }
private NewElement newDependencyElement(List<Dependency> dependencies) { final NewElement dependenciesElement = createElement("dependencies"); for (Dependency dependency : dependencies) { dependenciesElement.appendChild(dependency.asXMLElement()); } return dependenciesElement; }
private void removeDependencyFromXML(Dependency dependency) { if (dependencies.isEmpty()) { dependenciesParent.removeChild("dependencies"); dependency.dependencyElement = null; } else { dependency.remove(); } }
/** * Sets indicates the dependency is optional for use of this library. * * @see #setOptional(String) */ public Dependency setOptional(boolean optional) { return setOptional(String.valueOf(optional)); }
public void remove() { if (!isNew()) { dependencyElement.remove(); dependencyElement = null; } }
/** * 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; }
NewElement asXMLElement() { final NewElement newDependencies = createElement("dependencies"); for (Dependency dependency : dependencies) { newDependencies.appendChild(dependency.asXMLElement()); } return newDependencies; }
private void setDependencies(Collection<? extends Dependency> newDependencies) { // removing all dependencies from xml tree for (Dependency dependency : dependencies) { dependency.remove(); } // add and associate each new dependency with element in tree dependencies = new ArrayList<>(newDependencies.size()); for (Dependency newDependency : newDependencies) { add(newDependency); } }
@Override public Dependency map(Element element) { return new Dependency(element); } }
/** * 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; }
private void addDependencyToXML(Dependency dependency) { if (dependenciesParent.hasSingleChild("dependencies")) { dependenciesParent.getSingleChild("dependencies").appendChild(dependency.asXMLElement()); } else { dependenciesParent.appendChild(createElement("dependencies", dependency.asXMLElement())); } dependency.dependencyElement = dependenciesParent.getSingleChild("dependencies").getLastChild(); }
model .dependencies() .add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion)); model.writeTo(pom);
if (!isNew()) { if (scope == null) { dependencyElement.removeChild("scope");
private NewElement newDependencyManagementElement(List<Dependency> dependencies) { final NewElement dependenciesElement = createElement("dependencies"); for (Dependency dependency : dependencies) { dependenciesElement.appendChild(dependency.asXMLElement()); } final NewElement dependencyManagement = createElement("dependencyManagement"); dependencyManagement.appendChild(dependenciesElement); return dependencyManagement; }
/** * 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; }
/** * 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; }