use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class NugetRun method singleProjectHandler.
private void singleProjectHandler(String projectName, String csprojPath, String globalCachePath) throws Exception {
String dependenciesSource = getDependenciesSource(projectName, csprojPath);
if (StringUtils.isEmpty(dependenciesSource)) {
logger.debug("Project dependencies was not found for project: " + projectName);
return;
}
// Collect dependencies according to the correct method:
// Check if project uses packages.config or project.assets.json
List<Dependency> dependencies = new ArrayList<>();
if (dependenciesSource.endsWith(PACKAGES_CONFIG)) {
dependencies = collectDependenciesFromPackagesConfig(dependenciesSource, globalCachePath);
} else if (dependenciesSource.endsWith(PROJECT_ASSETS)) {
dependencies = collectDependenciesFromProjectAssets(dependenciesSource);
}
Module projectModule = new ModuleBuilder().type(ModuleType.NUGET).id(projectName).dependencies(dependencies).build();
if (StringUtils.isBlank(module)) {
modulesList.add(projectModule);
} else {
// If a custom module name was provided, we will aggregate all projects under the same module.
modulesList.get(0).append(projectModule);
}
}
use of org.jfrog.build.extractor.ci.Dependency 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.ci.Dependency 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.ci.Dependency in project build-info by JFrogDev.
the class DependencyBuilder method build.
/**
* Assembles the dependency class
*
* @return Assembled dependency
*/
public Dependency build() {
Dependency dependency = new Dependency();
dependency.setId(id);
dependency.setType(type);
dependency.setScopes(scopes);
dependency.setSha1(sha1);
dependency.setSha256(sha256);
dependency.setMd5(md5);
dependency.setLocalPath(localPath);
dependency.setRemotePath(remotePath);
dependency.setRequestedBy(requestedBy);
dependency.setProperties(properties);
return dependency;
}
use of org.jfrog.build.extractor.ci.Dependency 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);
}
}
Aggregations