Java Code Examples for org.eclipse.aether.graph.DependencyNode#setChildren()

The following examples show how to use org.eclipse.aether.graph.DependencyNode#setChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicTree() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), null)
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test" )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/BasicTree.txt");
    String expected = FileUtils.readFileToString( file );

    Assert.assertEquals(expected, actual);
}
 
Example 2
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSmallGraphWithCycle() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "")
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test" )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );

    root.setChildren( Arrays.asList( left, right ) );
    left.setChildren( Arrays.asList( root ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/BasicCycle.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example 3
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithOptional() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "")
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/OptionalDependency.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example 4
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithScopeConflict() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "compile" )
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "test" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/ScopeConflict.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example 5
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithVersionConflict() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "compile" )
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "2.0.0" ), "test" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/VersionConflict.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example 6
Source File: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void replaceWith(DependencyNode originalNode, DependencyNode newNode)
        throws BootstrapDependencyProcessingException {
    List<DependencyNode> children = newNode.getChildren();
    if (children.isEmpty()) {
        throw new BootstrapDependencyProcessingException(
                "No dependencies collected for Quarkus extension deployment artifact " + newNode.getArtifact()
                        + " while at least the corresponding runtime artifact " + originalNode.getArtifact()
                        + " is expected");
    }
    log.debugf("Injecting deployment dependency %s", newNode);

    originalNode.setData(QUARKUS_RUNTIME_ARTIFACT, originalNode.getArtifact());
    originalNode.setArtifact(newNode.getArtifact());
    originalNode.getDependency().setArtifact(newNode.getArtifact());
    originalNode.setChildren(children);
    injectedDeps = true;
}
 
Example 7
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that the generated rules preserve dependency relations
 * (i.e. parent, child sets). This will be used to generate the deps field.
 */
@Test
public void testBasicParentChildRelations() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode parentNode = dependencyNode("a:a:1");
  DependencyNode childNode = dependencyNode("a:2:1");

  sentinel.setChildren(ImmutableList.of(parentNode));
  parentNode.setChildren(ImmutableList.of(childNode));

  MavenJarRule parent = new MavenJarRule(parentNode);
  MavenJarRule child = new MavenJarRule(childNode);
  addDependency(parent, child);

  Set<MavenJarRule> actual = GraphSerializer.generateBuildRules(sentinel);

  assertRuleSetContainsExactly(actual, parent, child);
}
 
Example 8
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleDirectDependencies() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode nodeA = dependencyNode("a:a:1");
  DependencyNode nodeA1 = dependencyNode("a:1:1");
  DependencyNode nodeB = dependencyNode("b:b:1");
  DependencyNode nodeC = dependencyNode("c:c:1");

  sentinel.setChildren(ImmutableList.of(nodeA, nodeB, nodeC));
  nodeA.setChildren(ImmutableList.of(nodeA1));

  Set<MavenJarRule> rules = GraphSerializer.generateBuildRules(sentinel);

  MavenJarRule ruleA = new MavenJarRule(nodeA);
  MavenJarRule ruleA1 = new MavenJarRule(nodeA1);
  MavenJarRule ruleB = new MavenJarRule(nodeB);
  MavenJarRule ruleC = new MavenJarRule(nodeC);
  addDependency(ruleA, ruleA1);

  assertRuleSetContainsExactly(rules, ruleA, ruleA1, ruleB, ruleC);
}
 
Example 9
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedChild() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode nodeA = dependencyNode("a:a:1");
  DependencyNode nodeB = dependencyNode("b:b:1");
  DependencyNode child = dependencyNode("child:child:1");

  sentinel.setChildren(ImmutableList.of(nodeA, nodeB));
  nodeA.setChildren(ImmutableList.of(child));
  nodeB.setChildren(ImmutableList.of(child));

  Set<MavenJarRule> rules = GraphSerializer.generateBuildRules(sentinel);

  MavenJarRule ruleA = new MavenJarRule(nodeA);
  MavenJarRule ruleB = new MavenJarRule(nodeB);
  MavenJarRule childRule = new MavenJarRule(child);
  addDependency(ruleA, childRule);
  addDependency(ruleB, childRule);

  assertRuleSetContainsExactly(rules, ruleA, ruleB, childRule);

}
 
