Search in sources :

Example 21 with Dependency

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);
    }
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency) Module(org.jfrog.build.extractor.ci.Module)

Example 22 with Dependency

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;
}
Also used : Arrays(java.util.Arrays) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Collectors(java.util.stream.Collectors) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ModuleType(org.jfrog.build.api.builder.ModuleType) ArrayList(java.util.ArrayList) Log(org.jfrog.build.api.util.Log) List(java.util.List) Module(org.jfrog.build.extractor.ci.Module) Map(java.util.Map) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) AqlSearchResult(org.jfrog.build.api.search.AqlSearchResult) Path(java.nio.file.Path) Collections(java.util.Collections) Dependency(org.jfrog.build.extractor.ci.Dependency) AqlSearchResult(org.jfrog.build.api.search.AqlSearchResult) HashMap(java.util.HashMap) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 23 with Dependency

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());
        }
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 24 with Dependency

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;
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 25 with 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);
    }
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency) File(java.io.File)

Aggregations

Dependency (org.jfrog.build.extractor.ci.Dependency)29 File (java.io.File)12 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)9 Module (org.jfrog.build.extractor.ci.Module)7 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 Path (java.nio.file.Path)4 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)4 RandomAccessFile (java.io.RandomAccessFile)3 ArrayList (java.util.ArrayList)3 Artifact (org.jfrog.build.extractor.ci.Artifact)3 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2