use of org.jfrog.build.api.Artifact 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.api.Artifact 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.api.Artifact 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.api.Artifact in project build-info by JFrogDev.
the class ModuleBuilderTest method testBuilderAddMethods.
/**
* Validates the module values after using the builder add methods
*/
public void testBuilderAddMethods() {
Artifact artifact = new Artifact();
Dependency dependency = new Dependency();
String propertyKey = "key";
String propertyValue = "value";
Module module = new ModuleBuilder().id("test").addArtifact(artifact).addDependency(dependency).addProperty(propertyKey, propertyValue).build();
assertEquals(module.getId(), "test", "Unexpected module id");
assertFalse(module.getArtifacts().isEmpty(), "A module artifact should have been added.");
assertEquals(module.getArtifacts().get(0), artifact, "Unexpected module artifact.");
assertFalse(module.getDependencies().isEmpty(), "A module dependency should have been added.");
assertEquals(module.getDependencies().get(0), dependency, "Unexpected dependency artifact.");
assertTrue(module.getProperties().containsKey(propertyKey), "A module property should have been added.");
assertEquals(module.getProperties().get(propertyKey), propertyValue, "Unexpected module property value.");
}
use of org.jfrog.build.api.Artifact in project build-info by JFrogDev.
the class ArtifactBuilder method build.
/**
* Assembles the artifact class
*
* @return Assembled dependency
*/
public Artifact build() {
if (StringUtils.isBlank(name)) {
throw new IllegalArgumentException("Artifact must have a name");
}
Artifact artifact = new Artifact();
artifact.setName(name);
artifact.setType(type);
artifact.setSha1(sha1);
artifact.setSha256(sha256);
artifact.setMd5(md5);
artifact.setProperties(properties);
return artifact;
}
Aggregations