Search in sources :

Example 16 with DependencyPath

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

the class DependencyConflictTest method testToString_versionConflict_abstractMethod.

@Test
public void testToString_versionConflict_abstractMethod() {
    MethodSymbol methodSymbol = new MethodSymbol("foo.B", "equals", "(Lfoo/Object;)Z", false);
    AbstractMethodProblem abstractMethodProblem = new AbstractMethodProblem(new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "foo.A"), methodSymbol, new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "foo.B"));
    Artifact root = new DefaultArtifact("a:b:1");
    Artifact foo = new DefaultArtifact("com.google:foo:1");
    Artifact bar = new DefaultArtifact("com.google:foo:2");
    DependencyPath selectedPath = new DependencyPath(root).append(new Dependency(foo, "compile", false));
    DependencyPath unselectedPath = new DependencyPath(root).append(new Dependency(bar, "compile", false));
    DependencyConflict dependencyConflict = new DependencyConflict(abstractMethodProblem, selectedPath, unselectedPath);
    assertEquals("Dependency conflict: com.google:foo:1 defines " + "incompatible version of foo.B" + " but com.google:foo:2 defines compatible one.\n" + "  selected: a:b:jar:1 / com.google:foo:1 (compile)\n" + "  unselected: a:b:jar:1 / com.google:foo:2 (compile)", dependencyConflict.toString());
}
Also used : 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 17 with DependencyPath

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

the class DependencyConflictTest method testToString_versionConflict_missingSymbol.

@Test
public void testToString_versionConflict_missingSymbol() {
    MethodSymbol methodSymbol = new MethodSymbol("foo.B", "equals", "(Lfoo/Object;)Z", false);
    SymbolNotFoundProblem symbolNotFound = new SymbolNotFoundProblem(new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "foo.A"), new ClassFile(new ClassPathEntry(Paths.get("foo", "bar.jar")), "foo.B"), methodSymbol);
    Artifact root = new DefaultArtifact("a:b:1");
    Artifact foo = new DefaultArtifact("com.google:foo:1");
    Artifact bar = new DefaultArtifact("com.google:foo:2");
    DependencyPath selectedPath = new DependencyPath(root).append(new Dependency(foo, "compile", false));
    DependencyPath unselectedPath = new DependencyPath(root).append(new Dependency(bar, "compile", false));
    DependencyConflict dependencyConflict = new DependencyConflict(symbolNotFound, selectedPath, unselectedPath);
    assertEquals("Dependency conflict: com.google:foo:1 does not " + "define " + methodSymbol + " but com.google:foo:2 defines it.\n" + "  selected: a:b:jar:1 / com.google:foo:1 (compile)\n" + "  unselected: a:b:jar:1 / com.google:foo:2 (compile)", dependencyConflict.toString());
}
Also used : 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 18 with DependencyPath

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

the class LinkageCheckTask method createDependencyGraph.

