use of org.jfrog.build.api.Module in project build-info by JFrogDev.
the class ModuleBuilder method build.
/**
* Assembles the module class
*
* @return Assembled module
*/
public Module build() {
if (id == null || id.trim().length() == 0) {
throw new IllegalArgumentException("Cannot build module entity without Module ID value");
}
Module module = new Module();
module.setId(id.trim());
module.setArtifacts(artifacts);
module.setDependencies(dependencies);
module.setProperties(properties);
module.setExcludedArtifacts(excludedArtifacts);
return module;
}
use of org.jfrog.build.api.Module in project build-info by JFrogDev.
the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.
/**
* Collect dependency information during the build.
*
* @param event The end of resolution Ivy event
*/
private void collectDependencyInformation(IvyEvent event) {
Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
ResolveReport report = ((EndResolveEvent) event).getReport();
@SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
Module module = getOrCreateModule(attributes);
project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
String[] configurations = report.getConfigurations();
List<Dependency> moduleDependencies = Lists.newArrayList();
for (String configuration : configurations) {
project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
String type = getType(artifactsReport.getArtifact());
Dependency dependency = findDependencyInList(id, type, moduleDependencies);
if (dependency == null) {
DependencyBuilder dependencyBuilder = new DependencyBuilder();
dependencyBuilder.type(type).scopes(Sets.newHashSet(configuration));
String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
dependencyBuilder.id(idString);
File file = artifactsReport.getLocalFile();
Map<String, String> checksums;
try {
checksums = FileChecksumCalculator.calculateChecksums(file, MD5, SHA1);
} catch (Exception e) {
throw new RuntimeException(e);
}
String md5 = checksums.get(MD5);
String sha1 = checksums.get(SHA1);
dependencyBuilder.md5(md5).sha1(sha1);
dependency = dependencyBuilder.build();
moduleDependencies.add(dependency);
project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
} else {
if (!dependency.getScopes().contains(configuration)) {
dependency.getScopes().add(configuration);
project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
} else {
project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
}
}
}
}
module.setDependencies(moduleDependencies);
}
}
use of org.jfrog.build.api.Module in project build-info by JFrogDev.
the class ModuleBuilderTest method testBuilderSetters.
/**
* Validates the module values after using the builder setters
*/
public void testBuilderSetters() {
String id = "moo";
List<Artifact> artifacts = Lists.newArrayList();
List<Dependency> dependencies = Lists.newArrayList();
Properties properties = new Properties();
Module module = new ModuleBuilder().id(id).artifacts(artifacts).dependencies(dependencies).properties(properties).build();
assertEquals(module.getId(), id, "Unexpected module ID.");
assertEquals(module.getArtifacts(), artifacts, "Unexpected module artifacts.");
assertTrue(module.getArtifacts().isEmpty(), "Module artifacts list should not have been populated.");
assertEquals(module.getDependencies(), dependencies, "Unexpected module dependencies.");
assertTrue(module.getDependencies().isEmpty(), "Module dependencies list should not have been populated.");
assertEquals(module.getProperties(), properties, "Unexpected module properties.");
assertTrue(module.getProperties().isEmpty(), "Module properties list should not have been populated.");
}
use of org.jfrog.build.api.Module 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.Module 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);
}
}
Aggregations