Search in sources :

Example 11 with YarnLockDependency

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testOptionalSetFromMeta.

@Test
void testOptionalSetFromMeta() {
    List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
    "  version: 1", "  dependencies:", "    should-be-optional: 1.0.0", "    should-not-be-optional: 2.0.0", "  dependenciesMeta:", "    should-be-optional:", "      optional: true");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertTrue(yarnLock.getEntries().size() > 0);
    YarnLockEntry first = yarnLock.getEntries().get(0);
    YarnLockDependency optDep = first.getDependencies().stream().filter(it -> it.getName().equals("should-be-optional")).findFirst().get();
    YarnLockDependency reqDep = first.getDependencies().stream().filter(it -> it.getName().equals("should-not-be-optional")).findFirst().get();
    Assertions.assertTrue(optDep.isOptional());
    Assertions.assertFalse(reqDep.isOptional());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 12 with YarnLockDependency

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testDetectYarn2.

@Test
void testDetectYarn2() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("# This file is generated by running \"yarn install\" inside your project.");
    yarnLockText.add("# Manual changes might be lost - proceed with caution!");
    yarnLockText.add("");
    yarnLockText.add("__metadata:");
    yarnLockText.add("  version: 4");
    yarnLockText.add("  cacheKey: 7");
    yarnLockText.add("");
    yarnLockText.add("\"@babel/code-frame@npm:^7.0.0\":");
    yarnLockText.add("  version: 7.12.13");
    yarnLockText.add("  dependencies:");
    yarnLockText.add("    \"@babel/highlight\": ^7.12.13");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    YarnLockDependency dep = new YarnLockDependency("@babel/highlight", "^7.12.13", false);
    assertEntry(yarnLock, "@babel/code-frame", "^7.0.0", "7.12.13", dep);
    assertTrue(yarnLock.getFileFormatVersion().isPresent());
    assertEquals("4", yarnLock.getFileFormatVersion().get());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 13 with YarnLockDependency

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency 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)

Example 14 with YarnLockDependency

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.

the class YarnTransformerTest method addWorkspaceToYarnLockEntries.

private void addWorkspaceToYarnLockEntries(List<YarnLockEntry> yarnLockEntries, NameVersion workspace, String workspaceDepName) {
    List<YarnLockDependency> dependencyRefsToWkspDeps = Collections.singletonList(new YarnLockDependency(workspaceDepName, workspace.getVersion(), false));
    List<YarnLockEntryId> yarnLockEntryIdsWkspEntryIds = Arrays.asList(new YarnLockEntryId(workspace.getName(), workspace.getVersion()), new YarnLockEntryId(workspace.getName(), "workspace:packages/" + workspace.getName()));
    yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsWkspEntryIds, workspace.getVersion(), dependencyRefsToWkspDeps));
}
Also used : 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)

Example 15 with YarnLockDependency

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.

the class YarnLockDependencySpecParserTest method doValidDependencyTest.

private void doValidDependencyTest(String dependencySpec, String expectedName, String expectedVersion) {
    Optional<YarnLockDependency> dep = parser.parse(dependencySpec, true);
    Assertions.assertTrue(dep.isPresent());
    YarnLockDependency gottenDep = dep.get();
    Assertions.assertEquals(expectedName, gottenDep.getName());
    Assertions.assertEquals(expectedVersion, gottenDep.getVersion());
}
Also used : YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)

Aggregations

YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)15 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)10 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)9 Test (org.junit.jupiter.api.Test)9 YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)8 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)7 ArrayList (java.util.ArrayList)5 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)4 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)2 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)2 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 YarnWorkspace (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace)1 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)1 NameVersion (com.synopsys.integration.util.NameVersion)1 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1