use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class BuildDeploymentHelper method deploy.
public void deploy(Build build, ArtifactoryClientConfiguration clientConf, Map<String, DeployDetails> deployableArtifactBuilders, boolean wereThereTestFailures, File basedir) {
Set<DeployDetails> deployableArtifacts = prepareDeployableArtifacts(build, deployableArtifactBuilders);
logger.debug("Build Info Recorder: deploy artifacts: " + clientConf.publisher.isPublishArtifacts());
logger.debug("Build Info Recorder: publish build info: " + clientConf.publisher.isPublishBuildInfo());
File aggregateDirectory;
File buildInfoAggregated = null;
File buildInfoFile = null;
if (clientConf.publisher.isPublishBuildInfo() || clientConf.publisher.getAggregateArtifacts() != null) {
buildInfoFile = saveBuildInfoToFile(build, clientConf, basedir);
}
if (clientConf.publisher.getAggregateArtifacts() != null) {
aggregateDirectory = new File(clientConf.publisher.getAggregateArtifacts());
buildInfoAggregated = new File(aggregateDirectory, "build-info.json");
boolean isCopyAggregatedArtifacts = clientConf.publisher.isCopyAggregatedArtifacts();
boolean isPublishAggregatedArtifacts = clientConf.publisher.isPublishAggregatedArtifacts();
deployableArtifacts = aggregateArtifacts(aggregateDirectory, buildInfoFile, buildInfoAggregated, deployableArtifacts, isCopyAggregatedArtifacts, isPublishAggregatedArtifacts);
if (!isPublishAggregatedArtifacts) {
return;
}
}
if (!StringUtils.isEmpty(clientConf.info.getGeneratedBuildInfoFilePath())) {
try {
BuildInfoExtractorUtils.saveBuildInfoToFile(build, new File(clientConf.info.getGeneratedBuildInfoFilePath()));
} catch (Exception e) {
logger.error("Failed writing build info to file: ", e);
throw new RuntimeException("Failed writing build info to file", e);
}
}
if (!StringUtils.isEmpty(clientConf.info.getDeployableArtifactsFilePath())) {
try {
DeployableArtifactsUtils.saveDeployableArtifactsToFile(deployableArtifacts, new File(clientConf.info.getDeployableArtifactsFilePath()));
} catch (Exception e) {
logger.error("Failed writing deployable artifacts to file: ", e);
throw new RuntimeException("Failed writing deployable artifacts to file", e);
}
}
if (isDeployArtifacts(clientConf, wereThereTestFailures, deployableArtifacts)) {
deployArtifacts(clientConf, deployableArtifacts);
}
if (isPublishBuildInfo(clientConf, wereThereTestFailures)) {
publishBuildInfo(clientConf, build, buildInfoAggregated);
}
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class SpecsHelper method convertDeployDetailsToArtifacts.
private List<Artifact> convertDeployDetailsToArtifacts(Set<DeployDetails> details) {
List<Artifact> result = Lists.newArrayList();
for (DeployDetails detail : details) {
String ext = FilenameUtils.getExtension(detail.getFile().getName());
Artifact artifact = new ArtifactBuilder(detail.getFile().getName()).md5(detail.getMd5()).sha1(detail.getSha1()).type(ext).build();
result.add(artifact);
}
return result;
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class BuildDeploymentHelper method convertDeployables.
@SuppressWarnings({ "FeatureEnvy", "SuppressionAnnotation" })
private Set<DeployDetails> convertDeployables(File aggregateDirectory, Iterable<Map<String, ?>> deployables, boolean isCopyAggregatedArtifacts) throws IOException {
Set<DeployDetails> result = new HashSet<DeployDetails>();
for (Map<String, ?> map : deployables) {
File file = new File((String) map.get("file"));
if (isCopyAggregatedArtifacts) {
file = aggregatedFile(aggregateDirectory, file);
}
DeployDetails.Builder builder = new DeployDetails.Builder().targetRepository((String) map.get("targetRepository")).artifactPath((String) map.get("artifactPath")).file(file).sha1((String) map.get("sha1")).md5((String) map.get("md5")).addProperties((Map<String, String>) map.get("properties"));
result.add(builder.build());
}
return result;
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class BuildDeploymentHelper method prepareDeployableArtifacts.
private Set<DeployDetails> prepareDeployableArtifacts(Build build, Map<String, DeployDetails> deployableArtifactBuilders) {
Set<DeployDetails> deployableArtifacts = Sets.newLinkedHashSet();
List<Module> modules = build.getModules();
for (Module module : modules) {
List<Artifact> artifacts = module.getArtifacts();
if (artifacts != null) {
for (Artifact artifact : artifacts) {
String artifactId = BuildInfoExtractorUtils.getArtifactId(module.getId(), artifact.getName());
DeployDetails deployable = deployableArtifactBuilders.get(artifactId);
if (deployable != null) {
File file = deployable.getFile();
setArtifactChecksums(file, artifact);
deployableArtifacts.add(new DeployDetails.Builder().artifactPath(deployable.getArtifactPath()).file(file).md5(artifact.getMd5()).sha1(artifact.getSha1()).addProperties(deployable.getProperties()).targetRepository(deployable.getTargetRepository()).build());
}
}
}
}
return deployableArtifacts;
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class BuildDeploymentHelper method aggregateArtifacts.
@SuppressWarnings({ "TypeMayBeWeakened", "SuppressionAnnotation" })
private Set<DeployDetails> aggregateArtifacts(File aggregateDirectory, File buildInfoSource, File buildInfoDestination, Set<DeployDetails> deployables, boolean isCopyAggregatedArtifacts, boolean isPublishAggregatedArtifacts) {
try {
File deployablesDestination = new File(aggregateDirectory, "deployables.json");
List<Map<String, ?>> mergedDeployables = null;
if (buildInfoDestination.isFile()) {
Map<String, Object> buildInfoSourceMap = buildInfoMergeHelper.jsonToObject(buildInfoSource, Map.class);
Map<String, Object> buildInfoDestinationMap = buildInfoMergeHelper.jsonToObject(buildInfoDestination, Map.class);
int durationMillis = (Integer) buildInfoSourceMap.get("durationMillis") + (Integer) buildInfoDestinationMap.get("durationMillis");
buildInfoSourceMap.put("started", buildInfoDestinationMap.get("started"));
buildInfoSourceMap.put("durationMillis", durationMillis);
buildInfoMergeHelper.mergeAndWrite(buildInfoSourceMap, buildInfoDestinationMap, buildInfoDestination);
} else {
FileUtils.copyFile(buildInfoSource, buildInfoDestination);
}
if (deployablesDestination.isFile()) {
List<Map<String, ?>> currentDeployables = deployablesMergeHelper.jsonToObject(deployablesMergeHelper.objectToJson(deployables), List.class);
List<Map<String, ?>> previousDeployables = deployablesMergeHelper.jsonToObject(deployablesDestination, List.class);
mergedDeployables = deployablesMergeHelper.mergeAndWrite(currentDeployables, previousDeployables, deployablesDestination);
} else {
FileUtils.write(deployablesDestination, deployablesMergeHelper.objectToJson(deployables), "UTF-8");
}
if (isCopyAggregatedArtifacts) {
for (DeployDetails details : deployables) {
/**
* We could check MD5 checksum of destination file (if it exists) and save on copy operation but since most *.jar
* files contain a timestamp in pom.properties (thanks, Maven) - checksum would only match for POM files.
*/
File aggregatedFile = aggregatedFile(aggregateDirectory, details.getFile());
FileUtils.copyFile(details.getFile(), aggregatedFile);
}
}
return (isPublishAggregatedArtifacts && (mergedDeployables != null)) ? convertDeployables(aggregateDirectory, mergedDeployables, isCopyAggregatedArtifacts) : deployables;
} catch (IOException e) {
throw new RuntimeException("Failed to aggregate artifacts and Build Info in [" + aggregateDirectory + "]", e);
}
}
Aggregations