Search in sources :

Example 11 with Bom

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

the class LinkageCheckerTest method testBomHavingClassifierArtifacts.

@Test
public void testBomHavingClassifierArtifacts() throws Exception {
    String pomFile = "bom-with-classifier-artifacts.pom";
    Bom bom = Bom.readBom(TestHelper.absolutePathOfResource(pomFile));
    LinkageChecker linkageChecker = LinkageChecker.create(bom);
    ImmutableSet<LinkageProblem> linkageProblems = linkageChecker.findLinkageProblems();
    // bom-with-classifier-artifacts contains com.google.cloud:google-cloud-core:jar:tests:1.96.0.
    // This tests-classifier artifact requires Truth and JUnit dependencies to work, but it's not
    // declared in its pom.xml (The user of the class needs to declare them because the tests-
    // classifier artifacts are intended to be used in tests.) Therefore the linkage errors to the
    // classes in the missing dependencies are expected.
    Truth.assertThat(linkageProblems).comparingElementsUsing(Correspondence.transforming((LinkageProblem problem) -> problem.getSymbol().getClassBinaryName(), "has missing symbol")).containsAtLeast("com.google.common.testing.EqualsTester", "com.google.common.truth.Truth", "org.junit.Assert");
    Truth.assertThat(linkageProblems).comparingElementsUsing(Correspondence.transforming((LinkageProblem problem) -> problem.getSourceClass().getClassPathEntry().getArtifact().toString(), "has source class belonging to artifact")).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 12 with Bom

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

the class DashboardMain method main.

/**
 * Generates a code hygiene dashboard for a BOM. This tool takes a path to pom.xml of the BOM as
 * an argument or Maven coordinates to a BOM.
 *
 * <p>Generated dashboard is at {@code target/$groupId/$artifactId/$version/index.html}, where
 * each value is from BOM coordinates except {@code $version} is "snapshot" if the BOM has
 * snapshot version.
 */
public static void main(String[] arguments) throws IOException, TemplateException, RepositoryException, URISyntaxException, ParseException, MavenRepositoryException {
    DashboardArguments dashboardArguments = DashboardArguments.readCommandLine(arguments);
    // If looking to edit the dashboard structure, see DashboardMain#generateDashboard.
    if (dashboardArguments.hasVersionlessCoordinates()) {
        generateAllVersions(dashboardArguments.getVersionlessCoordinates());
        return;
    }
    Bom bom;
    if (dashboardArguments.hasFile()) {
        Path bomFile = dashboardArguments.getBomFile();
        checkArgument(Files.isRegularFile(bomFile), "The input BOM %s is not a regular file", bomFile);
        checkArgument(Files.isReadable(bomFile), "The input BOM %s is not readable", bomFile);
        bom = Bom.readBom(bomFile);
    } else {
        bom = Bom.readBom(dashboardArguments.getBomCoordinates());
    }
    if (dashboardArguments.getReport()) {
        if (!report(bom, System.out)) {
            throw new RuntimeException("Failed to converge dependencies");
        }
    } else {
        generate(bom);
    }
    if (dashboardArguments.getOutputFile() != null) {
        Path relativePath = dashboardArguments.getOutputFile();
        Files.createDirectories(relativePath.getParent());
        File file = new File(String.valueOf(relativePath));
        OutputStream outputStream = new FileOutputStream(file);
        if (!report(bom, outputStream)) {
            throw new RuntimeException("Failed to converge dependencies");
        }
        outputStream.close();
    }
}
Also used : Path(java.nio.file.Path) Bom(com.google.cloud.tools.opensource.dependencies.Bom) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 13 with Bom

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

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 14 with Bom

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

the class BomContentTest method checkBomReachable.

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

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