use of org.jfrog.build.api.builder.DependencyBuilder 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.builder.DependencyBuilder in project build-info by JFrogDev.
the class BuildInfoRecorder method addDependenciesToCurrentModule.
private void addDependenciesToCurrentModule(ModuleBuilder module) {
Set<Artifact> moduleDependencies = currentModuleDependencies.get();
if (moduleDependencies == null) {
logger.warn("Skipping Artifactory Build-Info module dependency addition: Null current module dependency " + "list.");
return;
}
for (Artifact dependency : moduleDependencies) {
File depFile = dependency.getFile();
DependencyBuilder dependencyBuilder = new DependencyBuilder().id(getModuleIdString(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion())).type(getTypeString(dependency.getType(), dependency.getClassifier(), getExtension(depFile)));
String scopes = dependency.getScope();
if (StringUtils.isNotBlank(scopes)) {
dependencyBuilder.scopes(Sets.newHashSet(scopes));
}
setDependencyChecksums(depFile, dependencyBuilder);
module.addDependency(dependencyBuilder.build());
}
}
Aggregations