Search in sources :

Example 6 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class NpmBuildInfoExtractor method getDependenciesMapFromBuild.

static Map<String, Dependency> getDependenciesMapFromBuild(BuildInfo buildInfo) {
    Map<String, Dependency> previousBuildDependencies = new ConcurrentHashMap<>();
    // Iterate over all modules and extract dependencies.
    List<Module> modules = buildInfo.getModules();
    for (Module module : modules) {
        List<Dependency> dependencies = module.getDependencies();
        if (dependencies != null) {
            for (Dependency dependency : dependencies) {
                previousBuildDependencies.put(dependency.getId(), dependency);
            }
        }
    }
    return previousBuildDependencies;
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Module(org.jfrog.build.extractor.ci.Module)

Example 7 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class NpmBuildInfoExtractor method extract.

@Override
public BuildInfo extract(NpmProject npmProject) throws Exception {
    String resolutionRepository = npmProject.getResolutionRepository();
    List<String> commandArgs = npmProject.getCommandArgs();
    Path workingDir = npmProject.getWorkingDir();
    preparePrerequisites(resolutionRepository, workingDir);
    createTempNpmrc(workingDir, commandArgs);
    try {
        if (npmProject.isCiCommand()) {
            runCi(workingDir, commandArgs);
        } else {
            runInstall(workingDir, commandArgs);
        }
    } finally {
        restoreNpmrc(workingDir);
    }
    List<Dependency> dependencies = collectDependencies(workingDir);
    String moduleId = StringUtils.isNotBlank(module) ? module : npmPackageInfo.toString();
    return createBuild(dependencies, moduleId);
}
Also used : Path(java.nio.file.Path) Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 8 with Dependency

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

Example 9 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class NugetRun method collectDependenciesFromPackagesConfig.

private List<Dependency> collectDependenciesFromPackagesConfig(String packagesConfigPath, String globalCachePath) throws Exception {
    File packagesConfig = new File(packagesConfigPath);
    NugetPackgesConfig config = new NugetPackgesConfig();
    config.readPackageConfig(packagesConfig);
    List<Dependency> dependenciesList = new ArrayList<>();
    for (NugetPackgesConfig.ConfigPackage pkg : config.getPackages()) {
        Dependency pkgDependency = createDependency(pkg, globalCachePath);
        if (pkgDependency == null) {
            logger.warn(String.format("The following NuGet package %s with version %s was not found in the NuGet cache %s.%s", pkg.getId(), pkg.getVersion(), globalCachePath, ABSENT_NUPKG_WARN_MSG));
            continue;
        }
        dependenciesList.add(pkgDependency);
    }
    return dependenciesList;
}
Also used : NugetPackgesConfig(org.jfrog.build.extractor.nuget.types.NugetPackgesConfig) Dependency(org.jfrog.build.extractor.ci.Dependency) File(java.io.File)

Example 10 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class NpmExtractorConsumer method appendDependency.

/**
 * If package is included in the dependencies map, add the current scope for the dependency.
 * Otherwise, retrieve sha1 and md5 from Artifactory and add the dependency to the dependencies map.
 *
 * @param npmPackageInfo - The npm package information.
 * @return True if the package is legal. False in case of an error such as an absence in Artifactory's cache.
 */
private boolean appendDependency(NpmPackageInfo npmPackageInfo) {
    String id = npmPackageInfo.getName() + ":" + npmPackageInfo.getVersion();
    Dependency dependency = dependencies.get(id);
    if (dependency == null) {
        dependency = createDependency(npmPackageInfo, id);
        if (dependency == null) {
            return false;
        }
        dependencies.put(id, dependency);
    } else {
        dependency.getScopes().add(npmPackageInfo.getScope());
    }
    dependency.addRequestedBy(npmPackageInfo.getPathToRoot());
    return true;
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency)

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