use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParser method parse.
private DependencyNode parse(BufferedReader in) throws IOException {
if (substitutions != null) {
substitutionIterator = substitutions.iterator();
}
String line = null;
DependencyNode root = null;
DependencyNode node = null;
int prevLevel = 0;
LinkedList<DependencyNode> stack = new LinkedList<DependencyNode>();
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 IllegalArgumentException("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().isReference()) {
DependencyNode child = reference(ctx.getDefinition().getReference());
node.getChildren().add(child);
node = child;
} else {
node = build(isRootNode ? null : stack.getLast(), ctx, isRootNode);
if (isRootNode) {
root = node;
isRootNode = false;
}
if (ctx.getDefinition() != null && ctx.getDefinition().hasId()) {
this.nodes.put(ctx.getDefinition().getId(), node);
}
}
}
this.nodes.clear();
return root;
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParser method parseMultiple.
/**
* Parse multiple graphs in one resource, divided by "---".
*/
public List<DependencyNode> parseMultiple(String resource) throws IOException {
URL res = this.getClass().getClassLoader().getResource(prefix + resource);
if (res == null) {
throw new IOException("Could not find classpath resource " + prefix + resource);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(res.openStream(), "UTF-8"));
List<DependencyNode> ret = new ArrayList<DependencyNode>();
DependencyNode root = null;
while ((root = parse(reader)) != null) {
ret.add(root);
}
return ret;
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method testResourceLoadingWithPrefix.
@Test
public void testResourceLoadingWithPrefix() throws UnsupportedEncodingException, IOException {
String prefix = "org/sonatype/aether/test/util/";
parser = new DependencyGraphParser(prefix);
String name = "testResourceLoading.txt";
DependencyNode node = parser.parse(name);
assertEquals(0, node.getChildren().size());
assertNodeProperties(node, "");
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
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.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DefaultDependencyCollectorTest method testSimpleCollection.
@Test
public void testSimpleCollection() throws IOException, DependencyCollectionException {
DependencyNode root = parser.parseLiteral("gid:aid:ext:ver");
Dependency dependency = root.getDependency();
CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
CollectResult result = collector.collectDependencies(session, request);
assertEquals(0, result.getExceptions().size());
DependencyNode newRoot = result.getRoot();
Dependency newDependency = newRoot.getDependency();
assertEquals(dependency, newDependency);
assertEquals(dependency.getArtifact(), newDependency.getArtifact());
assertEquals(1, newRoot.getChildren().size());
DependencyNode expect = parser.parseLiteral("gid:aid2:ext:ver:compile");
assertEquals(expect.getDependency(), newRoot.getChildren().get(0).getDependency());
}
Aggregations