/** * 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; }
/** * Indicates whether the given dependency is registered in dependencyManagement 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 isDependencyRegisteredInDependencyManagement(final Dependency dependency, boolean checkVersion) { if (checkVersion) { return dependency != null && dependenciesInDependencyManagement.contains(dependency); } boolean registered = false; Iterator<Dependency> it = dependenciesInDependencyManagement.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; }
/** * 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; }
/** * 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; }
DomUtils.createChildElement("exclusion", exclusionsElement, document); exclusionElement.appendChild(XmlUtils.createTextElement(document, "groupId", exclusion.getGroupId())); exclusionElement.appendChild(XmlUtils.createTextElement(document, "artifactId", exclusion.getArtifactId()));
final Element dependencyElement = XmlUtils.findFirstElement( "/project/dependencies/dependency[groupId = '" + dependency.getGroupId() + "' and artifactId = '" + dependency.getArtifactId() + "' and version = '" + dependency.getVersion() + "']", root);
private String bundleImportFor(Dependency dependency) { String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersionId(); try { return dependencyMap.getString(key); } catch (MissingResourceException ex) { return null; } }
/** * Install envers dependency on project */ private void installEnversDependency() { // Locate hiberante dependency ProjectMetadata projectMetadata = getProjectMetadata(); Set<Dependency> hibernateDependencies = getHibernateDependency(projectMetadata); if (hibernateDependencies.isEmpty()) { throw new IllegalStateException("No Hibernate dependency found"); } if (hibernateDependencies.size() > 1) { throw new IllegalStateException( "Error on Hibernate dependency: > 1 found for " .concat(HIBERNATE_DEPENDENCY.getSimpleDescription())); } // Gets hibernate-entityManager version String hibernateVersion = hibernateDependencies.iterator().next() .getVersion(); // Install hibernate envers dependency using hibernate-entityManager // version Dependency enversDependency = new Dependency( HIBERNATE_ENVERS_DEPENDENCY.getGroupId(), HIBERNATE_ENVERS_DEPENDENCY.getArtifactId(), hibernateVersion); projectOperations.addDependency( projectOperations.getFocusedModuleName(), enversDependency); }