Search in sources :

Example 16 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class FreemarkerTest method testCountFailures.

@Test
public void testCountFailures() throws IOException, TemplateException, ParsingException {
    Configuration configuration = DashboardMain.configureFreemarker();
    Artifact artifact1 = new DefaultArtifact("io.grpc:grpc-context:1.15.0");
    ArtifactResults results1 = new ArtifactResults(artifact1);
    results1.addResult("Linkage Errors", 56);
    Artifact artifact2 = new DefaultArtifact("grpc:grpc:1.15.0");
    ArtifactResults results2 = new ArtifactResults(artifact2);
    results2.addResult("Linkage Errors", 0);
    List<ArtifactResults> table = ImmutableList.of(results1, results2);
    List<DependencyGraph> globalDependencies = ImmutableList.of();
    DashboardMain.generateDashboard(configuration, outputDirectory, table, globalDependencies, symbolProblemTable, new ClassPathResult(new AnnotatedClassPath(), ImmutableList.of()), new Bom("mock:artifact:1.6.7", null));
    Path dashboardHtml = outputDirectory.resolve("index.html");
    Assert.assertTrue(Files.isRegularFile(dashboardHtml));
    Document document = builder.build(dashboardHtml.toFile());
    // xom's query cannot specify partial class field, e.g., 'statistic-item'
    Nodes counts = document.query("//div[@class='container']/div/h2");
    Assert.assertTrue(counts.size() > 0);
    for (int i = 0; i < counts.size(); i++) {
        Integer.parseInt(counts.get(i).getValue().trim());
    }
    // Linkage Errors
    Truth.assertThat(counts.get(1).getValue().trim()).isEqualTo("1");
}
Also used : AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) Path(java.nio.file.Path) Bom(com.google.cloud.tools.opensource.dependencies.Bom) Configuration(freemarker.template.Configuration) AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) Document(nu.xom.Document) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Nodes(nu.xom.Nodes) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 17 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class GradleDependencyMediationTest method testMediation_withEnforcedPlatform.

@Test
public void testMediation_withEnforcedPlatform() 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")));
    GradleDependencyMediation mediation = GradleDependencyMediation.withEnforcedPlatform(new Bom("g:bom:1.0.0", ImmutableList.of(artifactA1)));
    AnnotatedClassPath result = mediation.mediate(graph);
    Truth.assertThat(result.getClassPath()).comparingElementsUsing(CLASS_PATH_ENTRY_TO_ARTIFACT).containsExactly(artifactA1, artifactB1).inOrder();
}
Also used : Bom(com.google.cloud.tools.opensource.dependencies.Bom) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) Dependency(org.eclipse.aether.graph.Dependency) Test(org.junit.Test)

Example 18 with DependencyGraph

use of com.google.cloud.tools.opensource.dependencies.DependencyGraph in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckerTest method testFindLinkageProblems_catchesNoSuchMethodError.

@Test
public void testFindLinkageProblems_catchesNoSuchMethodError() throws IOException {
    // org.slf4j.MDC catches NoSuchMethodError to detect the availability of
    // implementation for logging backend. The tool should not show errors for such classes.
    DependencyGraph slf4jGraph = dependencyGraphBuilder.buildMavenDependencyGraph(new Dependency(new DefaultArtifact("org.slf4j:slf4j-api:1.7.26"), "compile"));
    DependencyGraph logbackGraph = dependencyGraphBuilder.buildMavenDependencyGraph(new Dependency(new DefaultArtifact("ch.qos.logback:logback-classic:1.2.3"), "compile"));
    ClassPathEntry slf4jJar = new ClassPathEntry(slf4jGraph.list().get(0).getLeaf().getFile().toPath());
    ClassPathEntry log4jJar = new ClassPathEntry(logbackGraph.list().get(0).getLeaf().getFile().toPath());
    List<ClassPathEntry> paths = ImmutableList.of(slf4jJar, log4jJar);
    LinkageChecker linkageChecker = LinkageChecker.create(paths);
    ImmutableSet<LinkageProblem> problems = linkageChecker.findLinkageProblems();
    ImmutableList<ClassFile> sourcesOfInvalidReferences = problems.stream().map(LinkageProblem::getSourceClass).collect(toImmutableList());
    assertThat(sourcesOfInvalidReferences).doesNotContain(new ClassFile(slf4jJar, "org.slf4j.MDC"));
}
Also used : DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Aggregations

DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)18 Dependency (org.eclipse.aether.graph.Dependency)12 DependencyPath (com.google.cloud.tools.opensource.dependencies.DependencyPath)9 Artifact (org.eclipse.aether.artifact.Artifact)9 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 Test (org.junit.Test)8 AnnotatedClassPath (com.google.cloud.tools.opensource.classpath.AnnotatedClassPath)4 ClassPathResult (com.google.cloud.tools.opensource.classpath.ClassPathResult)4 LinkedHashMap (java.util.LinkedHashMap)4 ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)2 Bom (com.google.cloud.tools.opensource.dependencies.Bom)2 Update (com.google.cloud.tools.opensource.dependencies.Update)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Configuration (freemarker.template.Configuration)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)2