use of org.jfrog.build.extractor.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();
String gav = getModuleIdString(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
DependencyBuilder dependencyBuilder = new DependencyBuilder().id(gav).requestedBy(dependencyParentsMaps.get(gav)).type(getTypeString(dependency.getType(), dependency.getClassifier(), getExtension(depFile)));
String scopes = dependency.getScope();
if (StringUtils.isNotBlank(scopes)) {
dependencyBuilder.scopes(CommonUtils.newHashSet(scopes));
}
setDependencyChecksums(depFile, dependencyBuilder);
module.addDependency(dependencyBuilder.build());
}
}
use of org.jfrog.build.extractor.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 = new ArrayList<>();
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(CommonUtils.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_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
} catch (Exception e) {
throw new RuntimeException(e);
}
String md5 = checksums.get(MD5_ALGORITHM);
String sha1 = checksums.get(SHA1_ALGORITHM);
String sha256 = checksums.get(SHA256_ALGORITHM);
dependencyBuilder.md5(md5).sha1(sha1).sha256(sha256);
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.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class NugetRun method createDependency.
private Dependency createDependency(NugetPackgesConfig.ConfigPackage pkg, String globalCachePath) throws IOException, NoSuchAlgorithmException {
boolean found = true;
File nupkg = createNupkgFile(pkg.getId(), pkg.getVersion(), globalCachePath);
if (!nupkg.exists()) {
// If the original version can not be found in cache, we will check if one of the alternative version forms do exist.
found = false;
for (String v : createAlternativeVersionForms(pkg.getVersion())) {
nupkg = createNupkgFile(pkg.getId(), v, globalCachePath);
if (nupkg.exists()) {
found = true;
break;
}
}
}
if (found) {
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(nupkg, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
Dependency dependency = new DependencyBuilder().id(pkg.getId() + ':' + pkg.getVersion()).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).build();
return dependency;
}
return null;
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class DependenciesDownloaderHelper method validateChecksumsAndBuildDependency.
private Dependency validateChecksumsAndBuildDependency(Map<String, String> checksumsMap, ArtifactMetaData artifactMetaData, String filePath, String fileDestination, String remotePath) throws IOException {
String md5 = validateMd5Checksum(artifactMetaData.getMd5(), checksumsMap.get(MD5_ALGORITHM));
String sha1 = validateSha1Checksum(artifactMetaData.getSha1(), checksumsMap.get(SHA1_ALGORITHM));
return new DependencyBuilder().md5(md5).sha1(sha1).sha256(checksumsMap.get(SHA256_ALGORITHM)).id(filePath.substring(filePath.lastIndexOf(File.separatorChar) + 1)).localPath(fileDestination).remotePath(remotePath).build();
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class BuildInfoMavenBuilderTest method testDuplicateModuleDependencies.
/**
* Validates adding same dependencies with different scopes to different modules
*/
public void testDuplicateModuleDependencies() {
ModuleBuilder module1 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
module1.addDependency(new DependencyBuilder().id("dep1").scopes(CommonUtils.newHashSet("compile")).build());
module1.addDependency(new DependencyBuilder().id("dep2").scopes(CommonUtils.newHashSet("compile")).build());
ModuleBuilder module2 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
module2.addDependency(new DependencyBuilder().id("dep1").scopes(CommonUtils.newHashSet("compile", "test")).build());
module2.addDependency(new DependencyBuilder().id("dep2").scopes(CommonUtils.newHashSet("compile", "test")).build());
BuildInfoMavenBuilder builder = new BuildInfoMavenBuilder("test").number("4").started("test");
builder.addModule(module1.build());
builder.addModule(module2.build());
BuildInfo buildInfo = builder.build();
List<Module> modules = buildInfo.getModules();
assertFalse(modules.isEmpty(), "A buildInfo module should have been added.");
assertEquals(modules.size(), 1, "Expected to find only 1 module.");
assertEquals(modules.get(0).getId(), "id", "Expected to find module with id = 'id'.");
assertEquals(modules.get(0).getType(), "maven", "Expected to find module with type = 'maven'.");
List<Dependency> dependencies = modules.get(0).getDependencies();
assertEquals(dependencies.size(), 2, "Expected to find only 2 dependencies.");
assertTrue(dependencies.get(0).getScopes().contains("compile"), "Expected to find compile scope");
assertTrue(dependencies.get(0).getScopes().contains("test"), "Expected to find test scope");
assertTrue(dependencies.get(1).getScopes().contains("compile"), "Expected to find compile scope");
assertTrue(dependencies.get(1).getScopes().contains("test"), "Expected to find test scope");
}
Aggregations