Search in sources :

Example 6 with DeployDetails

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);
    }
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) File(java.io.File) IOException(java.io.IOException)

Example 7 with DeployDetails

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;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) ArtifactBuilder(org.jfrog.build.api.builder.ArtifactBuilder) Artifact(org.jfrog.build.api.Artifact)

Example 8 with DeployDetails

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;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) File(java.io.File) HashSet(java.util.HashSet)

Example 9 with DeployDetails

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;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) Module(org.jfrog.build.api.Module) File(java.io.File) Artifact(org.jfrog.build.api.Artifact)

Example 10 with DeployDetails

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);
    }
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map)

Aggregations

DeployDetails (org.jfrog.build.client.DeployDetails)19 File (java.io.File)9 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)5 GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)5 IOException (java.io.IOException)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)4 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)4 Artifact (org.jfrog.build.api.Artifact)3 Map (java.util.Map)2 Module (org.jfrog.build.api.Module)2 ArtifactBuilder (org.jfrog.build.api.builder.ArtifactBuilder)2 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)2 PublishArtifactInfo (org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo)2 Function (com.google.common.base.Function)1 RandomAccessFile (java.io.RandomAccessFile)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 EndArtifactPublishEvent (org.apache.ivy.core.event.publish.EndArtifactPublishEvent)1