Search in sources :

Example 11 with DependencyPath

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

the class MissingDependencyTest method testToString_optional.

@Test
public void testToString_optional() {
    Artifact root = new DefaultArtifact("a:b:1");
    Artifact foo = new DefaultArtifact("com.google:foo:1");
    Artifact bar = new DefaultArtifact("com.google:bar:1");
    DependencyPath pathRootFooBar = new DependencyPath(root).append(new Dependency(foo, "test", false)).append(new Dependency(bar, "compile", true));
    MissingDependency missingDependency = new MissingDependency(pathRootFooBar);
    assertEquals("The valid symbol is in com.google:bar:jar:1 at a:b:jar:1 / " + "com.google:foo:1 (test) / com.google:bar:1 (compile, optional) " + "but it was not selected because the path contains an optional dependency", missingDependency.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 12 with DependencyPath

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

the class MissingDependencyTest method testToString_provided.

@Test
public void testToString_provided() {
    Artifact root = new DefaultArtifact("a:b:1");
    Artifact foo = new DefaultArtifact("com.google:foo:1");
    Artifact bar = new DefaultArtifact("com.google:bar:1");
    DependencyPath pathRootFooBar = new DependencyPath(root).append(new Dependency(foo, "test", false)).append(new Dependency(bar, "provided", false));
    MissingDependency missingDependency = new MissingDependency(pathRootFooBar);
    assertEquals("The valid symbol is in com.google:bar:jar:1 at a:b:jar:1 / " + "com.google:foo:1 (test) / com.google:bar:1 (provided) " + "but it was not selected because the path contains a provided-scope dependency", missingDependency.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 13 with DependencyPath

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

the class AbstractMethodProblem method describe.

@Override
String describe(DependencyConflict conflict) {
    DependencyPath pathToSelectedArtifact = conflict.getPathToSelectedArtifact();
    Artifact selected = pathToSelectedArtifact.getLeaf();
    String selectedCoordinates = Artifacts.toCoordinates(selected);
    DependencyPath pathToArtifactThruSource = conflict.getPathToArtifactThruSource();
    Artifact unselected = pathToArtifactThruSource.getLeaf();
    String unselectedCoordinates = Artifacts.toCoordinates(unselected);
    ClassFile supertype = getTargetClass();
    return "Dependency conflict: " + selectedCoordinates + " defines incompatible version of " + supertype.getBinaryName() + " but " + unselectedCoordinates + " defines compatible one.\n" + "  selected: " + pathToSelectedArtifact + "\n  unselected: " + pathToArtifactThruSource;
}
Also used : DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Artifact(org.eclipse.aether.artifact.Artifact)

Example 14 with DependencyPath

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

the class LinkageProblem method describe.

String describe(DependencyConflict conflict) {
    DependencyPath pathToSelectedArtifact = conflict.getPathToSelectedArtifact();
    Artifact selected = pathToSelectedArtifact.getLeaf();
    String selectedCoordinates = Artifacts.toCoordinates(selected);
    DependencyPath pathToArtifactThruSource = conflict.getPathToArtifactThruSource();
    Artifact unselected = pathToArtifactThruSource.getLeaf();
    String unselectedCoordinates = Artifacts.toCoordinates(unselected);
    return "Dependency conflict: " + selectedCoordinates + " does not define " + getSymbol() + " but " + unselectedCoordinates + " defines it.\n" + "  selected: " + pathToSelectedArtifact + "\n  unselected: " + pathToArtifactThruSource;
}
Also used : DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Artifact(org.eclipse.aether.artifact.Artifact)

Example 15 with DependencyPath

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

the class MavenDependencyMediation method mediate.

@Override
public AnnotatedClassPath mediate(DependencyGraph dependencyGraph) {
    Set<Artifact> artifacts = new HashSet<>();
    // Versionless coordinates plus classifier, if any
    Set<String> alreadyFound = new HashSet<>();
    AnnotatedClassPath annotatedClassPath = new AnnotatedClassPath();
    List<DependencyPath> dependencyPaths = dependencyGraph.list();
    for (DependencyPath dependencyPath : dependencyPaths) {
        // DependencyPaths have items in level-order; nearest items come first.
        Artifact artifact = dependencyPath.getLeaf();
        File file = artifact.getFile();
        if (file != null && file.getName().endsWith(".jar")) {
            String versionlessCoordinates = Artifacts.makeKey(artifact) + ":" + artifact.getClassifier();
            if (alreadyFound.add(versionlessCoordinates)) {
                // Adds to artifacts when versionlessCoordinates are new.
                artifacts.add(artifact);
            }
            if (artifacts.contains(artifact)) {
                // We include multiple dependency paths to the first version of an artifact we see,
                // but not paths to other versions of that artifact.
                annotatedClassPath.put(new ClassPathEntry(artifact), dependencyPath);
            }
        }
    }
    return annotatedClassPath;
}
Also used : DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) File(java.io.File) Artifact(org.eclipse.aether.artifact.Artifact) HashSet(java.util.HashSet)

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