use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class JavaEffectiveScopeCalculator method getInheritedScopes.
private Set<String> getInheritedScopes(ConflictGroup group, Map<?, ?> conflictIds, Set<?> prerequisites) {
Set<String> inheritedScopes = new HashSet<String>();
for (Map.Entry<DependencyNode, List<DependencyNode>> entry : group.parents.entrySet()) {
String childScope = entry.getKey().getDependency().getScope();
if (entry.getValue().isEmpty()) {
inheritedScopes.add(childScope);
} else {
for (DependencyNode parent : entry.getValue()) {
if (prerequisites != null && !prerequisites.contains(conflictIds.get(parent))) {
/*
* There's a cycle and the parent node belongs to a later group, i.e. its scope is not yet
* calculated so ignore it.
*/
continue;
}
String parentScope = parent.getDependency().getScope();
String inheritedScope = getInheritedScope(parentScope, childScope);
inheritedScopes.add(inheritedScope);
}
}
}
return inheritedScopes;
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class NearestVersionConflictResolver method backtrack.
private void backtrack(ConflictGroup group, Map<?, ?> conflictIds, DependencyNode root) throws UnsolvableVersionConflictException {
group.version = null;
for (Iterator<Map.Entry<DependencyNode, Position>> it = group.candidates.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<DependencyNode, Position> entry = it.next();
Version version = entry.getKey().getVersion();
Position pos = entry.getValue();
if (!isAcceptable(group, version)) {
it.remove();
} else if (group.version == null || isNearer(pos, version, group.position, group.version)) {
group.version = version;
group.position = pos;
}
}
if (group.version == null) {
throw newFailure(group, conflictIds, root);
}
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class NearestVersionConflictResolver method pruneNonSelectedVersions.
private void pruneNonSelectedVersions(ConflictGroup group, Map<?, ?> conflictIds) {
for (Position pos : group.positions) {
for (Iterator<DependencyNode> it = pos.parent.getChildren().iterator(); it.hasNext(); ) {
DependencyNode child = it.next();
Object key = conflictIds.get(child);
if (group.key.equals(key)) {
if (!group.pruned && group.position.depth == pos.depth && group.version.equals(child.getVersion())) {
group.pruned = true;
} else {
it.remove();
}
}
}
}
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class NearestVersionConflictResolver method newFailure.
private UnsolvableVersionConflictException newFailure(final ConflictGroup group, final Map<?, ?> conflictIds, DependencyNode root) {
DependencyFilter filter = new DependencyFilter() {
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
return group.key.equals(conflictIds.get(node));
}
};
PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(filter);
root.accept(visitor);
return new UnsolvableVersionConflictException(visitor.getPaths(), group.key);
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class NearestVersionConflictResolverTest method testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen.
@Test
public void testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen() throws Exception {
// root
// +- x:1
// +- a:1
// | \- b:1
// | \- x:3
// +- c:1
// | \- x:2
// \- d:1
// \- e:1
// \- x:[2,) # forces rejection of x:1, should fallback to nearest and not first-seen, i.e. x:2 and not x:3
DependencyNode x1 = builder.artifactId("x").version("1").build();
DependencyNode x2 = builder.artifactId("x").version("2").build();
DependencyNode x3 = builder.artifactId("x").version("3").build();
DependencyNode x2r = builder.artifactId("x").version("2").range("[2,)").build();
DependencyNode b = builder.artifactId("b").version("1").build();
b.getChildren().add(x3);
DependencyNode a = builder.artifactId("a").build();
a.getChildren().add(b);
DependencyNode c = builder.artifactId("c").build();
c.getChildren().add(x2);
DependencyNode e = builder.artifactId("e").build();
e.getChildren().add(x2r);
DependencyNode d = builder.artifactId("d").build();
d.getChildren().add(e);
DependencyNode root = builder.artifactId(null).build();
root.getChildren().add(x1);
root.getChildren().add(a);
root.getChildren().add(c);
root.getChildren().add(d);
Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
conflictIds.put(x1, "x");
conflictIds.put(x2, "x");
conflictIds.put(x3, "x");
conflictIds.put(x2r, "x");
conflictIds.put(a, "a");
conflictIds.put(b, "b");
conflictIds.put(c, "c");
conflictIds.put(d, "d");
conflictIds.put(e, "e");
context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
root = transformer.transformGraph(root, context);
List<DependencyNode> trail = find(root, "x");
assertEquals(3, trail.size());
assertSame(x2, trail.get(0));
}
Aggregations