Esempio n. 1
0
  /**
   * Indicates whether the given dependency is registered without checking dependency version , by
   * checking the result of {@link Dependency#equals(Object)}.
   *
   * @param dependency the dependency to check (can be <code>null</code>)
   * @return <code>false</code> if a <code>null</code> dependency is given
   */
  public boolean isDependencyRegistered(final Dependency dependency, boolean checkVersion) {
    if (checkVersion) {
      return dependency != null && dependencies.contains(dependency);
    }

    boolean registered = false;
    Iterator<Dependency> it = dependencies.iterator();
    while (it.hasNext()) {
      Dependency dp = it.next();
      if (dependency.getGroupId().equals(dp.getGroupId())
          && dependency.getArtifactId().equals(dp.getArtifactId())) {
        registered = true;
        break;
      }
    }
    return dependency != null && registered;
  }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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) {
   return newDependency != null
       && !isDependencyRegistered(newDependency, false)
       && !Dependency.isHigherLevel(newDependency.getType().toString(), packaging);
 }