org.eclipse.aether.graph.DefaultDependencyNode Java Examples

The following examples show how to use org.eclipse.aether.graph.DefaultDependencyNode. 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 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 #2
Source File: DependencyNodeTest.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void conflictFromAetherDependencyNode() {
  // arrange
  org.eclipse.aether.graph.DependencyNode aetherDependencyNode = createAetherDependencyNode();
  org.eclipse.aether.artifact.Artifact winnerArtifact = createAetherArtifact();
  winnerArtifact = winnerArtifact.setVersion(winnerArtifact.getVersion() + "-alpha");
  DefaultDependencyNode winner = new DefaultDependencyNode(new Dependency(winnerArtifact, "compile"));

  aetherDependencyNode.setData(NODE_DATA_WINNER, winner);

  // act
  DependencyNode adapter = new DependencyNode(aetherDependencyNode);

  // assert
  assertEquals(OMITTED_FOR_CONFLICT, adapter.getResolution());
}
 
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: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute_shouldExcludeTestScope() throws EnforcerRuleException {
  org.apache.maven.model.Dependency dependency = new org.apache.maven.model.Dependency();
  Artifact artifact = new DefaultArtifact("junit:junit:3.8.2");
  dependency.setArtifactId(artifact.getArtifactId());
  dependency.setGroupId(artifact.getGroupId());
  dependency.setVersion(artifact.getVersion());
  dependency.setClassifier(artifact.getClassifier());
  dependency.setScope("test");

  when(mockDependencyResolutionResult.getDependencyGraph()).thenReturn(
      new DefaultDependencyNode(dummyArtifactWithFile)
  );
  when(mockProject.getDependencies())
      .thenReturn(ImmutableList.of(dependency));

  rule.execute(mockRuleHelper);
}
 
Example #7
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Turns the list of dependencies into a simple dependency tree
 */
public DependencyResult toDependencyTree(List<Dependency> deps, List<RemoteRepository> mainRepos)
        throws BootstrapMavenException {
    DependencyResult result = new DependencyResult(
            new DependencyRequest().setCollectRequest(new CollectRequest(deps, Collections.emptyList(), mainRepos)));
    DefaultDependencyNode root = new DefaultDependencyNode((Dependency) null);
    result.setRoot(root);
    GenericVersionScheme vs = new GenericVersionScheme();
    for (Dependency i : deps) {
        DefaultDependencyNode node = new DefaultDependencyNode(i);
        try {
            node.setVersionConstraint(vs.parseVersionConstraint(i.getArtifact().getVersion()));
            node.setVersion(vs.parseVersion(i.getArtifact().getVersion()));
        } catch (InvalidVersionSpecificationException e) {
            throw new RuntimeException(e);
        }
        root.getChildren().add(node);
    }
    return result;
}
 
Example #8
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 #9
Source File: ArtifactProblemTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquality() {
  UnresolvableArtifactProblem problemA = new UnresolvableArtifactProblem(ImmutableList.of(nodeA));

  Artifact artifactACopy = new DefaultArtifact("foo:a:1.0.0");
  DependencyNode nodeACopy = new DefaultDependencyNode(new Dependency(artifactACopy, "compile"));
  UnresolvableArtifactProblem problemACopy =
      new UnresolvableArtifactProblem(ImmutableList.of(nodeACopy));

  DependencyNode nodeAWithProvidedScope =
      new DefaultDependencyNode(new Dependency(artifactACopy, "provided"));
  UnresolvableArtifactProblem problemAWithProvidedScope =
      new UnresolvableArtifactProblem(ImmutableList.of(nodeAWithProvidedScope));

  UnresolvableArtifactProblem problemB = new UnresolvableArtifactProblem(ImmutableList.of(nodeB));

  new EqualsTester()
      .addEqualityGroup(problemA, problemACopy)
      .addEqualityGroup(problemB)
      .addEqualityGroup(problemAWithProvidedScope)
      .testEquals();
}
 
