Search in sources :

Example 1 with NpmCliParser

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser in project synopsys-detect by blackducksoftware.

the class DetectableFactory method createNpmCliDetectable.

public NpmCliDetectable createNpmCliDetectable(DetectableEnvironment environment, NpmResolver npmResolver, NpmCliExtractorOptions npmCliExtractorOptions) {
    NpmCliParser npmCliParser = new NpmCliParser(externalIdFactory, npmCliExtractorOptions.getDependencyTypeFilter());
    NpmCliExtractor npmCliExtractor = new NpmCliExtractor(executableRunner, npmCliParser, gson, toolVersionLogger);
    return new NpmCliDetectable(environment, fileFinder, npmResolver, npmCliExtractor, npmCliExtractorOptions);
}
Also used : NpmCliExtractor(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliExtractor) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) NpmCliParser(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser)

Example 2 with NpmCliParser

use of com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser in project synopsys-detect by blackducksoftware.

the class NpmOutputParserTest method npmCliDependencyFinder.

@Test
public void npmCliDependencyFinder() {
    NpmCliParser parser = new NpmCliParser(new ExternalIdFactory(), EnumListFilter.excludeNone());
    String testIn = String.join(System.lineSeparator(), Arrays.asList("{", "   \"name\": \"node-js\",", "   \"version\": \"0.2.0\",", "   \"dependencies\": {", "       \"upper-case\": {", "       \"version\": \"1.1.3\",", "       \"from\": \"upper-case@latest\",", "       \"resolved\": \"https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz\"", "       },", "       \"xml2js\": {", "           \"version\": \"0.4.17\",", "           \"from\": \"xml2js@latest\",", "           \"resolved\": \"https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz\",", "            \"dependencies\": {", "               \"sax\": {", "                   \"version\": \"1.2.2\",", "                   \"from\": \"sax@>=0.6.0\",", "                   \"resolved\": \"https://registry.npmjs.org/sax/-/sax-1.2.2.tgz\"", "               },", "               \"xmlbuilder\": {", "                   \"version\": \"4.2.1\",", "                   \"from\": \"xmlbuilder@>=4.1.0 <5.0.0\",", "                   \"resolved\": \"https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz\",", "                   \"dependencies\": {", "                       \"lodash\": {", "                           \"version\": \"4.17.4\",", "                           \"from\": \"lodash@>=4.0.0 <5.0.0\",", "                           \"resolved\": \"https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz\"", "                       }", "                   }", "               }", "           }", "       }", "   }", "}"));
    NpmDependencyTypeFilter npmDependencyTypeFilter = new NpmDependencyTypeFilter(Collections.emptySet(), Collections.emptySet(), true, true);
    PackageJson packageJson = new PackageJson();
    NpmPackagerResult result = parser.convertNpmJsonFileToCodeLocation(testIn, packageJson);
    Assertions.assertEquals("node-js", result.getProjectName());
    Assertions.assertEquals("0.2.0", result.getProjectVersion());
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
    graphAssert.hasRootSize(2);
    graphAssert.hasRootDependency("xml2js", "0.4.17");
    graphAssert.hasRootDependency("upper-case", "1.1.3");
    graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "xmlbuilder", "4.2.1");
    graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "sax", "1.2.2");
    graphAssert.hasParentChildRelationship("xmlbuilder", "4.2.1", "lodash", "4.17.4");
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) NpmDependencyTypeFilter(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult) NpmCliParser(com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser) Test(org.junit.jupiter.api.Test)

Aggregations

NpmCliParser (com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmCliParser)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 NpmCliDetectable (com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable)1 NpmCliExtractor (com.synopsys.integration.detectable.detectables.npm.cli.NpmCliExtractor)1 NpmDependencyTypeFilter (com.synopsys.integration.detectable.detectables.npm.cli.parse.NpmDependencyTypeFilter)1 NpmPackagerResult (com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)1 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)1 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)1 Test (org.junit.jupiter.api.Test)1