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");
}
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();
}
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"));
}
Aggregations