Example 10
Source File: AetherGraphTraverserTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicGraphConstruction() {
  DependencyNode root = dependencyNode("root:root:1");
  DependencyNode depA = dependencyNode("a:a:1");
  DependencyNode depB = dependencyNode("b:b:1");

  root.setChildren(ImmutableList.of(depA, depB));

  MavenJarRule rootRule = new MavenJarRule(root);
  MavenJarRule aRule = new MavenJarRule(depA);
  MavenJarRule bRule = new MavenJarRule(depB);

  MutableGraph<MavenJarRule> expected = newGraph();
  addEdge(expected, rootRule, aRule);
  addEdge(expected, rootRule, bRule);

  // Construct the graph
  MutableGraph<MavenJarRule> actual = newGraph();
  AetherGraphTraverser visitor = new AetherGraphTraverser(actual);
  root.accept(visitor);

  assertThatGraphsEqual(actual, expected);
}
 
Example 11
Source File: CycleBreakerGraphTransformer.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static void removeChildFromParent(DependencyNode child, DependencyNode parent) {
  ImmutableList<DependencyNode> children =
      parent.getChildren().stream()
          .filter(node -> node != child)
          .collect(ImmutableList.toImmutableList());
  parent.setChildren(children);
}
 
Example 12
Source File: AetherGraphTraverserTest.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that when the dependency visitor is accepted by multiple
 * nodes, the constructed graph contains nodes and edges from all visits.
 */
@Test
public void testAccumulation() {
  DependencyNode rootNodeA = dependencyNode("a:a1:1");
  DependencyNode childNodeA = dependencyNode("a:a2:1");
  DependencyNode rootNodeB = dependencyNode("b:b1:1");
  DependencyNode childNodeB = dependencyNode("b:b2:1");

  rootNodeA.setChildren(ImmutableList.of(childNodeA));
  rootNodeB.setChildren(ImmutableList.of(childNodeB));

  MavenJarRule rootRuleA = new MavenJarRule(rootNodeA);
  MavenJarRule childRuleA = new MavenJarRule(childNodeA);
  MavenJarRule rootRuleB = new MavenJarRule(rootNodeB);
  MavenJarRule childRuleB = new MavenJarRule(childNodeB);

  MutableGraph<MavenJarRule> expected = newGraph();
  addEdge(expected, rootRuleA, childRuleA);
  addEdge(expected, rootRuleB, childRuleB);

  // Construct the graph
  MutableGraph<MavenJarRule> actual = newGraph();
  AetherGraphTraverser visitor = new AetherGraphTraverser(actual);
  rootNodeA.accept(visitor);
  rootNodeB.accept(visitor);

  assertThatGraphsEqual(actual, expected);
}
 
Example 13
Source File: AetherGraphTraverserTest.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
/**
 * Tests behavior when there is a duplicate dependency node within the graph, meaning
 * two nodes with the same maven coordinate. The generated graph should not contain
 * multiple instances of that node.
 */
