/** * Returns this module as a Dependency with the given scope and type * * @param scope the DependencyScope to use * @param type the DependencyType to use * @return a non-<code>null</code> instance */ public Dependency asDependency(final DependencyScope scope, final DependencyType type) { return new Dependency(gav, type, scope); }
final Element dependencyElement = XmlUtils.findFirstElement( "/project/dependencies/dependency[groupId = '" + dependency.getGroupId() + "' and artifactId = '" + dependency.getArtifactId() + "' and version = '" + dependency.getVersion() + "']", root); if (dependencyElement == null) { return; descriptionOfChange = highlight(ADDED + " scope") + " " + dependencyScope.name().toLowerCase() + " to dependency " + dependency.getSimpleDescription(); } else { descriptionOfChange = null; descriptionOfChange = highlight(CHANGED + " scope") + " to " + dependencyScope.name().toLowerCase() + " in dependency " + dependency.getSimpleDescription(); } else { dependencyElement.removeChild(scopeElement); descriptionOfChange = highlight(REMOVED + " scope") + " from dependency " + dependency.getSimpleDescription();
public int compareTo(final Dependency o) { final int result = compareCoordinates(o); if (result != 0) { return result; } return version.compareTo(o.getVersion()); }
/** * 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 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; }
for (final Iterator<Element> iter = existingDependencyElements.iterator(); iter.hasNext();) { final Element candidate = iter.next(); final Dependency candidateDependency = new Dependency(candidate); if (candidateDependency.equals(dependencyToRemove)) { removedDependencies.add(candidateDependency.getSimpleDescription());
if (StringUtils.isEmpty(newDependency.getVersion())) { continue; final Dependency existingDependency = new Dependency(existingDependencyElement); if (existingDependency.hasSameCoordinates(newDependency)) { inserted = true; break; removeVersionIfBlank(newDependency.getElement(parentDocument)); dependencyManagementElement.appendChild(newDependencyElement); finalDependencies.add(newDependency); addedDependencies.add(newDependency.getSimpleDescription()); final Dependency existingDependency = new Dependency(existingDependencyElement); if (existingDependency.hasSameCoordinates(newDependency)) { if (addToDependencyManagement && !StringUtils.isEmpty(newDependency.getVersion())) { removeManagementConfiguration(newDependency.getElement(document)); } else { newDependencyElement = removeVersionIfBlank(newDependency.getElement(document)); Dependency newDependencyWithoutVersion = new Dependency(newDependencyElement); if (!newDependencyWithoutVersion.getVersion().equals(existingDependency.getVersion())) { addedDependencies.add(newDependency.getSimpleDescription()); removedDependencies.add(existingDependency.getSimpleDescription());
final String version = DomUtils.getTextContent(versionElement, ""); final Dependency dependency = new Dependency(groupId, artifactId, version); dependency.addExclusion(exclusionGroupId, exclusionArtifactId);
/** * 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; }
private String bundleImportFor(Dependency dependency) { String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersionId(); try { return dependencyMap.getString(key); } catch (MissingResourceException ex) { return null; } }
/** * Returns true if the given feature is installed in current project. * * @param moduleName feature name to check in current project * @return true if given feature name is installed, otherwise returns false */ public boolean isInstalledInModule(final String moduleName) { final Pom pom = getProjectOperations().getPomFromModuleName(moduleName); if (pom == null) { return false; } // Look for gvnix jpa dependency for (final Dependency dependency : pom.getDependencies()) { if ("org.gvnix.addon.jpa.annotations".equals(dependency .getArtifactId())) { return true; } } return false; }
final Element dependenciesElement = XmlUtils.findFirstElement(containingPath, root); for (final Element candidate : XmlUtils.findElements(path, root)) { if (dependency.equals(new Dependency(candidate))) { dependenciesElement.removeChild(candidate); descriptionOfChange = highlight(REMOVED + " dependency") + " " + dependency.getSimpleDescription();
/** * 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; }
/** * Adds the given exclusion to this dependency * * @param exclusionGroupId the groupId of the dependency to exclude * (required) * @param exclusionArtifactId the artifactId of the dependency to exclude * (required) */ public void addExclusion(final String exclusionGroupId, final String exclusionArtifactId) { Validate.notBlank(exclusionGroupId, "Excluded groupId required"); Validate.notBlank(exclusionArtifactId, "Excluded artifactId required"); exclusions.add(new Dependency(exclusionGroupId, exclusionArtifactId, "ignored")); }
/** * 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); }
DomUtils.createChildElement("exclusion", exclusionsElement, document); exclusionElement.appendChild(XmlUtils.createTextElement(document, "groupId", exclusion.getGroupId())); exclusionElement.appendChild(XmlUtils.createTextElement(document, "artifactId", exclusion.getArtifactId()));
/** * Returns this module as a Dependency with the given scope * * @param scope the DependencyScope to use * @return a non-<code>null</code> instance */ public Dependency asDependency(final DependencyScope scope) { return new Dependency(gav, DependencyType.valueOfTypeCode(packaging), scope); }
private List<Dependency> getDependencies(final String xPathExpression, final Element configuration) { final List<Dependency> dependencies = new ArrayList<Dependency>(); for (final Element dependencyElement : XmlUtils.findElements(xPathExpression + "/dependencies/dependency", configuration)) { final Dependency dependency = new Dependency(dependencyElement); dependencies.add(dependency); } return dependencies; }
public final void removeDependency(final String moduleName, final String groupId, final String artifactId, final String version, final String classifier) { Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time"); Validate.notNull(groupId, "Group ID required"); Validate.notNull(artifactId, "Artifact ID required"); Validate.notBlank(version, "Version required"); final Dependency dependency = new Dependency(groupId, artifactId, version, DependencyType.JAR, COMPILE, classifier); removeDependency(moduleName, dependency); }
@Override public final Dependency addDependency(final String moduleName, final String groupId, final String artifactId, final String version, DependencyScope scope, final String classifier, boolean addToDependencyManagement) { Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time"); Validate.notNull(groupId, "Group ID required"); Validate.notNull(artifactId, "Artifact ID required"); Validate.notBlank(version, "Version required"); if (scope == null) { scope = COMPILE; } final Dependency dependency = new Dependency(groupId, artifactId, version, DependencyType.JAR, scope, classifier); return addDependency(moduleName, dependency, addToDependencyManagement, false); }