Example #10
Source File: UniquePathRecordingDependencyVisitorTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testVisitingUniqueNodes_twoPaths() {
  // This setup creates a dependency graph like below. There are two paths from the root to node
  // 'x': root-a-x and root-b-x. The two paths do not share intermediate nodes.
  //
  //    root
  //   /   \
  //  a     b
  //   \   /
  //     x

  DefaultDependencyNode root = new DefaultDependencyNode(new DefaultArtifact("g:r:1"));
  DefaultDependencyNode a = new DefaultDependencyNode(new DefaultArtifact("g:a:1"));
  DefaultDependencyNode b = new DefaultDependencyNode(new DefaultArtifact("g:b:1"));
  DefaultDependencyNode x = new DefaultDependencyNode(new DefaultArtifact("g:x:1"));

  root.setChildren(ImmutableList.of(a, b));
  a.setChildren(ImmutableList.of(x));
  b.setChildren(ImmutableList.of(x));

  UniquePathRecordingDependencyVisitor visitor =
      new UniquePathRecordingDependencyVisitor(
          (DependencyNode node, List<DependencyNode> parents) ->
              node.getArtifact().getArtifactId().equals("x"));

  root.accept(visitor);

  ImmutableList<List<DependencyNode>> paths = visitor.getPaths();
  Truth.assertThat(paths).hasSize(2);
  assertSame(root, paths.get(0).get(0));
  assertSame(a, paths.get(0).get(1));
  assertSame(x, paths.get(0).get(2));

  assertSame(root, paths.get(1).get(0));
  assertSame(b, paths.get(1).get(1));
  assertSame(x, paths.get(1).get(2));
}
 
Example #11
Source File: DependencyNodeUtil.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static DependencyNode createConflict(Artifact artifact, String winningVersion) {
  org.eclipse.aether.artifact.DefaultArtifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion());
  org.eclipse.aether.artifact.DefaultArtifact winnerArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), winningVersion);

  DefaultDependencyNode dependencyNode = new DefaultDependencyNode(new Dependency(aetherArtifact, artifact.getScope()));
  dependencyNode.setData(NODE_DATA_WINNER, new DefaultDependencyNode(new Dependency(winnerArtifact, "compile")));

  return new DependencyNode(dependencyNode);
}
 
Example #12
Source File: DependencyNodeTest.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void duplicateFromAetherDependencyNode() {
  // arrange
  org.eclipse.aether.graph.DependencyNode aetherDependencyNode = createAetherDependencyNode();
  DefaultDependencyNode winner = new DefaultDependencyNode(aetherDependencyNode);
  aetherDependencyNode.setData(NODE_DATA_WINNER, winner);

  // act
  DependencyNode adapter = new DependencyNode(aetherDependencyNode);

  // assert
  assertEquals(OMITTED_FOR_DUPLICATE, adapter.getResolution());
}
 
Example #13
Source File: GraphBuildingVisitorTest.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static org.eclipse.aether.graph.DependencyNode createMavenDependencyNode(String artifactId, String scope, org.eclipse.aether.graph.DependencyNode... children) {
  Dependency dependency = new Dependency(createArtifact(artifactId), scope);
  DefaultDependencyNode node = new DefaultDependencyNode(dependency);
  node.setChildren(asList(children));

  return node;
}
 
Example #14
Source File: ExampleGraphMojo.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static DependencyNode createConflict(Artifact artifact, String winningVersion) {
  org.eclipse.aether.artifact.DefaultArtifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion());
  org.eclipse.aether.artifact.DefaultArtifact winnerArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), winningVersion);

  DefaultDependencyNode dependencyNode = new DefaultDependencyNode(new Dependency(aetherArtifact, artifact.getScope()));
  dependencyNode.setData(NODE_DATA_WINNER, new DefaultDependencyNode(new Dependency(winnerArtifact, "compile")));

  return new DependencyNode(dependencyNode);
}
 
Example #15
Source File: MavenArtifactResolvingHelperTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * @see #testArtifactExtensions()
 */