private DependencyGraph createDependencyGraph(ResolvedConfiguration configuration) {
    // Why this method is not part of the DependencyGraph? Because the dependencies module
    // which the DependencyGraph belongs to is a Maven project, and Gradle does not provide good
    // Maven artifacts to develop code with Gradle-related classes.
    // For the details, see https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/1556
    // The root Gradle project is not available in `configuration`.
    DependencyGraph graph = new DependencyGraph(null);
    ArrayDeque<PathToNode<ResolvedDependency>> queue = new ArrayDeque<>();
    DependencyPath root = new DependencyPath(null);
    for (ResolvedDependency firstLevelDependency : configuration.getFirstLevelModuleDependencies()) {
        queue.add(new PathToNode<>(firstLevelDependency, root));
    }
    Set<ResolvedDependency> visited = new HashSet<>();
    while (!queue.isEmpty()) {
        PathToNode<ResolvedDependency> item = queue.poll();
        ResolvedDependency node = item.getNode();
        // Never null
        DependencyPath parentPath = item.getParentPath();
        // If there are multiple artifacts (with different classifiers) in this node, then the path is
        // the same, because these artifacts share the same dependencies with the same pom.xml.
        DependencyPath path = null;
        Set<ResolvedArtifact> moduleArtifacts = node.getModuleArtifacts();
        if (moduleArtifacts.isEmpty()) {
            // Unlike Maven's dependency tree, Gradle's dependency tree may include nodes that do not
            // have associated artifacts. BOMs, such as com.fasterxml.jackson:jackson-bom:2.12.3, fall
            // in this category. For the detailed observation, see the issue below:
            // https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/2174#issuecomment-897174898
            getLogger().warn("The dependency node " + node.getName() + " does not have any artifact. Skipping.");
            path = parentPath.append(new Dependency(artifactWithPomFrom(node), "compile"));
        } else {
            // For artifacts with classifiers, there can be multiple resolved artifacts for one node
            for (ResolvedArtifact artifact : moduleArtifacts) {
                path = parentPath.append(dependencyFrom(node, artifact));
                graph.addPath(path);
            }
        }
        for (ResolvedDependency child : node.getChildren()) {
            if (visited.add(child)) {
                queue.add(new PathToNode<>(child, path));
            }
        }
    }
    return graph;
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) PathToNode(com.google.cloud.tools.opensource.dependencies.PathToNode) ResolvedDependency(org.gradle.api.artifacts.ResolvedDependency) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) ResolvedDependency(org.gradle.api.artifacts.ResolvedDependency) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 19 with DependencyPath

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

the class LinkageMonitorTest method generateMessageForNewError.

@Test
public void generateMessageForNewError() {
    Set<LinkageProblem> baselineProblems = ImmutableSet.of(classNotFoundProblem);
    ImmutableSet<LinkageProblem> snapshotProblems = ImmutableSet.of(// This is in baseline. It should not be printed
    classNotFoundProblem, methodNotFoundProblemFromA, methodNotFoundProblemFromB);
    DependencyPath pathToA = new DependencyPath(new DefaultArtifact("foo:bar:1.0.0")).append(new org.eclipse.aether.graph.Dependency(new DefaultArtifact("foo:a:1.2.3"), "compile", true));
    DependencyPath pathToB = new DependencyPath(new DefaultArtifact("foo:b:1.0.0"));
    String message = LinkageMonitor.messageForNewErrors(snapshotProblems, baselineProblems, new ClassPathResult(AnnotatedClassPath.fromMultimap(ImmutableListMultimap.of(jarA, pathToA, jarB, pathToB)), ImmutableList.of()));
    assertEquals("Newly introduced problem:\n" + "(foo:b:1.0.0) io.grpc.protobuf.ProtoUtils's method" + " \"io.grpc.MethodDescriptor$Marshaller marshaller(com.google.protobuf.Message)\"" + " is not found\n" + "  referenced from com.abc.AAA (foo:a:1.2.3)\n" + "  referenced from com.abc.BBB (foo:a:1.2.3)\n" + "\n" + "foo:b:1.0.0 is at:\n" + "  foo:b:jar:1.0.0\n" + "foo:a:1.2.3 is at:\n" + "  foo:bar:jar:1.0.0 / foo:a:1.2.3 (compile, optional)\n", message);
}
Also used : LinkageProblem(com.google.cloud.tools.opensource.classpath.LinkageProblem) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 20 with DependencyPath

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

the class DashboardMain method commonVersionlessArtifacts.

private static ImmutableList<String> commonVersionlessArtifacts(List<DependencyPath> dependencyPaths) {
    ImmutableList<String> initialVersionlessCoordinates = dependencyPaths.get(0).getArtifactKeys();
    // LinkedHashSet remembers insertion order
    LinkedHashSet<String> versionlessCoordinatesIntersection = Sets.newLinkedHashSet(initialVersionlessCoordinates);
    for (DependencyPath dependencyPath : dependencyPaths) {
        // List of versionless coordinates ("groupId:artifactId")
        ImmutableList<String> versionlessCoordinatesInPath = dependencyPath.getArtifactKeys();
        // intersection of elements in DependencyPaths
        versionlessCoordinatesIntersection.retainAll(versionlessCoordinatesInPath);
    }
    return ImmutableList.copyOf(versionlessCoordinatesIntersection);
}
Also used : DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath)

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