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