@Test
public void testManagedDependenciesExtensions() throws Exception {
    // prepare mocks
    // always find an artifact in local repo
    Mockito.when(localRepositoryManager.find(Mockito.any(), Mockito.any(LocalArtifactRequest.class)))
            .thenReturn(new LocalArtifactResult(new LocalArtifactRequest())
                    .setAvailable(true).setFile(new File("test.jar")));
    // return non-null when system.collectDependencies() is called
    CollectResult collectResult = new CollectResult(new CollectRequest());
    collectResult.setRoot(new DefaultDependencyNode((Artifact) null));
    Mockito.when(system.collectDependencies(Mockito.any(), Mockito.any(CollectRequest.class)))
            .thenReturn(collectResult);


    DependencyManagement dependencyManagement = new DependencyManagement();
    dependencyManagement.addDependency(createDependency("ejb-client"));
    dependencyManagement.addDependency(createDependency("javadoc"));
    dependencyManagement.addDependency(createDependency("pom"));

    MavenArtifactResolvingHelper artifactResolverHelper =
            new MavenArtifactResolvingHelper(resolver, system, sessionMock, dependencyManagement);
    // try to resolve artifacts with various packagings
    List<ArtifactSpec> artifacts = Arrays.asList(createSpec("ejb"), createSpec("pom"), createSpec("javadoc"));
    artifactResolverHelper.resolveAll(artifacts, true, false);


    ArgumentCaptor<CollectRequest> captor = ArgumentCaptor.forClass(CollectRequest.class);
    Mockito.verify(system).collectDependencies(Mockito.any(), captor.capture());
    // verify managed dependencies extensions
    Assert.assertEquals("jar", captor.getValue().getManagedDependencies().get(0).getArtifact().getExtension()); // type ejb-client
    Assert.assertEquals("jar", captor.getValue().getManagedDependencies().get(1).getArtifact().getExtension()); // type javadoc
    Assert.assertEquals("pom", captor.getValue().getManagedDependencies().get(2).getArtifact().getExtension()); // type pom
    // verify artifact extensions
    Assert.assertEquals("jar", captor.getValue().getDependencies().get(0).getArtifact().getExtension()); // packaging ejb
    Assert.assertEquals("pom", captor.getValue().getDependencies().get(1).getArtifact().getExtension()); // packaging pom
    Assert.assertEquals("jar", captor.getValue().getDependencies().get(2).getArtifact().getExtension()); // packaging javadoc
}
 
Example #16
Source File: ExtraArtifactsHandler.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
    Artifact original = n.getArtifact();
    Artifact withExtension =
            new DefaultArtifact(original.getGroupId(),
                    original.getArtifactId(),
                    classifier.orElse(original.getClassifier()),
                    extension.orElse(original.getExtension()),
                    original.getVersion(),
                    original.getProperties(),
                    (File) null);

    DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));

    return nodeWithClassifier;
}
 
Example #17
Source File: UniquePathRecordingDependencyVisitorTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testVisitingUniqueNodes() {
  // This setup creates a dependency graph like below. There are two paths from the root to node
  // 'y'. UniquePathRecordingDependencyVisitor does not record paths that have the same
  // intermediate node.
  //
  //    root
  //   /   \
  //  a     b
  //   \   /
  //     x
  //     |
  //     y

  DefaultDependencyNode root = new DefaultDependencyNode(new DefaultArtifact("g:r:1"));
  DefaultDependencyNode a = new DefaultDependencyNode(new DefaultArtifact("g:a:1"));
  DefaultDependencyNode b = new DefaultDependencyNode(new DefaultArtifact("g:b:1"));
  DefaultDependencyNode x = new DefaultDependencyNode(new DefaultArtifact("g:x:1"));
  DefaultDependencyNode y = new DefaultDependencyNode(new DefaultArtifact("g:y:1"));

  root.setChildren(ImmutableList.of(a, b));
  a.setChildren(ImmutableList.of(x));
  b.setChildren(ImmutableList.of(x));
  x.setChildren(ImmutableList.of(y));

  UniquePathRecordingDependencyVisitor visitor =
      new UniquePathRecordingDependencyVisitor(
          (DependencyNode node, List<DependencyNode> parents) ->
              node.getArtifact().getArtifactId().equals("y"));

  root.accept(visitor);

  ImmutableList<List<DependencyNode>> paths = visitor.getPaths();
  Truth.assertThat(paths).hasSize(1);
  assertSame(root, paths.get(0).get(0));
  assertSame(a, paths.get(0).get(1));
  assertSame(x, paths.get(0).get(2));
  assertSame(y, paths.get(0).get(3));
}
 
