use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class PipBuildInfoExtractor method createDependenciesFromAqlResult.
private Map<String, Dependency> createDependenciesFromAqlResult(AqlSearchResult searchResult, Map<String, String> fileToPackage, Log logger) {
if (searchResult.getResults().isEmpty()) {
return Collections.emptyMap();
}
Map<String, Dependency> dependenciesMap = new HashMap<>();
for (AqlSearchResult.SearchEntry searchEntry : searchResult.getResults()) {
if (!isResultComplete(searchEntry)) {
continue;
}
// Avoid adding duplicated dependencies.
if (dependenciesMap.containsKey(fileToPackage.get(searchEntry.getName()))) {
continue;
}
// Add a new dependency only if searchEntry represents a package downloaded in this build execution.
if (fileToPackage.containsKey(searchEntry.getName())) {
Dependency curDep = new DependencyBuilder().id(searchEntry.getName()).md5(searchEntry.getActualMd5()).sha1(searchEntry.getActualSha1()).build();
dependenciesMap.put(fileToPackage.get(searchEntry.getName()), curDep);
}
}
Set<String> missingFiles = fileToPackage.keySet().stream().filter(x -> !dependenciesMap.containsKey(fileToPackage.get(x))).collect(Collectors.toSet());
promptMissingChecksumFromArtifactory(missingFiles, logger);
return dependenciesMap;
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class DependenciesCacheTest method dependenciesCacheTest.
@Test
public void dependenciesCacheTest() {
Map<String, Dependency> cacheMap = new HashMap<>();
// Create depA.
Dependency depA = new DependencyBuilder().id("depenA-1.0-A.zip").sha1("sha1A").md5("md5A").build();
cacheMap.put("depA", depA);
// Create depC.
Dependency depC = new DependencyBuilder().id("depenC-3.4-C.gzip").sha1("sha1C").md5("md5C").build();
cacheMap.put("depC", depC);
// Test cache methods.
Path projectDir = null;
try {
projectDir = TestUtils.createTempDir("pipCacheTest");
// Read empty cache.
DependenciesCache nullCache = DependenciesCache.getProjectDependenciesCache(projectDir, log);
assertNull(nullCache, "Expecting null cache read.");
// Write cache.
DependenciesCache.updateDependenciesCache(cacheMap, projectDir);
// Read existing cache.
DependenciesCache readCache = DependenciesCache.getProjectDependenciesCache(projectDir, log);
assertNotNull(readCache, "Expecting cache read.");
// Validate cache content.
Dependency depATest = readCache.getDependency("depA");
assertEquals(depATest, depA, String.format("Actual: %s\nExpected: %s", mapper.writeValueAsString(depATest), mapper.writeValueAsString(depA)));
Dependency depCTest = readCache.getDependency("depC");
assertEquals(depCTest, depC, String.format("Actual: %s\nExpected: %s", mapper.writeValueAsString(depCTest), mapper.writeValueAsString(depC)));
Dependency nonExistingDepTTest = readCache.getDependency("depT");
assertNull(nonExistingDepTTest, String.format("Actual: %s\nExpected null", mapper.writeValueAsString(nonExistingDepTTest)));
} catch (IOException e) {
fail(ExceptionUtils.getStackTrace(e));
} finally {
if (projectDir != null) {
FileUtils.deleteQuietly(projectDir.toFile());
}
}
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class GoRun method addDependency.
/**
* Each dependency is in format <name>:<version>.
* We add only the pgk zip file as build's dependency.
* The dependency's id is "module-name:version", and its type is "zip".
* We locate each pkg zip file downloaded to local Go cache, and calculate the pkg checksum.
*/
private void addDependency(String dependencyId, String cachePath) throws Exception {
String[] dependencyIdSplit = StringUtils.split(dependencyId, ":");
String name = dependencyIdSplit[0];
String version = "v" + dependencyIdSplit[1];
String cachedPkgPath = cachePath + convertModuleNameToCachePathConvention(name) + File.separator + "@v" + File.separator + version + ".zip";
File moduleZip = new File(cachedPkgPath);
if (moduleZip.exists()) {
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(moduleZip, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
Dependency dependency = new DependencyBuilder().id(name + ":" + version).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).type("zip").build();
dependenciesList.add(dependency);
}
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class DockerImage method setDependenciesAndArtifacts.
/**
* Search the docker image in Artifactory and add all artifacts & dependencies into Module.
*/
private void setDependenciesAndArtifacts(ModuleBuilder moduleBuilder, ArtifactoryManager artifactoryManager) throws IOException {
DockerLayer historyLayer = layers.getByDigest(imageId);
if (historyLayer == null) {
throw new IllegalStateException("Could not find the history docker layer: " + imageId + " for image: " + imageTag + " in Artifactory.");
}
int dependencyLayerNum = DockerUtils.getNumberOfDependentLayers(artifactoryManager.download(historyLayer.getFullPath()).getContent());
LinkedHashSet<Dependency> dependencies = new LinkedHashSet<>();
LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
// Filter out duplicate layers from manifest by using HashSet.
// Docker manifest may hold 'empty layers', as a result, docker promote will fail to promote the same layer more than once.
Iterator<String> it = DockerUtils.getLayersDigests(manifest).iterator();
for (int i = 0; i < dependencyLayerNum; i++) {
String digest = it.next();
DockerLayer layer = layers.getByDigest(digest);
Dependency dependency = new DependencyBuilder().id(layer.getFileName()).sha1(layer.getSha1()).build();
dependencies.add(dependency);
Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
artifacts.add(artifact);
}
moduleBuilder.dependencies(new ArrayList<>(dependencies));
while (it.hasNext()) {
String digest = it.next();
DockerLayer layer = layers.getByDigest(digest);
if (layer == null) {
continue;
}
Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
artifacts.add(artifact);
}
moduleBuilder.artifacts(new ArrayList<>(artifacts));
}
Aggregations