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;
}
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.");
}
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();
}
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));
}
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();
}
Aggregations