Search in sources :

Example 1 with ArtifactBuilder

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

the class SpecsHelper method convertDeployDetailsToArtifacts.

private List<Artifact> convertDeployDetailsToArtifacts(Set<DeployDetails> details) {
    List<Artifact> result = new ArrayList<>();
    for (DeployDetails detail : details) {
        String ext = FilenameUtils.getExtension(detail.getFile().getName());
        ArtifactBuilder artifactBuilder = new ArtifactBuilder(detail.getFile().getName());
        artifactBuilder.md5(detail.getMd5()).sha1(detail.getSha1()).sha256(detail.getSha256()).type(ext).localPath(detail.getFile().getAbsolutePath()).remotePath(detail.getArtifactPath()).build();
        result.add(artifactBuilder.build());
    }
    return result;
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ArrayList(java.util.ArrayList) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) Artifact(org.jfrog.build.extractor.ci.Artifact)

Example 2 with ArtifactBuilder

use of org.jfrog.build.extractor.builder.ArtifactBuilder 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)

Example 3 with ArtifactBuilder

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

the class NpmPublish method doDeploy.

private void doDeploy() throws IOException {
    DeployDetails deployDetails = new DeployDetails.Builder().file(path.toFile()).targetRepository(repo).addProperties(properties).artifactPath(npmPackageInfo.getDeployPath()).packageType(DeployDetails.PackageType.NPM).build();
    ArtifactoryUploadResponse response = artifactoryManager.upload(deployDetails);
    deployedArtifact = new ArtifactBuilder(npmPackageInfo.getModuleId()).md5(response.getChecksums().getMd5()).sha1(response.getChecksums().getSha1()).remotePath(StringUtils.substringBeforeLast(npmPackageInfo.getDeployPath(), "/")).build();
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) ArtifactoryManagerBuilder(org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder) ArtifactoryUploadResponse(org.jfrog.build.client.ArtifactoryUploadResponse) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder)

Example 4 with ArtifactBuilder

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

the class DockerImage method setDependenciesAndArtifacts.

/**
 * Search the docker image in Artifactory and add all artifacts & dependencies into Module.
 */
private void setDependenciesAndArtifacts(ModuleBuilder moduleBuilder, ArtifactoryManager artifactoryManager) throws IOException {
    DockerLayer historyLayer = layers.getByDigest(imageId);
    if (historyLayer == null) {
        throw new IllegalStateException("Could not find the history docker layer: " + imageId + " for image: " + imageTag + " in Artifactory.");
    }
    int dependencyLayerNum = DockerUtils.getNumberOfDependentLayers(artifactoryManager.download(historyLayer.getFullPath()).getContent());
    LinkedHashSet<Dependency> dependencies = new LinkedHashSet<>();
    LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
    // Filter out duplicate layers from manifest by using HashSet.
    // Docker manifest may hold 'empty layers', as a result, docker promote will fail to promote the same layer more than once.
    Iterator<String> it = DockerUtils.getLayersDigests(manifest).iterator();
    for (int i = 0; i < dependencyLayerNum; i++) {
        String digest = it.next();
        DockerLayer layer = layers.getByDigest(digest);
        Dependency dependency = new DependencyBuilder().id(layer.getFileName()).sha1(layer.getSha1()).build();
        dependencies.add(dependency);
        Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
        artifacts.add(artifact);
    }
    moduleBuilder.dependencies(new ArrayList<>(dependencies));
    while (it.hasNext()) {
        String digest = it.next();
        DockerLayer layer = layers.getByDigest(digest);
        if (layer == null) {
            continue;
        }
        Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
        artifacts.add(artifact);
    }
    moduleBuilder.artifacts(new ArrayList<>(artifacts));
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) Artifact(org.jfrog.build.extractor.ci.Artifact) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder)

Example 5 with ArtifactBuilder

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

the class GoPublish method deploy.

/**
 * Deploy pkg file and add it as an buildInfo's artifact
 */
private Artifact deploy(ArtifactoryManager artifactoryManager, File deployedFile, String extension) throws Exception {
    String artifactName = version + "." + extension;
    Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(deployedFile, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
    String remotePath = moduleName + "/@v";
    DeployDetails deployDetails = new DeployDetails.Builder().file(deployedFile).targetRepository(deploymentRepo).addProperties(properties).artifactPath(remotePath + "/" + artifactName).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).packageType(DeployDetails.PackageType.GO).build();
    ArtifactoryUploadResponse response = artifactoryManager.upload(deployDetails);
    return new ArtifactBuilder(moduleName + ":" + artifactName).md5(response.getChecksums().getMd5()).sha1(response.getChecksums().getSha1()).sha256(response.getChecksums().getSha256()).remotePath(remotePath).build();
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ArtifactoryUploadResponse(org.jfrog.build.client.ArtifactoryUploadResponse) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder)

Aggregations

ArtifactBuilder (org.jfrog.build.extractor.builder.ArtifactBuilder)8 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)4 File (java.io.File)3 Artifact (org.jfrog.build.extractor.ci.Artifact)3 ArtifactMetadata (org.apache.maven.artifact.metadata.ArtifactMetadata)2 ProjectArtifactMetadata (org.apache.maven.project.artifact.ProjectArtifactMetadata)2 ArtifactoryUploadResponse (org.jfrog.build.client.ArtifactoryUploadResponse)2 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)2 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)2 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)2 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)2 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)2 ArrayList (java.util.ArrayList)1 EndArtifactPublishEvent (org.apache.ivy.core.event.publish.EndArtifactPublishEvent)1 PublishEvent (org.apache.ivy.core.event.publish.PublishEvent)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 Project (org.apache.tools.ant.Project)1 BuildInfoMavenBuilder (org.jfrog.build.extractor.builder.BuildInfoMavenBuilder)1