use of com.google.cloud.tools.opensource.classpath.ClassPathEntry in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardMain method generateHtml.
private static Path generateHtml(Bom bom, ArtifactCache cache, ClassPathResult classPathResult, ImmutableSet<LinkageProblem> linkageProblems) throws IOException, TemplateException, URISyntaxException {
Artifact bomArtifact = new DefaultArtifact(bom.getCoordinates());
Path relativePath = outputDirectory(bomArtifact.getGroupId(), bomArtifact.getArtifactId(), bomArtifact.getVersion());
Path output = Files.createDirectories(relativePath);
copyResource(output, "css/dashboard.css");
copyResource(output, "js/dashboard.js");
ImmutableMap<ClassPathEntry, ImmutableSet<LinkageProblem>> linkageProblemTable = indexByJar(linkageProblems);
List<ArtifactResults> table = generateReports(freemarkerConfiguration, output, cache, linkageProblemTable, classPathResult, bom);
generateDashboard(freemarkerConfiguration, output, table, cache.getGlobalDependencies(), linkageProblemTable, classPathResult, bom);
return output;
}
use of com.google.cloud.tools.opensource.classpath.ClassPathEntry in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardMain method generateReports.
@VisibleForTesting
static List<ArtifactResults> generateReports(Configuration configuration, Path output, ArtifactCache cache, ImmutableMap<ClassPathEntry, ImmutableSet<LinkageProblem>> linkageProblemTable, ClassPathResult classPathResult, Bom bom) throws TemplateException {
Map<Artifact, ArtifactInfo> artifacts = cache.getInfoMap();
List<ArtifactResults> table = new ArrayList<>();
for (Entry<Artifact, ArtifactInfo> entry : artifacts.entrySet()) {
ArtifactInfo info = entry.getValue();
try {
if (info.getException() != null) {
ArtifactResults unavailable = new ArtifactResults(entry.getKey());
unavailable.setExceptionMessage(info.getException().getMessage());
table.add(unavailable);
} else {
Artifact artifact = entry.getKey();
ImmutableSet<ClassPathEntry> jarsInDependencyTree = classPathResult.getClassPathEntries(Artifacts.toCoordinates(artifact));
Map<ClassPathEntry, ImmutableSet<LinkageProblem>> relevantLinkageProblemTable = Maps.filterKeys(linkageProblemTable, jarsInDependencyTree::contains);
ArtifactResults results = generateArtifactReport(configuration, output, artifact, entry.getValue(), cache.getGlobalDependencies(), ImmutableMap.copyOf(relevantLinkageProblemTable), classPathResult, bom);
table.add(results);
}
} catch (IOException ex) {
ArtifactResults unavailableTestResult = new ArtifactResults(entry.getKey());
unavailableTestResult.setExceptionMessage(ex.getMessage());
// Even when there's a problem generating test result, show the error in the dashboard
table.add(unavailableTestResult);
}
}
return table;
}
use of com.google.cloud.tools.opensource.classpath.ClassPathEntry 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.classpath.ClassPathEntry 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.classpath.ClassPathEntry 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