Search in sources :

Example 6 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class GradleDependencyMediationTest method testMediation_oneArtifactForEachVersionlessCoordinates.

@Test
public void testMediation_oneArtifactForEachVersionlessCoordinates() throws InvalidVersionSpecificationException {
    DependencyGraph graph = new DependencyGraph(null);
    // The old version comes first in the graph.list
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA1, "compile")));
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA2, "compile")));
    // The duplicate shouldn't appear in the class path
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactB1, "compile")));
    AnnotatedClassPath result = mediation.mediate(graph);
    Truth.assertThat(result.getClassPath()).comparingElementsUsing(CLASS_PATH_ENTRY_TO_ARTIFACT).containsExactly(artifactA2, artifactB1).inOrder();
}
Also used : DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) Test(org.junit.Test)

Example 7 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckerTest method resolveTransitiveDependencyPaths.

/**
 * Returns the class path resolved for the transitive dependencies of {@code coordinates}.
 */
private ImmutableList<ClassPathEntry> resolveTransitiveDependencyPaths(String coordinates) throws IOException {
    DependencyGraph dependencies = dependencyGraphBuilder.buildMavenDependencyGraph(new Dependency(new DefaultArtifact(coordinates), "compile"));
    ImmutableList.Builder<ClassPathEntry> builder = ImmutableList.builder();
    for (DependencyPath path : dependencies.list()) {
        builder.add(new ClassPathEntry(path.getLeaf()));
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 8 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class MavenDependencyMediationTest method testMediation_noDuplicates.

@Test
public void testMediation_noDuplicates() throws InvalidVersionSpecificationException {
    DependencyGraph graph = new DependencyGraph(null);
    // The old version comes first in the graph.list
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA1, "compile")));
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA2, "compile")));
    // The duplicate shouldn't appear in the class path
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA1, "compile")));
    AnnotatedClassPath result = mediation.mediate(graph);
    Truth.assertThat(result.getClassPath()).hasSize(1);
    Truth.assertThat(result.getClassPath()).comparingElementsUsing(CLASS_PATH_ENTRY_TO_ARTIFACT).containsExactly(artifactA1);
}
Also used : DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) Test(org.junit.Test)

Example 9 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class MavenDependencyMediationTest method testMediation_oneArtifactForEachVersionlessCoordinates.

@Test
public void testMediation_oneArtifactForEachVersionlessCoordinates() throws InvalidVersionSpecificationException {
    DependencyGraph graph = new DependencyGraph(null);
    // The old version comes first in the graph.list
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA1, "compile")));
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactA2, "compile")));
    // The duplicate shouldn't appear in the class path
    graph.addPath(new DependencyPath(null).append(new Dependency(artifactB1, "compile")));
    AnnotatedClassPath result = mediation.mediate(graph);
    Truth.assertThat(result.getClassPath()).comparingElementsUsing(CLASS_PATH_ENTRY_TO_ARTIFACT).containsExactly(artifactA1, artifactB1).inOrder();
}
Also used : DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) Test(org.junit.Test)

Example 10 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckTask method createClassPathResult.

private ClassPathResult createClassPathResult(ResolvedConfiguration configuration) {
    DependencyGraph dependencyGraph = createDependencyGraph(configuration);
    AnnotatedClassPath annotatedClassPath = new AnnotatedClassPath();
    for (DependencyPath path : dependencyGraph.list()) {
        Artifact artifact = path.getLeaf();
        annotatedClassPath.put(new ClassPathEntry(artifact), path);
    }
    return new ClassPathResult(annotatedClassPath, ImmutableList.of());
}
Also used : AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry)

Aggregations

DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)18 Dependency (org.eclipse.aether.graph.Dependency)12 DependencyPath (com.google.cloud.tools.opensource.dependencies.DependencyPath)9 Artifact (org.eclipse.aether.artifact.Artifact)9 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 Test (org.junit.Test)8 AnnotatedClassPath (com.google.cloud.tools.opensource.classpath.AnnotatedClassPath)4 ClassPathResult (com.google.cloud.tools.opensource.classpath.ClassPathResult)4 LinkedHashMap (java.util.LinkedHashMap)4 ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)2 Bom (com.google.cloud.tools.opensource.dependencies.Bom)2 Update (com.google.cloud.tools.opensource.dependencies.Update)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Configuration (freemarker.template.Configuration)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)2