Example #18
Source File: CycleBreakerGraphTransformerTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldVisitChildren() {
  CycleBreakerGraphTransformer transformer = new CycleBreakerGraphTransformer();
  Artifact artifact = new DefaultArtifact("g:a:1");
  DependencyNode node1 = new DefaultDependencyNode(artifact);
  DependencyNode node2 = new DefaultDependencyNode(artifact);

  assertTrue(transformer.shouldVisitChildren(node1));
  assertFalse(transformer.shouldVisitChildren(node1));
  assertTrue(transformer.shouldVisitChildren(node2));
}
 
Example #19
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testArtifactTransferError_missingArtifactNotInGraph()
    throws URISyntaxException, DependencyResolutionException, EnforcerRuleException {
  // Creating a dummy tree
  //   com.google.foo:project
  //     +- com.google.foo:child1 (provided)
  //        +- com.google.foo:child2 (optional)
  DefaultDependencyNode child2 =
      new DefaultDependencyNode(
          new Dependency(
              createArtifactWithDummyFile("com.google.foo:child2:1.0.0"), "compile", true));
  DefaultDependencyNode child1 =
      new DefaultDependencyNode(
          new Dependency(createArtifactWithDummyFile("com.google.foo:child1:1.0.0"), "provided"));
  child1.setChildren(ImmutableList.of(child2));
  DefaultDependencyNode root =
      new DefaultDependencyNode(createArtifactWithDummyFile("com.google.foo:project:1.0.0"));
  root.setChildren(ImmutableList.of(child1));

  DependencyResolutionResult resolutionResult = mock(DependencyResolutionResult.class);
  when(resolutionResult.getDependencyGraph()).thenReturn(root);
  when(resolutionResult.getResolvedDependencies())
      .thenReturn(ImmutableList.of(child1.getDependency(), child2.getDependency()));

  // The exception is caused by this node but this node does not appear in the dependency graph.
  DefaultDependencyNode missingArtifactNode =
      new DefaultDependencyNode(
          new Dependency(
              createArtifactWithDummyFile("xerces:xerces-impl:jar:2.6.2"), "compile", true));
  // xerces-impl does not exist in Maven Central
  DependencyResolutionException exception =
      createDummyResolutionException(missingArtifactNode.getArtifact(), resolutionResult);

  when(mockProjectDependenciesResolver.resolve(any())).thenThrow(exception);

  rule.execute(mockRuleHelper);
  verify(mockLog)
      .warn("xerces:xerces-impl:jar:2.6.2 was not resolved. Dependency path is unknown.");
}
 
Example #20
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 4 votes vote down vote up
/** Helper for creating a dependency node */
private DependencyNode dependencyNode(String coordinate) {
  Dependency dependency = new Dependency(new DefaultArtifact(coordinate), JavaScopes.COMPILE);
  return new DefaultDependencyNode(dependency);
}
 
Example #21
Source File: AetherGraphTraverserTest.java    From migration-tooling with Apache License 2.0 4 votes vote down vote up
/** Helper for creating a dependency node */
private DependencyNode dependencyNode(String coordinate) {
  Dependency dependency = new Dependency(new DefaultArtifact(coordinate), JavaScopes.COMPILE);
  return new DefaultDependencyNode(dependency);
}
 
Example #22
Source File: ExtraArtifactsHandlerTest.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private DependencyNode dependencyNode() {        
    DefaultArtifact artifact = new DefaultArtifact(GROUP_ID, ARTIFACT_ID, JAR, VERSION);
    return new DefaultDependencyNode(
            new Dependency(artifact, "system")
    );
}
 
