Search in sources :

Example 1 with YarnLockParser

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

the class YarnLockParserFunctionalTest method testV1Lockfile.

@Test
void testV1Lockfile() throws IOException {
    File lockfile = FunctionalTestFiles.asFile("/yarn/lockfilev1/yarn.lock");
    List<String> yarnLockLines = FileUtils.readLines(lockfile, StandardCharsets.UTF_8);
    Assertions.assertTrue(lockfile.exists());
    YarnLockLineAnalyzer yarnLockLineAnalyzer = new YarnLockLineAnalyzer();
    YarnLockDependencySpecParser yarnLockDependencySpecParser = new YarnLockDependencySpecParser(yarnLockLineAnalyzer);
    YarnLockEntrySectionParserSet yarnLockEntryElementParser = new YarnLockEntrySectionParserSet(yarnLockLineAnalyzer, yarnLockDependencySpecParser);
    YarnLockEntryParser yarnLockEntryParser = new YarnLockEntryParser(yarnLockLineAnalyzer, yarnLockEntryElementParser);
    YarnLockParser yarnLockParser = new YarnLockParser(yarnLockEntryParser);
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockLines);
    Assertions.assertEquals(4238, yarnLock.getEntries().size());
    Assertions.assertEquals("zwitch", yarnLock.getEntries().get(4237).getIds().get(0).getName());
    Assertions.assertEquals("^1.0.0", yarnLock.getEntries().get(4237).getIds().get(0).getVersion());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockDependencySpecParser(com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser) YarnLockEntrySectionParserSet(com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) YarnLockEntryParser(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser) YarnLockLineAnalyzer(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with YarnLockParser

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

the class YarnLockParserTest method testSkipIrrelevantStuff.

@Test
void testSkipIrrelevantStuff() {
    List<String> yarnLockText = Arrays.asList("#", "", "any-root-dep@1:", "  ignoredelement1", // must have a version to create an entry
    "  version: 1.0.0", "  ignoredelement2", "  dependencies:", "    some-peer: ^10.0.0", "  ignoredelement3", "#", "");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertEquals(1, yarnLock.getEntries().size());
    YarnLockEntry first = yarnLock.getEntries().get(0);
    Assertions.assertEquals("1.0.0", first.getVersion());
    Assertions.assertEquals(1, first.getDependencies().size());
    YarnLockDependency dep = first.getDependencies().get(0);
    Assertions.assertEquals("some-peer", dep.getName());
    Assertions.assertEquals("^10.0.0", dep.getVersion());
    Assertions.assertFalse(dep.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 3 with YarnLockParser

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

the class YarnLockParserTest method testThatYarnLockIsParsedCorrectlyToMap.

@Test
void testThatYarnLockIsParsedCorrectlyToMap() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.");
    yarnLockText.add("# yarn lockfile v1");
    yarnLockText.add("");
    yarnLockText.add("");
    yarnLockText.add("async@0.9.0:");
    yarnLockText.add("  version \"0.9.0\"");
    yarnLockText.add("  resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/async/-/async-0.9.0.tgz#ac3613b1da9bed1b47510bb4651b8931e47146c7\"");
    yarnLockText.add("colors@~1.0.3:");
    yarnLockText.add("  version \"1.0.3\"");
    yarnLockText.add("  resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b\"");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    assertEntry(yarnLock, "async", "0.9.0", "0.9.0");
    assertEntry(yarnLock, "colors", "~1.0.3", "1.0.3");
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 4 with YarnLockParser

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

the class YarnLockParserTest method createYarnLockParser.

@NotNull
private YarnLockParser createYarnLockParser() {
    YarnLockLineAnalyzer lineAnalyzer = new YarnLockLineAnalyzer();
    YarnLockDependencySpecParser yarnLockDependencySpecParser = new YarnLockDependencySpecParser(lineAnalyzer);
    YarnLockEntrySectionParserSet yarnLockEntryElementParser = new YarnLockEntrySectionParserSet(lineAnalyzer, yarnLockDependencySpecParser);
    YarnLockEntryParser entryParser = new YarnLockEntryParser(lineAnalyzer, yarnLockEntryElementParser);
    YarnLockParser yarnLockParser = new YarnLockParser(entryParser);
    return yarnLockParser;
}
Also used : YarnLockDependencySpecParser(com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser) YarnLockEntrySectionParserSet(com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) YarnLockEntryParser(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser) YarnLockLineAnalyzer(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with YarnLockParser

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

the class YarnLockParserTest method testParsingNamesWithAtSymbolSlash.

@Test
void testParsingNamesWithAtSymbolSlash() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.");
    yarnLockText.add("# yarn lockfile v1");
    yarnLockText.add("");
    yarnLockText.add("");
    yarnLockText.add("\"@apollo/client@^3.1.3\", \"@apollo/client@^3.1.4\", \"@apollo/client@^3.3.6\":\n");
    yarnLockText.add("  version \"3.3.6\"\n");
    yarnLockText.add("  resolved \"https://registry.yarnpkg.com/@apollo/client/-/client-3.3.6.tgz#f359646308167f38d5bc498dfc2344c888400093\"\n");
    yarnLockText.add("  integrity sha512-XSm/STyNS8aHdDigLLACKNMHwI0qaQmEHWHtTP+jHe/E1wZRnn66VZMMgwKLy2V4uHISHfmiZ4KpUKDPeJAKqg==\n");
    yarnLockText.add("  dependencies:\n");
    yarnLockText.add("    \"@graphql-typed-document-node/core\" \"^3.0.0\"\n");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    YarnLockDependency dep = new YarnLockDependency("@graphql-typed-document-node/core", "^3.0.0", false);
    assertEntry(yarnLock, "@apollo/client", "^3.1.3", "3.3.6", dep);
}
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)

Aggregations

YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)13 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)11 Test (org.junit.jupiter.api.Test)11 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)10 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)8 ArrayList (java.util.ArrayList)6 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)4 YarnLockLineAnalyzer (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer)3 YarnLockEntryParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser)3 YarnLockDependencySpecParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser)3 YarnLockEntrySectionParserSet (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet)3 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1