use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class BuildInfoRecorder method addDeployableArtifact.
private void addDeployableArtifact(org.jfrog.build.api.Artifact artifact, File artifactFile, String groupId, String artifactId, String version, String classifier, String fileExtension) {
String deploymentPath = getDeploymentPath(groupId, artifactId, version, classifier, fileExtension);
// deploy to snapshots or releases repository based on the deploy version
String targetRepository = getTargetRepository(deploymentPath);
DeployDetails deployable = new DeployDetails.Builder().artifactPath(deploymentPath).file(artifactFile).targetRepository(targetRepository).addProperties(conf.publisher.getMatrixParams()).build();
String myArtifactId = BuildInfoExtractorUtils.getArtifactId(currentModule.get().build().getId(), artifact.getName());
deployableArtifactBuilderMap.put(myArtifactId, deployable);
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class TaskHelperConfigurations method gradleDeployDetails.
private GradleDeployDetails gradleDeployDetails(PublishArtifact artifact, String configuration, @Nullable String artifactPath, @Nullable Set<String> processedFiles) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(getProject());
if (publisher == null) {
return null;
}
File file = artifact.getFile();
if (processedFiles != null && processedFiles.contains(file.getAbsolutePath())) {
return null;
}
if (!file.exists()) {
throw new GradleException("File '" + file.getAbsolutePath() + "'" + " does not exists, and need to be published!");
}
if (processedFiles != null) {
processedFiles.add(file.getAbsolutePath());
}
String revision = getProject().getVersion().toString();
Map<String, String> extraTokens = Maps.newHashMap();
if (StringUtils.isNotBlank(artifact.getClassifier())) {
extraTokens.put("classifier", artifact.getClassifier());
}
String pattern = publisher.getIvyArtifactPattern();
String gid = getProject().getGroup().toString();
if (publisher.isM2Compatible()) {
gid = gid.replace(".", "/");
}
DeployDetails.Builder deployDetailsBuilder = new DeployDetails.Builder().file(file);
try {
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(file, "MD5", "SHA1");
deployDetailsBuilder.md5(checksums.get("MD5")).sha1(checksums.get("SHA1"));
} catch (Exception e) {
throw new GradleException("Failed to calculate checksums for artifact: " + file.getAbsolutePath(), e);
}
if (artifactPath != null) {
deployDetailsBuilder.artifactPath(artifactPath);
} else {
deployDetailsBuilder.artifactPath(IvyPatternHelper.substitute(pattern, gid, getModuleName(), revision, artifact.getName(), artifact.getType(), artifact.getExtension(), configuration, extraTokens, null));
}
deployDetailsBuilder.targetRepository(publisher.getRepoKey());
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifact);
Map<String, String> propsToAdd = getPropsToAdd(artifactInfo, configuration);
deployDetailsBuilder.addProperties(propsToAdd);
DeployDetails details = deployDetailsBuilder.build();
return new GradleDeployDetails(artifactInfo, details, getProject());
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class TaskHelperPublications method addArtifactInfoToDeployDetails.
private void addArtifactInfoToDeployDetails(Set<GradleDeployDetails> deployDetails, String publicationName, DeployDetails.Builder builder, PublishArtifactInfo artifactInfo) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(getProject());
if (publisher != null) {
builder.targetRepository(publisher.getRepoKey());
Map<String, String> propsToAdd = getPropsToAdd(artifactInfo, publicationName);
builder.addProperties(propsToAdd);
DeployDetails details = builder.build();
deployDetails.add(new GradleDeployDetails(artifactInfo, details, getProject()));
}
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class ArtifactoryBuildInfoTrigger method collectModuleInformation.
/**
* Collect module information for each module.
*
* @param event the Ivy publish event
*/
private void collectModuleInformation(IvyEvent event) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ctx.getClientConf().publisher;
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
// Finding module object from context
@SuppressWarnings("unchecked") final Map<String, String> map = event.getAttributes();
Module module = getOrCreateModule(map);
List<Artifact> artifacts = module.getArtifacts();
if (artifacts == null) {
module.setArtifacts(Lists.<Artifact>newArrayList());
}
List<Artifact> excludedArtifacts = module.getExcludedArtifacts();
if (excludedArtifacts == null) {
module.setExcludedArtifacts(Lists.<Artifact>newArrayList());
}
final org.apache.ivy.core.module.descriptor.Artifact pubArtifact = ((PublishEvent) event).getArtifact();
@SuppressWarnings("unchecked") Map<String, String> extraAttributes = pubArtifact.getExtraAttributes();
// Using the original file, not the published one that can be far away (network wise)
String file = map.get("file");
// But all other attributes are taken from the actual published artifact
final ModuleRevisionId mrid = pubArtifact.getModuleRevisionId();
String moduleName = mrid.getName();
String type = getType(pubArtifact);
// By default simple name
String name = pubArtifact.getName() + "-" + mrid.getRevision() + "." + pubArtifact.getExt();
// Set name from name of published file
String fullPath = IvyResolverHelper.calculateArtifactPath(publisher, map, extraAttributes);
int lastSlash = fullPath.lastIndexOf('/');
if (lastSlash > 0 && lastSlash + 1 < fullPath.length()) {
name = fullPath.substring(lastSlash + 1);
}
project.log("[buildinfo:collect] Collecting artifact " + name + " for module " + moduleName + " using file " + file, Project.MSG_INFO);
if (isArtifactExist(module.getArtifacts(), name) || isArtifactExist(module.getExcludedArtifacts(), name)) {
return;
}
ArtifactBuilder artifactBuilder = new ArtifactBuilder(name);
artifactBuilder.type(type);
File artifactFile = new File(file);
Map<String, String> checksums = calculateFileChecksum(artifactFile);
String md5 = checksums.get(MD5);
String sha1 = checksums.get(SHA1);
artifactBuilder.md5(md5).sha1(sha1);
Artifact artifact = artifactBuilder.build();
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(fullPath, patterns)) {
module.getExcludedArtifacts().add(artifact);
} else {
module.getArtifacts().add(artifact);
}
@SuppressWarnings("unchecked") DeployDetails deployDetails = buildDeployDetails(artifactFile, artifact, ctx, map, extraAttributes);
ctx.addDeployDetailsForModule(deployDetails);
List<Module> contextModules = ctx.getModules();
if (contextModules.indexOf(module) == -1) {
ctx.addModule(module);
}
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class SpecsHelper method buildDeployDetailsFromFileEntry.
/**
* Creates set of DeployDetails from provided map of String->File entries, FileSpec and Properties
*
* @param fileEntry the FileSpec that contains the needed params.
* @param uploadFile a map of String->File entries that will be returned as a set of DeployDetails.
* @param buildProperties a map of properties to add to all the DeployDetails objects.
* @return Set of DeployDetails that represents the provided map of fileEntries aggregated with the ptops and the
* target provided in the uploadFile and buildProperties.
* @throws IOException in case of IO problem.
* @throws NoSuchAlgorithmException if appropriate checksum algorithm was not found.
*/
private DeployDetails buildDeployDetailsFromFileEntry(Map.Entry<String, File> fileEntry, FileSpec uploadFile, Multimap<String, String> buildProperties) throws IOException, NoSuchAlgorithmException {
String targetPath = fileEntry.getKey();
File artifactFile = fileEntry.getValue();
String path = UploadSpecHelper.wildcardCalculateTargetPath(targetPath, artifactFile);
path = StringUtils.replace(path, "//", "/");
// calculate the sha1 checksum and add it to the deploy artifactsToDeploy
Map<String, String> checksums;
try {
checksums = FileChecksumCalculator.calculateChecksums(artifactFile, SHA1, MD5);
} catch (NoSuchAlgorithmException e) {
throw new NoSuchAlgorithmException(String.format("Could not find checksum algorithm for %s or %s.", SHA1, MD5), e);
}
DeployDetails.Builder builder = new DeployDetails.Builder().file(artifactFile).artifactPath(path).targetRepository(getRepositoryKey(uploadFile.getTarget())).md5(checksums.get(MD5)).sha1(checksums.get(SHA1)).explode(BooleanUtils.toBoolean(uploadFile.getExplode())).addProperties(getPropertiesMap(uploadFile.getProps()));
if (buildProperties != null && !buildProperties.isEmpty()) {
builder.addProperties(buildProperties);
}
return builder.build();
}
Aggregations