Example #23
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testArtifactTransferError_acceptableMissingArtifact()
    throws URISyntaxException, DependencyResolutionException, EnforcerRuleException {
  // Creating a dummy tree
  //   com.google.foo:project
  //     +- com.google.foo:child1 (provided)
  //        +- com.google.foo:child2 (optional)
  //           +- xerces:xerces-impl:jar:2.6.2 (optional)
  DefaultDependencyNode missingArtifactNode =
      new DefaultDependencyNode(
          new Dependency(
              createArtifactWithDummyFile("xerces:xerces-impl:jar:2.6.2"), "compile", true));
  DefaultDependencyNode child2 =
      new DefaultDependencyNode(
          new Dependency(
              createArtifactWithDummyFile("com.google.foo:child2:1.0.0"), "compile", true));
  child2.setChildren(ImmutableList.of(missingArtifactNode));
  DefaultDependencyNode child1 =
      new DefaultDependencyNode(
          new Dependency(createArtifactWithDummyFile("com.google.foo:child1:1.0.0"), "provided"));
  child1.setChildren(ImmutableList.of(child2));
  DefaultDependencyNode root =
      new DefaultDependencyNode(createArtifactWithDummyFile("com.google.foo:project:1.0.0"));
  root.setChildren(ImmutableList.of(child1));

  DependencyResolutionResult resolutionResult = mock(DependencyResolutionResult.class);
  when(resolutionResult.getDependencyGraph()).thenReturn(root);
  when(resolutionResult.getResolvedDependencies())
      .thenReturn(
          ImmutableList.of(
              child1.getDependency(),
              child2.getDependency(),
              missingArtifactNode.getDependency()));

  // xerces-impl does not exist in Maven Central
  DependencyResolutionException exception =
      createDummyResolutionException(missingArtifactNode.getArtifact(), resolutionResult);

  when(mockProjectDependenciesResolver.resolve(any())).thenThrow(exception);

  // Should not throw DependencyResolutionException, because the missing xerces-impl is under both
  // provided and optional dependencies.
  rule.execute(mockRuleHelper);
}
 
Example #24
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);
}
 
Example #25
Source File: DependencyNodeTest.java    From depgraph-maven-plugin with Apache License 2.0 4 votes vote down vote up
private org.eclipse.aether.graph.DependencyNode createAetherDependencyNode() {
  Dependency dependency = new Dependency(createAetherArtifact(), "compile");
  return new DefaultDependencyNode(dependency);
}
 
Example #26
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 #27
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 3 votes vote down vote up
/**
 * Finds the full compile time, transitive dependency graph including duplicates, conflicting
 * versions, and provided and optional dependencies. In the event of I/O errors, missing
 * artifacts, and other problems, it can return an incomplete graph. Each node's dependencies are
 * resolved recursively. The scope of a dependency does not affect the scope of its children's
 * dependencies. Provided and optional dependencies are not treated differently than any other
 * dependency.
 *
 * @param artifacts Maven artifacts whose dependencies to retrieve
 * @return dependency graph representing the tree of Maven artifacts
 */
public DependencyGraph buildFullDependencyGraph(List<Artifact> artifacts) {
  ImmutableList<DependencyNode> dependencyNodes =
      artifacts.stream().map(DefaultDependencyNode::new).collect(toImmutableList());
  DefaultRepositorySystemSession session = RepositoryUtility.newSessionForFullDependency(system);
  return buildDependencyGraph(dependencyNodes, session);
}
 
Example #28
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 2 votes vote down vote up
/**
 * Builds the transitive dependency graph as seen by Maven. It does not include duplicates and
 * conflicting versions. That is, this resolves conflicting versions by picking the first version
 * seen. This is how Maven normally operates. It does not contain provided-scope dependencies
 * of transitive dependencies. It does not contain optional dependencies of transitive
 * dependencies. In the event of I/O errors, missing artifacts, and other problems, it can
 * return an incomplete graph.
 */
public DependencyGraph buildMavenDependencyGraph(Dependency dependency) {
  ImmutableList<DependencyNode> roots = ImmutableList.of(new DefaultDependencyNode(dependency));
  return buildDependencyGraph(roots, RepositoryUtility.newSession(system));
}
 
Example #29
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 2 votes vote down vote up
/**
 * Finds the full compile time, transitive dependency graph including conflicting versions and
 * provided dependencies. This includes direct optional dependencies of the root node but not
 * optional dependencies of transitive dependencies.
 *
 * <p>In the event of I/O errors, missing artifacts, and other problems, it can return an
 * incomplete graph. Each node's dependencies are resolved recursively. The scope of a dependency
 * does not affect the scope of its children's dependencies. Provided and optional dependencies
 * are not treated differently than any other dependency.
 *
 * @param dependency the root
 * @return the graph as built by Maven before dependency mediation
 */
DependencyGraph buildVerboseDependencyGraph(Dependency dependency) {
  DefaultRepositorySystemSession session = RepositoryUtility.newSessionForVerboseDependency(system);
  ImmutableList<DependencyNode> roots = ImmutableList.of(new DefaultDependencyNode(dependency));
  return buildDependencyGraph(roots, session);
}