Search in sources :

Example 1 with ClassPathEntry

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;
}
Also used : Path(java.nio.file.Path) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ImmutableSet(com.google.common.collect.ImmutableSet) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry)

Example 2 with ClassPathEntry

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry) ImmutableSet(com.google.common.collect.ImmutableSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ClassPathEntry

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 &gt;
 * commons-logging:commons-logging &gt; 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();
}
Also used : DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ImmutableMap(com.google.common.collect.ImmutableMap) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry)

Example 4 with ClassPathEntry

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());
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) Artifact(org.eclipse.aether.artifact.Artifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry) DependencyNode(org.eclipse.aether.graph.DependencyNode) UnresolvableArtifactProblem(com.google.cloud.tools.opensource.dependencies.UnresolvableArtifactProblem) File(java.io.File)

Example 5 with ClassPathEntry

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());
}
Also used : AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry)

Aggregations

ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)17 Artifact (org.eclipse.aether.artifact.Artifact)12 ClassPathResult (com.google.cloud.tools.opensource.classpath.ClassPathResult)10 DependencyPath (com.google.cloud.tools.opensource.dependencies.DependencyPath)8 ClassPathBuilder (com.google.cloud.tools.opensource.classpath.ClassPathBuilder)7 LinkageProblem (com.google.cloud.tools.opensource.classpath.LinkageProblem)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 AnnotatedClassPath (com.google.cloud.tools.opensource.classpath.AnnotatedClassPath)4 ImmutableList (com.google.common.collect.ImmutableList)4 Path (java.nio.file.Path)4 ClassFile (com.google.cloud.tools.opensource.classpath.ClassFile)3 LinkageChecker (com.google.cloud.tools.opensource.classpath.LinkageChecker)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)2 Dependency (org.eclipse.aether.graph.Dependency)2