Search in sources :

Example 6 with DependencyPath

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

the class LinkageProblemCauseAnnotatorTest method testAnnotate_googleApiClientAndGrpcConflict.

@Test
public void testAnnotate_googleApiClientAndGrpcConflict() throws IOException, RepositoryException {
    // The google-api-client and grpc-core have dependency conflict on Guava's Verify.verify
    // method.
    ClassPathBuilder builder = new ClassPathBuilder();
    ClassPathResult classPathResult = builder.resolve(ImmutableList.of(new DefaultArtifact("com.google.api-client:google-api-client:1.27.0"), new DefaultArtifact("io.grpc:grpc-core:1.17.1")), false, DependencyMediation.MAVEN);
    LinkageChecker linkageChecker = LinkageChecker.create(classPathResult.getClassPath());
    ImmutableSet<LinkageProblem> linkageProblems = linkageChecker.findLinkageProblems();
    Optional<LinkageProblem> foundProblem = linkageProblems.stream().filter(problem -> problem instanceof SymbolNotFoundProblem).findFirst();
    SymbolNotFoundProblem problem = (SymbolNotFoundProblem) foundProblem.get();
    assertEquals("verify", ((MethodSymbol) problem.getSymbol()).getName());
    LinkageProblemCauseAnnotator.annotate(classPathBuilder, classPathResult, ImmutableSet.of(problem));
    LinkageProblemCause cause = problem.getCause();
    assertTrue(cause instanceof DependencyConflict);
    DependencyPath pathToSelectedArtifact = ((DependencyConflict) cause).getPathToSelectedArtifact();
    Artifact selectedLeaf = pathToSelectedArtifact.getLeaf();
    assertEquals("guava", selectedLeaf.getArtifactId());
    assertEquals("20.0", selectedLeaf.getVersion());
    Artifact firstElementInSelected = pathToSelectedArtifact.get(1);
    assertEquals("google-api-client", firstElementInSelected.getArtifactId());
    DependencyPath pathToUnselectedArtifact = ((DependencyConflict) cause).getPathToArtifactThruSource();
    Artifact unselectedLeaf = pathToUnselectedArtifact.getLeaf();
    assertEquals("guava", unselectedLeaf.getArtifactId());
    assertEquals("26.0-android", unselectedLeaf.getVersion());
    Artifact firstElementInUnselected = pathToUnselectedArtifact.get(1);
    assertEquals("grpc-core", firstElementInUnselected.getArtifactId());
}
Also used : Artifacts(com.google.cloud.tools.opensource.dependencies.Artifacts) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Assert.assertTrue(org.junit.Assert.assertTrue) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) Test(org.junit.Test) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ImmutableList(com.google.common.collect.ImmutableList) RepositoryException(org.eclipse.aether.RepositoryException) Optional(java.util.Optional) RepositoryUtility(com.google.cloud.tools.opensource.dependencies.RepositoryUtility) DependencyGraphBuilder(com.google.cloud.tools.opensource.dependencies.DependencyGraphBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 7 with DependencyPath

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

the class LinkageProblemCauseTest method testEquality.

@Test
public void testEquality() {
    Artifact root = new DefaultArtifact("a:b:1");
    Artifact foo = new DefaultArtifact("com.google:foo:1");
    Artifact bar = new DefaultArtifact("com.google:bar:1");
    MethodSymbol methodSymbol = new MethodSymbol("java.lang.Object", "equals", "(Ljava/lang/Object;)Z", false);
    ClassSymbol classSymbol = new ClassSymbol("java.lang.Object$XYZ");
    SymbolNotFoundProblem methodSymbolNotFound = new SymbolNotFoundProblem(new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "java.lang.A"), new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "java.lang.Object"), methodSymbol);
    SymbolNotFoundProblem classSymbolNotFound = new SymbolNotFoundProblem(new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "java.lang.A"), new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "java.lang.Object"), classSymbol);
    DependencyPath path1 = new DependencyPath(root).append(new Dependency(foo, "compile", false));
    DependencyPath path2 = new DependencyPath(root).append(new Dependency(bar, "compile", false));
    new EqualsTester().addEqualityGroup(new DependencyConflict(methodSymbolNotFound, path1, path2), new DependencyConflict(methodSymbolNotFound, path1, path2)).addEqualityGroup(new DependencyConflict(methodSymbolNotFound, path1, path1)).addEqualityGroup(new DependencyConflict(methodSymbolNotFound, path2, path2)).addEqualityGroup(new DependencyConflict(classSymbolNotFound, path2, path2)).addEqualityGroup(new MissingDependency(path1), new MissingDependency(path1)).addEqualityGroup(new ExcludedDependency(path1, foo), new ExcludedDependency(path1, foo)).addEqualityGroup(new ExcludedDependency(path1, bar)).addEqualityGroup(new MissingDependency(path2)).addEqualityGroup(UnknownCause.getInstance()).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 8 with DependencyPath

use of com.google.cloud.tools.opensource.dependencies.DependencyPath 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 DependencyPath

use of com.google.cloud.tools.opensource.dependencies.DependencyPath 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 DependencyPath

use of com.google.cloud.tools.opensource.dependencies.DependencyPath 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

DependencyPath (com.google.cloud.tools.opensource.dependencies.DependencyPath)27 Artifact (org.eclipse.aether.artifact.Artifact)17 Dependency (org.eclipse.aether.graph.Dependency)15 Test (org.junit.Test)15 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)12 DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)9 ImmutableList (com.google.common.collect.ImmutableList)5 ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)4 ClassPathResult (com.google.cloud.tools.opensource.classpath.ClassPathResult)4 AnnotatedClassPath (com.google.cloud.tools.opensource.classpath.AnnotatedClassPath)2 Artifacts (com.google.cloud.tools.opensource.dependencies.Artifacts)2 DependencyGraphBuilder (com.google.cloud.tools.opensource.dependencies.DependencyGraphBuilder)2 RepositoryUtility (com.google.cloud.tools.opensource.dependencies.RepositoryUtility)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 RepositoryException (org.eclipse.aether.RepositoryException)2