use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class PatternInclusionsDependencyFilterTest method acceptTestMatches.
@Test
public void acceptTestMatches() {
NodeBuilder builder = new NodeBuilder();
builder.groupId("com.example.test").artifactId("testArtifact").ext("jar").version("1.0.3");
DependencyNode node = builder.build();
// full match
assertEquals("com.example.test:testArtifact:jar:1.0.3", true, accept(node, "com.example.test:testArtifact:jar:1.0.3"));
// single wildcard
assertEquals("*:testArtifact:jar:1.0.3", true, accept(node, "*:testArtifact:jar:1.0.3"));
assertEquals("com.example.test:*:jar:1.0.3", true, accept(node, "com.example.test:*:jar:1.0.3"));
assertEquals("com.example.test:testArtifact:*:1.0.3", true, accept(node, "com.example.test:testArtifact:*:1.0.3"));
assertEquals("com.example.test:testArtifact:*:1.0.3", true, accept(node, "com.example.test:testArtifact:*:1.0.3"));
// implicit wildcard
assertEquals(":testArtifact:jar:1.0.3", true, accept(node, ":testArtifact:jar:1.0.3"));
assertEquals("com.example.test::jar:1.0.3", true, accept(node, "com.example.test::jar:1.0.3"));
assertEquals("com.example.test:testArtifact::1.0.3", true, accept(node, "com.example.test:testArtifact::1.0.3"));
assertEquals("com.example.test:testArtifact:jar:", true, accept(node, "com.example.test:testArtifact:jar:"));
// multi wildcards
assertEquals("*:*:jar:1.0.3", true, accept(node, "*:*:jar:1.0.3"));
assertEquals("com.example.test:*:*:1.0.3", true, accept(node, "com.example.test:*:*:1.0.3"));
assertEquals("com.example.test:testArtifact:*:*", true, accept(node, "com.example.test:testArtifact:*:*"));
assertEquals("*:testArtifact:jar:*", true, accept(node, "*:testArtifact:jar:*"));
assertEquals("*:*:jar:*", true, accept(node, "*:*:jar:*"));
assertEquals(":*:jar:", true, accept(node, ":*:jar:"));
// partial wildcards
assertEquals("*.example.test:testArtifact:jar:1.0.3", true, accept(node, "*.example.test:testArtifact:jar:1.0.3"));
assertEquals("com.example.test:testArtifact:*ar:1.0.*", true, accept(node, "com.example.test:testArtifact:*ar:1.0.*"));
assertEquals("com.example.test:testArtifact:jar:1.0.*", true, accept(node, "com.example.test:testArtifact:jar:1.0.*"));
assertEquals("*.example.*:testArtifact:jar:1.0.3", true, accept(node, "*.example.*:testArtifact:jar:1.0.3"));
// wildcard as empty string
assertEquals("com.example.test*:testArtifact:jar:1.0.3", true, accept(node, "com.example.test*:testArtifact:jar:1.0.3"));
}
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();
}
Aggregations