use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DefaultDependencyCollectorTest method testSimpleCollection.
@Test
public void testSimpleCollection() throws DependencyCollectionException {
Dependency dependency = newDep("gid:aid:ext:ver", "compile");
CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
CollectResult result = collector.collectDependencies(session, request);
assertEquals(0, result.getExceptions().size());
DependencyNode root = result.getRoot();
Dependency newDependency = root.getDependency();
assertEquals(dependency, newDependency);
assertEquals(dependency.getArtifact(), newDependency.getArtifact());
assertEquals(1, root.getChildren().size());
Dependency expect = newDep("gid:aid2:ext:ver", "compile");
assertEquals(expect, root.getChildren().get(0).getDependency());
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DependencyGraphParser method parse.
private DependencyNode parse(BufferedReader in) throws IOException {
Iterator<String> substitutionIterator = (substitutions != null) ? substitutions.iterator() : null;
String line = null;
DependencyNode root = null;
DependencyNode node = null;
int prevLevel = 0;
Map<String, DependencyNode> nodes = new HashMap<>();
LinkedList<DependencyNode> stack = new LinkedList<>();
boolean isRootNode = true;
while ((line = in.readLine()) != null) {
line = cutComment(line);
if (isEmpty(line)) {
// skip empty line
continue;
}
if (isEOFMarker(line)) {
// stop parsing
break;
}
while (line.contains("%s")) {
if (!substitutionIterator.hasNext()) {
throw new IllegalStateException("not enough substitutions to fill placeholders");
}
line = line.replaceFirst("%s", substitutionIterator.next());
}
LineContext ctx = createContext(line);
if (prevLevel < ctx.getLevel()) {
// previous node is new parent
stack.add(node);
}
// get to real parent
while (prevLevel > ctx.getLevel()) {
stack.removeLast();
prevLevel -= 1;
}
prevLevel = ctx.getLevel();
if (ctx.getDefinition() != null && ctx.getDefinition().reference != null) {
String reference = ctx.getDefinition().reference;
DependencyNode child = nodes.get(reference);
if (child == null) {
throw new IllegalStateException("undefined reference " + reference);
}
node.getChildren().add(child);
} else {
node = build(isRootNode ? null : stack.getLast(), ctx, isRootNode);
if (isRootNode) {
root = node;
isRootNode = false;
}
if (ctx.getDefinition() != null && ctx.getDefinition().id != null) {
nodes.put(ctx.getDefinition().id, node);
}
}
}
return root;
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class DependencyGraphParser method parseLiteral.
/**
* Parse the given graph definition.
*/
public DependencyNode parseLiteral(String dependencyGraph) throws IOException {
BufferedReader reader = new BufferedReader(new StringReader(dependencyGraph));
DependencyNode node = parse(reader);
reader.close();
return node;
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class NearestVersionSelectorTest method testOverlappingCycles.
@Test
public void testOverlappingCycles() throws Exception {
DependencyNode root = parseResource("overlapping-cycles.txt");
assertSame(root, transform(root));
assertEquals(2, root.getChildren().size());
}
use of org.eclipse.aether.graph.DependencyNode in project maven-resolver by apache.
the class SimpleConflictMarker method mark.
private void mark(DependencyNode node, Map<DependencyNode, Object> conflictIds) {
Dependency dependency = node.getDependency();
if (dependency != null) {
Artifact artifact = dependency.getArtifact();
String key = String.format("%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension());
if (conflictIds.put(node, key) != null) {
return;
}
}
for (DependencyNode child : node.getChildren()) {
mark(child, conflictIds);
}
}
Aggregations