use of com.google.cloud.tools.opensource.dependencies.DependencyPath in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardMain method findRootCauses.
/**
* Returns mapping from jar files to summaries of the root problem in their {@link
* DependencyPath}s. The summary explains common patterns ({@code groupId:artifactId}) in the path
* elements. The returned map does not have a key for a jar file when it has fewer than {@link
* #MINIMUM_NUMBER_DEPENDENCY_PATHS} dependency paths or a common pattern is not found among the
* elements in the paths.
*
* <p>Example summary: "Artifacts 'com.google.http-client:google-http-client >
* commons-logging:commons-logging > log4j:log4j' exist in all 994 dependency paths. Example
* path: com.google.cloud:google-cloud-core:1.59.0 ..."
*
* <p>Using this summary in the BOM dashboard avoids repetitive items in the {@link
* DependencyPath} list that share the same root problem caused by widely-used libraries, for
* example, {@code commons-logging:commons-logging}, {@code
* com.google.http-client:google-http-client} and {@code log4j:log4j}.
*/
private static ImmutableMap<String, String> findRootCauses(ClassPathResult classPathResult) {
// Freemarker is not good at handling non-string keys. Path object in .ftl is automatically
// converted to String. https://freemarker.apache.org/docs/app_faq.html#faq_nonstring_keys
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (ClassPathEntry entry : classPathResult.getClassPath()) {
List<DependencyPath> dependencyPaths = classPathResult.getDependencyPaths(entry);
ImmutableList<String> commonVersionlessArtifacts = commonVersionlessArtifacts(dependencyPaths);
if (dependencyPaths.size() > MINIMUM_NUMBER_DEPENDENCY_PATHS && commonVersionlessArtifacts.size() > 1) {
// The last paths elements are always same
builder.put(entry.toString(), summaryMessage(dependencyPaths.size(), commonVersionlessArtifacts, dependencyPaths.get(0)));
}
}
return builder.build();
}
use of com.google.cloud.tools.opensource.dependencies.DependencyPath in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerRule method buildClassPathResult.
private static ClassPathResult buildClassPathResult(DependencyResolutionResult result) throws EnforcerRuleException {
// The root node must have the project's JAR file
DependencyNode root = result.getDependencyGraph();
File rootFile = root.getArtifact().getFile();
if (rootFile == null) {
throw new EnforcerRuleException("The root project artifact is not associated with a file.");
}
List<Dependency> unresolvedDependencies = result.getUnresolvedDependencies();
Set<Artifact> unresolvedArtifacts = unresolvedDependencies.stream().map(Dependency::getArtifact).collect(toImmutableSet());
DependencyGraph dependencyGraph = DependencyGraph.from(root);
AnnotatedClassPath annotatedClassPath = new AnnotatedClassPath();
ImmutableList.Builder<UnresolvableArtifactProblem> problems = ImmutableList.builder();
for (DependencyPath path : dependencyGraph.list()) {
Artifact artifact = path.getLeaf();
if (unresolvedArtifacts.contains(artifact)) {
problems.add(new UnresolvableArtifactProblem(artifact));
} else {
annotatedClassPath.put(new ClassPathEntry(artifact), path);
}
}
return new ClassPathResult(annotatedClassPath, problems.build());
}
use of com.google.cloud.tools.opensource.dependencies.DependencyPath in project cloud-opensource-java by GoogleCloudPlatform.
the class GradleDependencyMediationTest 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);
// Gradle chooses the highest version
Truth.assertThat(result.getClassPath()).comparingElementsUsing(CLASS_PATH_ENTRY_TO_ARTIFACT).containsExactly(artifactA2);
}
use of com.google.cloud.tools.opensource.dependencies.DependencyPath in project cloud-opensource-java by GoogleCloudPlatform.
the class GradleDependencyMediationTest 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(artifactA2, artifactB1).inOrder();
}
use of com.google.cloud.tools.opensource.dependencies.DependencyPath in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerTest method resolveTransitiveDependencyPaths.
/**
* Returns the class path resolved for the transitive dependencies of {@code coordinates}.
*/
private ImmutableList<ClassPathEntry> resolveTransitiveDependencyPaths(String coordinates) throws IOException {
DependencyGraph dependencies = dependencyGraphBuilder.buildMavenDependencyGraph(new Dependency(new DefaultArtifact(coordinates), "compile"));
ImmutableList.Builder<ClassPathEntry> builder = ImmutableList.builder();
for (DependencyPath path : dependencies.list()) {
builder.add(new ClassPathEntry(path.getLeaf()));
}
return builder.build();
}
Aggregations