/** * Locates any dependencies which match the presented dependency, excluding * the version number. This is useful for upgrade use cases, where it is * necessary to remove any dependencies with the same group id, artifact id, * and type as the dependency being upgraded to. * * @param dependency to locate (can be <code>null</code>) * @return any matching dependencies (never returns null, but may return an * empty {@link Set}) */ public Set<Dependency> getDependenciesExcludingVersion(final Dependency dependency) { final Set<Dependency> result = new HashSet<Dependency>(); for (final Dependency d : dependencies) { if (dependency != null && dependency.getArtifactId().equals(d.getArtifactId()) && dependency.getGroupId().equals(d.getGroupId()) && dependency.getType().equals(d.getType())) { result.add(d); } } return result; }
/** * Indicates whether it's valid to add the given {@link Dependency} to this * POM. * * @param newDependency the {@link Dependency} to check (can be * <code>null</code>) * @return see above * @since 1.2.1 */ public boolean canAddDependency(final Dependency newDependency, boolean checkVersion) { return newDependency != null && !isDependencyRegistered(newDependency, checkVersion) && !Dependency.isHigherLevel(newDependency.getType().toString(), packaging); }
/** * Indicates whether it's valid to add the given {@link Dependency} to the dependencyManagement * of this pom * * @param newDependency the {@link Dependency} to check (can be * <code>null</code>) * @return see above * @since 2.0 */ public boolean canAddDependencyToDependencyManagement(final Dependency newDependency, boolean checkVersion) { return newDependency != null && !isDependencyRegisteredInDependencyManagement(newDependency, checkVersion) && !Dependency.isHigherLevel(newDependency.getType().toString(), packaging); }
/** * Compares this dependency's identifying coordinates (i.e. not the version) * to those of the given dependency * * @param other the dependency being compared to (required) * @return see {@link Comparable#compareTo(Object)} */ private int compareCoordinates(final Dependency other) { Validate.notNull(other, "Dependency being compared to cannot be null"); int result = groupId.compareTo(other.getGroupId()); if (result == 0) { result = artifactId.compareTo(other.getArtifactId()); } if (result == 0) { result = StringUtils.stripToEmpty(classifier).compareTo( StringUtils.stripToEmpty(other.getClassifier())); } if (result == 0 && type != null) { result = type.compareTo(other.getType()); } return result; }