Search in sources :

Example 1 with PnpmPackageInfo

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformer method buildGraph.

private void buildGraph(MutableDependencyGraph graphBuilder, List<String> rootPackageIds, @Nullable Map<String, PnpmPackageInfo> packageMap, PnpmLinkedPackageResolver linkedPackageResolver, @Nullable String reportingProjectPackagePath) throws IntegrationException {
    if (packageMap == null) {
        throw new DetectableException("Could not parse 'packages' section of the pnpm-lock.yaml file.");
    }
    for (Map.Entry<String, PnpmPackageInfo> packageEntry : packageMap.entrySet()) {
        String packageId = packageEntry.getKey();
        Optional<Dependency> pnpmPackage = buildDependencyFromPackageEntry(packageEntry);
        if (!pnpmPackage.isPresent()) {
            logger.debug(String.format("Could not add package %s to the graph.", packageId));
            continue;
        }
        if (isRootPackage(packageId, rootPackageIds)) {
            graphBuilder.addChildToRoot(pnpmPackage.get());
        }
        PnpmPackageInfo packageInfo = packageEntry.getValue();
        if (dependencyTypeFilter.shouldInclude(packageInfo.getDependencyType())) {
            for (Map.Entry<String, String> packageDependency : packageInfo.getDependencies().entrySet()) {
                String dependencyPackageId = convertRawEntryToPackageId(packageDependency, linkedPackageResolver, reportingProjectPackagePath);
                Optional<Dependency> child = buildDependencyFromPackageId(dependencyPackageId);
                child.ifPresent(c -> graphBuilder.addChildWithParent(child.get(), pnpmPackage.get()));
            }
        }
    }
}
Also used : Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) PnpmPackageInfo(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo)

Example 2 with PnpmPackageInfo

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformer method buildGraph.

private void buildGraph(DependencyGraph graphBuilder, List<String> rootPackageIds, @Nullable Map<String, PnpmPackageInfo> packageMap, PnpmLinkedPackageResolver linkedPackageResolver, @Nullable String reportingProjectPackagePath) throws IntegrationException {
    if (packageMap == null) {
        throw new DetectableException("Could not parse 'packages' section of the pnpm-lock.yaml file.");
    }
    for (Map.Entry<String, PnpmPackageInfo> packageEntry : packageMap.entrySet()) {
        String packageId = packageEntry.getKey();
        Optional<Dependency> pnpmPackage = buildDependencyFromPackageEntry(packageEntry);
        if (!pnpmPackage.isPresent()) {
            logger.debug(String.format("Could not add package %s to the graph.", packageId));
            continue;
        }
        if (isRootPackage(packageId, rootPackageIds)) {
            graphBuilder.addChildToRoot(pnpmPackage.get());
        }
        PnpmPackageInfo packageInfo = packageEntry.getValue();
        if (dependencyTypeFilter.shouldInclude(packageInfo.getDependencyType())) {
            for (Map.Entry<String, String> packageDependency : packageInfo.getDependencies().entrySet()) {
                String dependencyPackageId = convertRawEntryToPackageId(packageDependency, linkedPackageResolver, reportingProjectPackagePath);
                Optional<Dependency> child = buildDependencyFromPackageId(dependencyPackageId);
                child.ifPresent(c -> graphBuilder.addChildWithParent(child.get(), pnpmPackage.get()));
            }
        }
    }
}
Also used : Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) PnpmPackageInfo(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo)

Example 3 with PnpmPackageInfo

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformerTest method createPnpmLockYaml.

private PnpmLockYaml createPnpmLockYaml() {
    PnpmLockYaml pnpmLockYaml = new PnpmLockYaml();
    Map<String, String> dependencies = new HashMap<>();
    dependencies.put("dep", "1.0.0");
    dependencies.put("fileDep", "file:fileDep-1.0.0.tgz");
    pnpmLockYaml.dependencies = dependencies;
    Map<String, String> devDependencies = new HashMap<>();
    devDependencies.put("devDep", "2.0.0");
    pnpmLockYaml.devDependencies = devDependencies;
    Map<String, String> optionalDependencies = new HashMap<>();
    optionalDependencies.put("optDep", "3.0.0");
    pnpmLockYaml.optionalDependencies = optionalDependencies;
    Map<String, PnpmPackageInfo> packages = new HashMap<>();
    PnpmPackageInfo dep = new PnpmPackageInfo();
    Map<String, String> depDependencies = new HashMap<>();
    depDependencies.put("transitive", "1.1.0");
    dep.dependencies = depDependencies;
    packages.put("/dep/1.0.0", dep);
    PnpmPackageInfo devDep = new PnpmPackageInfo();
    devDep.dev = true;
    packages.put("/devDep/2.0.0", devDep);
    PnpmPackageInfo optDep = new PnpmPackageInfo();
    optDep.optional = true;
    packages.put("/optDep/3.0.0", optDep);
    PnpmPackageInfo transitive = new PnpmPackageInfo();
    packages.put("/transitive/1.1.0", transitive);
    PnpmPackageInfo fileDep = new PnpmPackageInfo();
    fileDep.name = "fileDep";
    fileDep.version = "1.0.0";
    packages.put("file:fileDep-1.0.0.tgz", fileDep);
    pnpmLockYaml.packages = packages;
    return pnpmLockYaml;
}
Also used : HashMap(java.util.HashMap) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) PnpmPackageInfo(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo)

Aggregations

PnpmPackageInfo (com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo)3 HashMap (java.util.HashMap)3 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)2 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)2 Map (java.util.Map)2 PnpmLockYaml (com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml)1