Search in sources :

Example 11 with PackageJson

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

the class PackageJsonExtractor method extract.

public Extraction extract(InputStream packageJsonInputStream) {
    Reader packageJsonReader = new InputStreamReader(packageJsonInputStream);
    PackageJson packageJson = gson.fromJson(packageJsonReader, PackageJson.class);
    return extract(packageJson);
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)

Example 12 with PackageJson

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

the class YarnTransformerTest method doesntThrowOnMissingExternalId.

@Test
void doesntThrowOnMissingExternalId() throws MissingExternalIdException {
    // Ensure components not defined in the graph doesn't cause an exception to be thrown. See IDETECT-1974.
    PackageJson rawPackageJson = new PackageJson();
    rawPackageJson.dependencies = new HashMap<>();
    rawPackageJson.dependencies.put("foo", "fooFuzzyVersion-1.0");
    NullSafePackageJson packageJson = new NullSafePackageJson(rawPackageJson);
    List<YarnLockEntryId> validYarnLockEntryIds = Collections.singletonList(new YarnLockEntryId("foo", "fooFuzzyVersion-1.0"));
    List<YarnLockDependency> validYarnLockDependencies = Collections.singletonList(new YarnLockDependency("yarn", "^1.22.4", false));
    List<YarnLockEntry> yarnLockEntries = Collections.singletonList(new YarnLockEntry(false, validYarnLockEntryIds, "1.0", validYarnLockDependencies));
    YarnLock yarnLock = new YarnLock(null, true, yarnLockEntries);
    YarnLockResult yarnLockResult = new YarnLockResult(packageJson, YarnWorkspaces.EMPTY, yarnLock);
    // This should not throw an exception.
    List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
    // Sanity check.
    assertEquals(1, codeLocations.size());
    CodeLocation codeLocation = codeLocations.get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    Assertions.assertNotNull(dependencyGraph, "The dependency graph should not be null.");
    assertEquals(1, dependencyGraph.getRootDependencies().size(), "Only 'foo:1.0' should appear in the graph.");
    ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
    assertTrue(dependencyGraph.hasDependency(fooExternalId), "Missing the only expected dependency.");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) WorkspacePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)12 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)4 NameVersion (com.synopsys.integration.util.NameVersion)4 Test (org.junit.jupiter.api.Test)4 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)3 NpmPackagerResult (com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)3 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)3 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)3 Extraction (com.synopsys.integration.detectable.extraction.Extraction)3 Gson (com.google.gson.Gson)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 NpmCliParser (com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser)2 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)2 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)2 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)2 YarnWorkspace (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace)2