use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project java-cloud-bom by googleapis.
the class DashboardMain method generateArtifactReport.
private static ArtifactResults generateArtifactReport(Artifact artifact, ArtifactInfo artifactInfo) {
// includes all versions
DependencyGraph graph = artifactInfo.getCompleteDependencies();
List<Update> convergenceIssues = graph.findUpdates();
// picks versions according to Maven rules
DependencyGraph transitiveDependencies = artifactInfo.getTransitiveDependencies();
Map<Artifact, Artifact> upperBoundFailures = findUpperBoundsFailures(graph.getHighestVersionMap(), transitiveDependencies);
ArtifactResults results = new ArtifactResults(artifact);
results.addResult(TEST_NAME_UPPER_BOUND, upperBoundFailures.size());
results.addResult(TEST_NAME_DEPENDENCY_CONVERGENCE, convergenceIssues.size());
return results;
}
use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project java-cloud-bom by googleapis.
the class DashboardMain method loadArtifactInfo.
/**
* This is the only method that queries the Maven repository.
*/
private static ArtifactCache loadArtifactInfo(List<Artifact> artifacts) {
Map<Artifact, ArtifactInfo> infoMap = new LinkedHashMap<>();
List<DependencyGraph> globalDependencies = new ArrayList<>();
for (Artifact artifact : artifacts) {
DependencyGraph completeDependencies = dependencyGraphBuilder.buildFullDependencyGraph(ImmutableList.of(artifact));
globalDependencies.add(completeDependencies);
// picks versions according to Maven rules
DependencyGraph transitiveDependencies = dependencyGraphBuilder.buildMavenDependencyGraph(new Dependency(artifact, "compile"));
ArtifactInfo info = new ArtifactInfo(completeDependencies, transitiveDependencies);
infoMap.put(artifact, info);
}
ArtifactCache cache = new ArtifactCache();
cache.setInfoMap(infoMap);
cache.setGlobalDependencies(globalDependencies);
return cache;
}
use of com.google.cloud.tools.opensource.dependencies.DependencyGraph 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.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardMain method collectLatestVersions.
private static Map<String, String> collectLatestVersions(List<DependencyGraph> globalDependencies) {
Map<String, String> latestArtifacts = new TreeMap<>();
VersionComparator comparator = new VersionComparator();
if (globalDependencies != null) {
for (DependencyGraph graph : globalDependencies) {
Map<String, String> map = graph.getHighestVersionMap();
for (String key : map.keySet()) {
String newVersion = map.get(key);
String oldVersion = latestArtifacts.get(key);
if (oldVersion == null || comparator.compare(newVersion, oldVersion) > 0) {
latestArtifacts.put(key, map.get(key));
}
}
}
}
return latestArtifacts;
}
use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardUnavailableArtifactTest method testDashboardForRepositoryException.
@Test
public void testDashboardForRepositoryException() throws TemplateException {
Configuration configuration = DashboardMain.configureFreemarker();
Artifact validArtifact = new DefaultArtifact("io.grpc:grpc-context:1.15.0");
Artifact nonExistentArtifact = new DefaultArtifact("io.grpc:nonexistent:jar:1.15.0");
DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder();
Map<Artifact, ArtifactInfo> map = new LinkedHashMap<>();
DependencyGraph graph1 = graphBuilder.buildMavenDependencyGraph(new Dependency(validArtifact, "compile"));
DependencyGraph graph2 = graphBuilder.buildMavenDependencyGraph(new Dependency(nonExistentArtifact, "compile"));
map.put(validArtifact, new ArtifactInfo(graph1, graph2));
map.put(nonExistentArtifact, new ArtifactInfo(new RepositoryException("foo")));
ArtifactCache cache = new ArtifactCache();
cache.setInfoMap(map);
List<ArtifactResults> artifactResults = DashboardMain.generateReports(configuration, outputDirectory, cache, ImmutableMap.of(), new ClassPathResult(new AnnotatedClassPath(), ImmutableList.of()), bom);
Assert.assertEquals("The length of the ArtifactResults should match the length of artifacts", 2, artifactResults.size());
Assert.assertEquals("The first artifact result should be valid", true, artifactResults.get(0).getResult(DashboardMain.TEST_NAME_UPPER_BOUND));
ArtifactResults errorArtifactResult = artifactResults.get(1);
Assert.assertNull("The second artifact result should be null", errorArtifactResult.getResult(DashboardMain.TEST_NAME_UPPER_BOUND));
Assert.assertEquals("The error artifact result should contain error message", "foo", errorArtifactResult.getExceptionMessage());
}
Aggregations