use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DefaultDependencyCollectorTest method assertEqualSubtree.
private static void assertEqualSubtree(DependencyNode expected, DependencyNode actual, LinkedList<DependencyNode> parents) {
assertEquals("path: " + parents, expected.getDependency(), actual.getDependency());
if (actual.getDependency() != null) {
Artifact artifact = actual.getDependency().getArtifact();
for (DependencyNode parent : parents) {
if (parent.getDependency() != null && artifact.equals(parent.getDependency().getArtifact())) {
return;
}
}
}
parents.addLast(expected);
assertEquals("path: " + parents + ", expected: " + expected.getChildren() + ", actual: " + actual.getChildren(), expected.getChildren().size(), actual.getChildren().size());
Iterator<DependencyNode> iterator1 = expected.getChildren().iterator();
Iterator<DependencyNode> iterator2 = actual.getChildren().iterator();
while (iterator1.hasNext()) {
assertEqualSubtree(iterator1.next(), iterator2.next(), parents);
}
parents.removeLast();
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DefaultDependencyCollectorTest method testDependencyManagement_TransitiveDependencyManager.
@Test
public void testDependencyManagement_TransitiveDependencyManager() throws DependencyCollectionException, IOException {
collector.setArtifactDescriptorReader(newReader("managed/"));
parser = new DependencyGraphParser("artifact-descriptions/managed/");
session.setDependencyManager(new TransitiveDependencyManager());
final Dependency root = newDep("gid:root:ext:ver", "compile");
CollectRequest request = new CollectRequest(root, Collections.singletonList(repository));
request.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
CollectResult result = collector.collectDependencies(session, request);
final DependencyNode expectedTree = parser.parseResource("management-tree.txt");
assertEqualSubtree(expectedTree, result.getRoot());
// Same test for root artifact (POM) request.
final CollectRequest rootArtifactRequest = new CollectRequest();
rootArtifactRequest.setRepositories(Collections.singletonList(repository));
rootArtifactRequest.setRootArtifact(new DefaultArtifact("gid:root:ext:ver"));
rootArtifactRequest.addDependency(newDep("gid:direct:ext:ver", "compile"));
rootArtifactRequest.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
rootArtifactRequest.addManagedDependency(newDep("gid:direct:ext:must-retain-core-management"));
rootArtifactRequest.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
session.setDependencyManager(new TransitiveDependencyManager());
result = collector.collectDependencies(session, rootArtifactRequest);
assertEqualSubtree(expectedTree, toDependencyResult(result.getRoot(), "compile", null));
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DefaultDependencyCollectorTest method testPartialResultOnError.
@Test
public void testPartialResultOnError() throws IOException {
DependencyNode root = parser.parseResource("expectedPartialSubtreeOnError.txt");
Dependency dependency = root.getDependency();
CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
CollectResult result;
try {
result = collector.collectDependencies(session, request);
fail("expected exception ");
} catch (DependencyCollectionException e) {
result = e.getResult();
assertSame(request, result.getRequest());
assertNotNull(result.getExceptions());
assertEquals(1, result.getExceptions().size());
assertTrue(result.getExceptions().get(0) instanceof ArtifactDescriptorException);
assertEqualSubtree(root, result.getRoot());
}
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DefaultDependencyCollectorTest method testCyclicProjects.
@Test
public void testCyclicProjects() throws Exception {
CollectRequest request = new CollectRequest(newDep("test:a:2"), Arrays.asList(repository));
collector.setArtifactDescriptorReader(newReader("versionless-cycle/"));
CollectResult result = collector.collectDependencies(session, request);
DependencyNode root = result.getRoot();
DependencyNode a1 = path(root, 0, 0);
assertEquals("a", a1.getArtifact().getArtifactId());
assertEquals("1", a1.getArtifact().getVersion());
for (DependencyNode child : a1.getChildren()) {
assertNotEquals("1", child.getArtifact().getVersion());
}
assertEquals(1, result.getCycles().size());
DependencyCycle cycle = result.getCycles().get(0);
assertEquals(Arrays.asList(), cycle.getPrecedingDependencies());
assertEquals(Arrays.asList(root.getDependency(), path(root, 0).getDependency(), a1.getDependency()), cycle.getCyclicDependencies());
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DependencyGraphDumper method dump.
private static void dump(Context context, DependencyNode node, int depth, boolean last) {
Line line = context.nodes.get(node);
if (line != null) {
if (line.id <= 0) {
line.id = ++context.ids;
}
context.lines.add(new Line(null, line.id, depth, last));
return;
}
Dependency dependency = node.getDependency();
if (dependency == null) {
line = new Line(null, 0, depth, last);
} else {
line = new Line(dependency, 0, depth, last);
}
context.lines.add(line);
context.nodes.put(node, line);
depth++;
for (Iterator<DependencyNode> it = node.getChildren().iterator(); it.hasNext(); ) {
DependencyNode child = it.next();
dump(context, child, depth, !it.hasNext());
}
}
Aggregations