Search in sources :

Example 6 with Bom

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

the class LinkageMonitorTest method testBuildModelWithSnapshotBom_BomSnapshotUpdate.

@Test
public void testBuildModelWithSnapshotBom_BomSnapshotUpdate() throws ModelBuildingException, ArtifactResolutionException {
    // Linkage Monitor should update a BOM in Google Cloud Libraries BOM when it's available local
    // repository. This test case simulates the issue below where
    // google-cloud-bom:0.106.0-alpha-SNAPSHOT should provide gax:1.48.0.
    // https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/853
    // Libraries-bom:2.2.1 has google-cloud-bom:0.91.0-alpha, which has gax:1.44.0
    Model model = LinkageMonitor.buildModelWithSnapshotBom(system, session, "com.google.cloud:libraries-bom:2.2.1", ImmutableMap.of("com.google.cloud:google-cloud-bom", "0.106.0-alpha"));
    List<Dependency> dependencies = model.getDependencyManagement().getDependencies();
    // google-cloud-bom:0.106.0 has new artifacts such as google-cloud-gameservices
    assertEquals(224, dependencies.size());
    // google-cloud-bom:0.106.0-alpha has gax:1.48.0
    assertTrue(dependencies.stream().anyMatch(dependency -> "gax".equals(dependency.getArtifactId()) && "1.48.0".equals(dependency.getVersion())));
}
Also used : MavenRepositoryException(com.google.cloud.tools.opensource.dependencies.MavenRepositoryException) Bom(com.google.cloud.tools.opensource.dependencies.Bom) SymbolNotFoundProblem(com.google.cloud.tools.opensource.classpath.SymbolNotFoundProblem) Dependency(org.apache.maven.model.Dependency) AnnotatedClassPath(com.google.cloud.tools.opensource.classpath.AnnotatedClassPath) LinkageProblem(com.google.cloud.tools.opensource.classpath.LinkageProblem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ClassSymbol(com.google.cloud.tools.opensource.classpath.ClassSymbol) Correspondence.transforming(com.google.common.truth.Correspondence.transforming) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) Truth(com.google.common.truth.Truth) ImmutableList(com.google.common.collect.ImmutableList) Iterables.skip(com.google.common.collect.Iterables.skip) ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) Assert.fail(org.junit.Assert.fail) RepositoryUtility(com.google.cloud.tools.opensource.dependencies.RepositoryUtility) Path(java.nio.file.Path) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Before(org.junit.Before) ClassNotFoundProblem(com.google.cloud.tools.opensource.classpath.ClassNotFoundProblem) Artifacts(com.google.cloud.tools.opensource.dependencies.Artifacts) ImmutableSet(com.google.common.collect.ImmutableSet) Artifacts.toCoordinates(com.google.cloud.tools.opensource.dependencies.Artifacts.toCoordinates) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Assert.assertNotNull(org.junit.Assert.assertNotNull) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) ClassPathResult(com.google.cloud.tools.opensource.classpath.ClassPathResult) Assert.assertTrue(org.junit.Assert.assertTrue) MethodSymbol(com.google.cloud.tools.opensource.classpath.MethodSymbol) Set(java.util.Set) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) DependencyPath(com.google.cloud.tools.opensource.dependencies.DependencyPath) List(java.util.List) RepositoryException(org.eclipse.aether.RepositoryException) Paths(java.nio.file.Paths) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Assert.assertEquals(org.junit.Assert.assertEquals) Model(org.apache.maven.model.Model) RepositorySystem(org.eclipse.aether.RepositorySystem) Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) Test(org.junit.Test)

Example 7 with Bom

use of com.google.cloud.tools.opensource.dependencies.Bom 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 8 with Bom

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

the class BomContentTest method checkBom.

private void checkBom(Path bomPath) throws Exception {
    Bom bom = Bom.readBom(bomPath);
    List<Artifact> artifacts = bom.getManagedDependencies();
    for (Artifact artifact : artifacts) {
        assertReachable(buildMavenCentralUrl(artifact));
    }
    assertNoDowngradeRule(bom);
    assertUniqueClasses(artifacts);
    assertBomIsImported(bom);
}
Also used : Bom(com.google.cloud.tools.opensource.dependencies.Bom) Artifact(org.eclipse.aether.artifact.Artifact)

Example 9 with Bom

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

the class ClassPathBuilderTest method testArtifactsWithClassifiers.

@Test
public void testArtifactsWithClassifiers() throws Exception {
    String pomFile = "bom-with-classifier-artifacts.pom";
    Bom bom = Bom.readBom(TestHelper.absolutePathOfResource(pomFile));
    ClassPathResult classPathResult = classPathBuilder.resolve(bom.getManagedDependencies(), true, DependencyMediation.MAVEN);
    Truth.assertThat(classPathResult.getClassPath()).comparingElementsUsing(Correspondence.transforming((ClassPathEntry entry) -> entry.getArtifact().toString(), "has artifact coordinates")).contains("com.google.cloud:google-cloud-core:jar:tests:1.96.0");
}
Also used : Bom(com.google.cloud.tools.opensource.dependencies.Bom) Test(org.junit.Test)

Example 10 with Bom

use of com.google.cloud.tools.opensource.dependencies.Bom 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)

Aggregations

Bom (com.google.cloud.tools.opensource.dependencies.Bom)14 Test (org.junit.Test)8 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 Path (java.nio.file.Path)4 ClassPathResult (com.google.cloud.tools.opensource.classpath.ClassPathResult)3 LinkageProblem (com.google.cloud.tools.opensource.classpath.LinkageProblem)3 AnnotatedClassPath (com.google.cloud.tools.opensource.classpath.AnnotatedClassPath)2 ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)2 DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)2 DependencyPath (com.google.cloud.tools.opensource.dependencies.DependencyPath)2 ImmutableList (com.google.common.collect.ImmutableList)2 File (java.io.File)2 IOException (java.io.IOException)2 ClassFile (com.google.cloud.tools.opensource.classpath.ClassFile)1 ClassNotFoundProblem (com.google.cloud.tools.opensource.classpath.ClassNotFoundProblem)1 ClassPathBuilder (com.google.cloud.tools.opensource.classpath.ClassPathBuilder)1 ClassSymbol (com.google.cloud.tools.opensource.classpath.ClassSymbol)1 LinkageChecker (com.google.cloud.tools.opensource.classpath.LinkageChecker)1 MethodSymbol (com.google.cloud.tools.opensource.classpath.MethodSymbol)1