use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method testChildNullDependency.
@Test
public void testChildNullDependency() throws IOException {
String literal = "gid:aid:ext:ver\n+- (null)";
DependencyNode root = parser.parseLiteral(literal);
assertNotNull(root.getDependency());
assertEquals(1, root.getChildren().size());
assertNull(root.getChildren().get(0).getDependency());
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method testId.
@Test
public void testId() throws IOException {
String def = "(id)gid:aid:ext:ver\n\\- ^id";
DependencyNode node = parser.parseLiteral(def);
assertNodeProperties(node, "");
assertNotNull(node.getChildren());
assertEquals(1, node.getChildren().size());
assertSame(node, node.getChildren().get(0));
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
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.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParser method addNode.
private void addNode(DependencyNode root, int level, List<NodeEntry> entries) {
NodeEntry entry = new NodeEntry();
Dependency dependency = root.getDependency();
StringBuilder defBuilder = new StringBuilder();
if (dependency == null) {
defBuilder.append("(null)");
} else {
Artifact artifact = dependency.getArtifact();
defBuilder.append(artifact.getGroupId()).append(":").append(artifact.getArtifactId()).append(":").append(artifact.getExtension()).append(":").append(artifact.getVersion());
if (dependency.getScope() != null && (!"".equals(dependency.getScope()))) {
defBuilder.append(":").append(dependency.getScope());
}
Map<String, String> properties = artifact.getProperties();
if (!(properties == null || properties.isEmpty())) {
for (Map.Entry<String, String> prop : properties.entrySet()) {
defBuilder.append(";").append(prop.getKey()).append("=").append(prop.getValue());
}
}
}
entry.setDefinition(defBuilder.toString());
entry.setLevel(level++);
entries.add(entry);
for (DependencyNode node : root.getChildren()) {
addNode(node, level, entries);
}
}
use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.
the class DependencyGraphParser method build.
private DependencyNode build(DependencyNode parent, LineContext ctx, boolean isRoot) {
ArtifactDefinition def = ctx.getDefinition();
if (!isRoot && parent == null) {
throw new IllegalArgumentException("dangling node: " + def);
} else if (ctx.getLevel() == 0 && parent != null) {
throw new IllegalArgumentException("inconsistent leveling (parent for level 0?): " + def);
}
NodeBuilder builder = new NodeBuilder();
if (def != null) {
builder.artifactId(def.getArtifactId()).groupId(def.getGroupId());
builder.ext(def.getExtension()).version(def.getVersion()).scope(def.getScope());
builder.properties(ctx.getProperties());
}
DependencyNode node = builder.build();
if (parent != null) {
parent.getChildren().add(node);
}
return node;
}
Aggregations