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());
}
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();
}
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);
}
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();
}
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());
}
Aggregations