use of com.google.cloud.tools.opensource.classpath.AnnotatedClassPath in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardUnavailableArtifactTest method testDashboardWithRepositoryException.
@Test
public void testDashboardWithRepositoryException() throws IOException, TemplateException, ParsingException {
Configuration configuration = DashboardMain.configureFreemarker();
Artifact validArtifact = new DefaultArtifact("io.grpc:grpc-context:1.15.0");
ArtifactResults validArtifactResult = new ArtifactResults(validArtifact);
validArtifactResult.addResult(DashboardMain.TEST_NAME_UPPER_BOUND, 0);
validArtifactResult.addResult(DashboardMain.TEST_NAME_DEPENDENCY_CONVERGENCE, 0);
validArtifactResult.addResult(DashboardMain.TEST_NAME_GLOBAL_UPPER_BOUND, 0);
Artifact invalidArtifact = new DefaultArtifact("io.grpc:nonexistent:jar:1.15.0");
ArtifactResults errorArtifactResult = new ArtifactResults(invalidArtifact);
errorArtifactResult.setExceptionMessage("Could not find artifact io.grpc:nonexistent:jar:1.15.0 in central" + " (https://repo1.maven.org/maven2/)");
List<ArtifactResults> table = new ArrayList<>();
table.add(validArtifactResult);
table.add(errorArtifactResult);
DashboardMain.generateDashboard(configuration, outputDirectory, table, ImmutableList.of(), ImmutableMap.of(), new ClassPathResult(new AnnotatedClassPath(), ImmutableList.of()), bom);
Path generatedHtml = outputDirectory.resolve("artifact_details.html");
Assert.assertTrue(Files.isRegularFile(generatedHtml));
Document document = builder.build(generatedHtml.toFile());
Assert.assertEquals("en-US", document.getRootElement().getAttribute("lang").getValue());
Nodes tr = document.query("//tr");
Assert.assertEquals("The size of rows in table should match the number of artifacts + 1 (header)", tr.size(), table.size() + 1);
Nodes tdForValidArtifact = tr.get(1).query("td");
Assert.assertEquals(Artifacts.toCoordinates(validArtifact), tdForValidArtifact.get(0).getValue());
Element firstResult = (Element) (tdForValidArtifact.get(2));
Truth.assertThat(firstResult.getValue().trim()).isEqualTo("PASS");
Truth.assertThat(firstResult.getAttributeValue("class")).isEqualTo("pass");
Nodes tdForErrorArtifact = tr.get(2).query("td");
Assert.assertEquals(Artifacts.toCoordinates(invalidArtifact), tdForErrorArtifact.get(0).getValue());
Element secondResult = (Element) (tdForErrorArtifact.get(2));
Truth.assertThat(secondResult.getValue().trim()).isEqualTo("UNAVAILABLE");
Truth.assertThat(secondResult.getAttributeValue("class")).isEqualTo("unavailable");
}
use of com.google.cloud.tools.opensource.classpath.AnnotatedClassPath 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.AnnotatedClassPath 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());
}
use of com.google.cloud.tools.opensource.classpath.AnnotatedClassPath in project cloud-opensource-java by GoogleCloudPlatform.
the class DashboardUnavailableArtifactTest method testDashboardForRepositoryException.
@Test
public void testDashboardForRepositoryException() throws TemplateException {
Configuration configuration = DashboardMain.configureFreemarker();
Artifact validArtifact = new DefaultArtifact("io.grpc:grpc-context:1.15.0");
Artifact nonExistentArtifact = new DefaultArtifact("io.grpc:nonexistent:jar:1.15.0");
DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder();
Map<Artifact, ArtifactInfo> map = new LinkedHashMap<>();
DependencyGraph graph1 = graphBuilder.buildMavenDependencyGraph(new Dependency(validArtifact, "compile"));
DependencyGraph graph2 = graphBuilder.buildMavenDependencyGraph(new Dependency(nonExistentArtifact, "compile"));
map.put(validArtifact, new ArtifactInfo(graph1, graph2));
map.put(nonExistentArtifact, new ArtifactInfo(new RepositoryException("foo")));
ArtifactCache cache = new ArtifactCache();
cache.setInfoMap(map);
List<ArtifactResults> artifactResults = DashboardMain.generateReports(configuration, outputDirectory, cache, ImmutableMap.of(), new ClassPathResult(new AnnotatedClassPath(), ImmutableList.of()), bom);
Assert.assertEquals("The length of the ArtifactResults should match the length of artifacts", 2, artifactResults.size());
Assert.assertEquals("The first artifact result should be valid", true, artifactResults.get(0).getResult(DashboardMain.TEST_NAME_UPPER_BOUND));
ArtifactResults errorArtifactResult = artifactResults.get(1);
Assert.assertNull("The second artifact result should be null", errorArtifactResult.getResult(DashboardMain.TEST_NAME_UPPER_BOUND));
Assert.assertEquals("The error artifact result should contain error message", "foo", errorArtifactResult.getExceptionMessage());
}
use of com.google.cloud.tools.opensource.classpath.AnnotatedClassPath 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");
}
Aggregations