@Test
public void testDuplicateChildren() {
  DependencyNode rootNodeA = dependencyNode("a:a:1");
  DependencyNode rootNodeB = dependencyNode("b:b:1");
  DependencyNode childNode = dependencyNode("c:c:1");
  DependencyNode childNodeDuplicate = dependencyNode("c:c:1");

  rootNodeA.setChildren(ImmutableList.of(childNode));
  rootNodeB.setChildren(ImmutableList.of(childNode));
  rootNodeA.setChildren(ImmutableList.of(childNodeDuplicate));
  rootNodeB.setChildren(ImmutableList.of(childNodeDuplicate));

  MavenJarRule rootRuleA = new MavenJarRule(rootNodeA);
  MavenJarRule childRule = new MavenJarRule(childNode);
  MavenJarRule rootRuleB = new MavenJarRule(rootNodeB);

  MutableGraph<MavenJarRule> expected = newGraph();
  addEdge(expected, rootRuleA, childRule);
  addEdge(expected, rootRuleB, childRule);

  // Construct the graph
  MutableGraph<MavenJarRule> actual = newGraph();
  AetherGraphTraverser visitor = new AetherGraphTraverser(actual);
  rootNodeA.accept(visitor);
  rootNodeB.accept(visitor);

  assertThatGraphsEqual(actual, expected);
}
 
Example 14
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testLargeTree() throws IOException
{
    // Construct nodes for tree l1 = level 1 with the root being l0
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), null )
    );
    DependencyNode l1left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test" )
    );
    DependencyNode l1right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );
    DependencyNode l2left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.maven", "a4", "jar", "2.2.1" ), "system" )
    );
    DependencyNode l2middle = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "a5", "zip", "0" ), "import" )
    );
    DependencyNode l2right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.xyz", "a9", "xml", "1.2" ), "runtime" )
    );
    DependencyNode l3 = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.xyz", "a6", "xml", "1.2.1" ), "test" )
    );
    DependencyNode l4 = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.example", "a7", "jar", "2.2.2" ), "provided" )
    );
    DependencyNode l5right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.comm", "a7", "jar", "1" ), "compile" )
    );
    DependencyNode l5left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.comm", "a7", "jar", "1" ), "compile" )
    );
    DependencyNode l6left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.example", "a8", "xml", "2.1" ), "test" )
    );

    // Set Node Relationships
    l5left.setChildren( Arrays.asList( l6left ) );
    l4.setChildren( Arrays.asList( l5left, l5right ) );
    l3.setChildren( Arrays.asList( l4 ) );
    l2middle.setChildren( Arrays.asList( l3 ) );

    l1left.setChildren( Arrays.asList( l2left, l2middle ) );
    l1right.setChildren( Arrays.asList( l2right ) );

    root.setChildren( Arrays.asList( l1left, l1right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/LargeTree.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example 15
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testLargeGraphWithCycles() throws IOException
{
    // Construct nodes for tree l1 = level 1 with the root being l0
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), null )
    );
    DependencyNode l1left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test" )
    );
    DependencyNode l1right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );
    DependencyNode l2left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.maven", "a4", "jar", "2.2.1" ), "system" )
    );
    DependencyNode l2middle = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "a5", "zip", "0" ), "import" )
    );
    DependencyNode l2right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.xyz", "a9", "xml", "1.2" ), "runtime" )
    );
    DependencyNode l3 = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.xyz", "a6", "xml", "1.2.1" ), "test" )
    );
    DependencyNode l4 = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.example", "a7", "jar", "2.2.2" ), "provided" )
    );
    DependencyNode l5right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.comm", "a7", "jar", "1" ), "compile" )
    );
    DependencyNode l5left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.comm", "a7", "jar", "1" ), "compile" )
    );
    DependencyNode l6left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.example", "a8", "xml", "2.1" ), "test" )
    );

    // Set Node Relationships
    l5left.setChildren( Arrays.asList( l6left ) );
    l4.setChildren( Arrays.asList( l5left, l5right ) );
    l3.setChildren( Arrays.asList( l4 ) );
    l2middle.setChildren( Arrays.asList( l3 ) );

    l1left.setChildren( Arrays.asList( l2left, l2middle ) );
    l1right.setChildren( Arrays.asList( l2right ) );

    root.setChildren( Arrays.asList( l1left, l1right ) );

    // Introduce cycles
    l5left.setChildren( Arrays.asList( l2left, l1right, l3 ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/LargeGraphWithCycles.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}