Search in sources :

Example 1 with PackageLock

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

the class NpmLockfilePackager method parseAndTransform.

public NpmPackagerResult parseAndTransform(@Nullable String packageJsonText, String lockFileText, List<NameVersion> externalDependencies) {
    PackageJson packageJson = Optional.ofNullable(packageJsonText).map(content -> gson.fromJson(content, PackageJson.class)).orElse(null);
    PackageLock packageLock = gson.fromJson(lockFileText, PackageLock.class);
    NpmDependencyConverter dependencyConverter = new NpmDependencyConverter(externalIdFactory);
    NpmProject project = dependencyConverter.convertLockFile(packageLock, packageJson);
    DependencyGraph dependencyGraph = graphTransformer.transform(packageLock, project, externalDependencies);
    ExternalId projectId = projectIdTransformer.transform(packageJson, packageLock);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph, projectId);
    return new NpmPackagerResult(projectId.getName(), projectId.getVersion(), codeLocation);
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) Nullable(org.jetbrains.annotations.Nullable) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NpmDependencyConverter(com.synopsys.integration.detectable.detectables.npm.lockfile.NpmDependencyConverter) Gson(com.google.gson.Gson) NpmProject(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult) Optional(java.util.Optional) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PackageLock(com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock) PackageLock(com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NpmProject(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) NpmDependencyConverter(com.synopsys.integration.detectable.detectables.npm.lockfile.NpmDependencyConverter) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)

Example 2 with PackageLock

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

the class NpmWithoutRequiresExcludesTest method testDevDependencyExcluded.

@Test
public void testDevDependencyExcluded() {
    PackageLock packageLock = new PackageLock();
    packageLock.dependencies = new HashMap<>();
    List<NpmDependency> resolvedDependencies = new ArrayList<>();
    resolvedDependencies.add(new NpmDependency("example", "1.0.0", true, true));
    NpmProject npmProject = new NpmProject(Strings.EMPTY, Strings.EMPTY, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), resolvedDependencies);
    NpmLockfileGraphTransformer graphTransformer = new NpmLockfileGraphTransformer(EnumListFilter.fromExcluded(NpmDependencyType.DEV, NpmDependencyType.PEER));
    DependencyGraph graph = graphTransformer.transform(packageLock, npmProject, Collections.emptyList());
    GraphAssert graphAssert = new GraphAssert(Forge.NPMJS, graph);
    graphAssert.hasRootSize(0);
}
Also used : PackageLock(com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock) NpmLockfileGraphTransformer(com.synopsys.integration.detectable.detectables.npm.lockfile.parse.NpmLockfileGraphTransformer) NpmDependency(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmDependency) NpmProject(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Aggregations

DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 NpmProject (com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject)2 PackageLock (com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock)2 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 NpmDependencyConverter (com.synopsys.integration.detectable.detectables.npm.lockfile.NpmDependencyConverter)1 NpmDependency (com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmDependency)1 NpmLockfileGraphTransformer (com.synopsys.integration.detectable.detectables.npm.lockfile.parse.NpmLockfileGraphTransformer)1 NpmPackagerResult (com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)1 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)1 GraphAssert (com.synopsys.integration.detectable.util.graph.GraphAssert)1 NameVersion (com.synopsys.integration.util.NameVersion)1 List (java.util.List)1 Optional (java.util.Optional)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.jupiter.api.Test)1