Search in sources :

Example 6 with ModuleBuilder

use of org.jfrog.build.extractor.builder.ModuleBuilder in project build-info by JFrogDev.

the class GoPublish method createBuild.

private BuildInfo createBuild() {
    BuildInfo buildInfo = new BuildInfo();
    String moduleId = StringUtils.defaultIfBlank(buildInfoModuleId, moduleName);
    Module module = new ModuleBuilder().type(ModuleType.GO).id(moduleId).repository(deploymentRepo).artifacts(artifactList).build();
    buildInfo.setModules(Collections.singletonList(module));
    return buildInfo;
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Module(org.jfrog.build.extractor.ci.Module)

Example 7 with ModuleBuilder

use of org.jfrog.build.extractor.builder.ModuleBuilder in project build-info by JFrogDev.

the class GoRun method createBuild.

private BuildInfo createBuild() {
    BuildInfo buildInfo = new BuildInfo();
    String moduleId = StringUtils.defaultIfBlank(buildInfoModuleId, moduleName);
    Module module = new ModuleBuilder().type(ModuleType.GO).id(moduleId).dependencies(dependenciesList).build();
    buildInfo.setModules(Collections.singletonList(module));
    return buildInfo;
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Module(org.jfrog.build.extractor.ci.Module)

Example 8 with ModuleBuilder

use of org.jfrog.build.extractor.builder.ModuleBuilder in project build-info by JFrogDev.

the class DockerImage method generateBuildInfoModule.

public Module generateBuildInfoModule(Log logger, DockerUtils.CommandType cmdType) throws IOException, InterruptedException {
    try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
        ModuleBuilder moduleBuilder = new ModuleBuilder().type(ModuleType.DOCKER).id(substringAfterLast(imageTag, "/")).repository(targetRepo);
        try {
            findAndSetManifestFromArtifactory(artifactoryManager, logger, cmdType);
        } catch (IOException e) {
            // The manifest could not be found in Artifactory.
            // Yet, we do not fail the build, but return an empty build-info instead.
            // The reason for not failing build is that there's a chance that the image was replaced
            // with another image, deployed to the same repo path.
            // This can happen if two parallel jobs build the same image. In that case, the build-info
            // for this build will be empty.
            logger.error("The manifest could not be fetched from Artifactory.");
            return moduleBuilder.build();
        }
        logger.info("Fetching details of published docker layers from Artifactory...");
        if (cmdType == DockerUtils.CommandType.Push) {
            setDependenciesAndArtifacts(moduleBuilder, artifactoryManager);
        } else {
            setDependencies(moduleBuilder);
        }
        setBuildInfoModuleProps(moduleBuilder);
        return moduleBuilder.build();
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) IOException(java.io.IOException)

Example 9 with ModuleBuilder

use of org.jfrog.build.extractor.builder.ModuleBuilder in project build-info by JFrogDev.

the class BuildExtractorUtilsTest method testBuildToJson.

public void testBuildToJson() throws IOException {
    String[] requestedByA = new String[] { "parentA", "b", "moduleId" };
    String[] requestedByB = new String[] { "parentB", "d", "moduleId" };
    Dependency dependencyA = new DependencyBuilder().id("depA").addRequestedBy(requestedByA).addRequestedBy(requestedByB).build();
    Module module = new ModuleBuilder().id("moduleId").addDependency(dependencyA).build();
    BuildInfo buildInfo = new BuildInfoBuilder("buildId").number("12").started("34").addModule(module).build();
    // Serialize and deserialize again
    BuildInfo actualBuildInfo = jsonStringToBuildInfo(buildInfoToJsonString(buildInfo));
    // Check buildInfo
    assertEquals(actualBuildInfo.getName(), buildInfo.getName());
    assertEquals(actualBuildInfo.getNumber(), buildInfo.getNumber());
    assertEquals(actualBuildInfo.getStarted(), buildInfo.getStarted());
    // Check module
    Module actualModule = actualBuildInfo.getModule(module.getId());
    assertNotNull(actualModule);
    // Check dependency
    assertEquals(actualModule.getDependencies().size(), 1);
    Dependency actualDependency = actualModule.getDependencies().get(0);
    assertEquals(actualDependency.getId(), dependencyA.getId());
    // Check requestedBy
    String[][] requestedBy = actualDependency.getRequestedBy();
    assertEquals(ArrayUtils.getLength(requestedBy), 2);
    assertEquals(requestedBy[0], requestedByA);
    assertEquals(requestedBy[1], requestedByB);
}
Also used : BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder)

Example 10 with ModuleBuilder

use of org.jfrog.build.extractor.builder.ModuleBuilder in project build-info by JFrogDev.

the class BuildInfoMavenBuilderTest method testDuplicateModuleArtifacts.

/**
 * Validates adding same artifacts to different modules
 */
public void testDuplicateModuleArtifacts() {
    ModuleBuilder module1 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
    module1.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).build());
    module1.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).build());
    ModuleBuilder module2 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
    module2.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).build());
    module2.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).build());
    BuildInfoMavenBuilder builder = new BuildInfoMavenBuilder("test").number("4").started("test");
    builder.addModule(module1.build());
    builder.addModule(module2.build());
    BuildInfo buildInfo = builder.build();
    List<Module> modules = buildInfo.getModules();
    assertFalse(modules.isEmpty(), "A buildInfo module should have been added.");
    assertEquals(modules.size(), 1, "Expected to find only 1 module.");
    assertEquals(modules.get(0).getId(), "id", "Expected to find module with id = 'id'.");
    assertEquals(modules.get(0).getType(), "maven", "Expected to find module with type = 'maven'.");
    List<Artifact> artifacts = modules.get(0).getArtifacts();
    assertEquals(artifacts.size(), 2, "Expected to find only 2 artifacts.");
    assertEquals(artifacts.get(0).getName(), "artifact1", "Unexpected artifact name.");
    assertEquals(artifacts.get(0).getMd5(), MD5, "Unexpected MD5 checksum.");
    assertEquals(artifacts.get(0).getSha1(), SHA1, "Unexpected SHA-1 checksum.");
    assertEquals(artifacts.get(0).getSha256(), SHA2, "Unexpected SHA-256 checksum.");
    assertEquals(artifacts.get(1).getName(), "artifact2", "Unexpected artifact name.");
    assertEquals(artifacts.get(1).getMd5(), MD5, "Unexpected MD5 checksum.");
    assertEquals(artifacts.get(1).getSha1(), SHA1, "Unexpected SHA-1 checksum.");
    assertEquals(artifacts.get(1).getSha256(), SHA2, "Unexpected SHA-256 checksum.");
}
Also used : BuildInfoMavenBuilder(org.jfrog.build.extractor.builder.BuildInfoMavenBuilder) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder)

Aggregations

ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)17 Module (org.jfrog.build.extractor.ci.Module)7 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)6 IOException (java.io.IOException)3 BuildInfoMavenBuilder (org.jfrog.build.extractor.builder.BuildInfoMavenBuilder)3 ArrayList (java.util.ArrayList)2 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)2 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)2 BuildInfoBuilder (org.jfrog.build.extractor.builder.BuildInfoBuilder)2 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArtifactBuilder (org.jfrog.build.extractor.builder.ArtifactBuilder)1 Artifact (org.jfrog.build.extractor.ci.Artifact)1 Dependency (org.jfrog.build.extractor.ci.Dependency)1 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)1 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)1 ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)1 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)1 ArtifactoryTask (org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask)1