Search in sources :

Example 1 with YarnLock

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

the class YarnLockExtractor method extract.

public Extraction extract(File projectDir, File yarnLockFile, File rootPackageJsonFile) {
    try {
        NullSafePackageJson rootPackageJson = packageJsonFiles.read(rootPackageJsonFile);
        String projectName = rootPackageJson.getName().orElse("null");
        logger.debug("Extracting Yarn project {} in {}", projectName, projectDir.getAbsolutePath());
        YarnLock yarnLock = readYarnLock(yarnLockFile);
        YarnWorkspaces workspaceData = collectWorkspaceData(projectDir);
        ExcludedIncludedWildcardFilter workspacesFilter = deriveExcludedIncludedWildcardFilter();
        YarnResult yarnResult = yarnPackager.generateCodeLocation(rootPackageJson, workspaceData, yarnLock, new ArrayList<>(), workspacesFilter);
        Optional<Exception> yarnException = yarnResult.getException();
        if (yarnException.isPresent()) {
            throw yarnException.get();
        }
        return new Extraction.Builder().projectName(yarnResult.getProjectName()).projectVersion(yarnResult.getProjectVersionName()).success(yarnResult.getCodeLocations()).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException)

Example 2 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock 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 3 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock 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 4 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock 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 5 with YarnLock

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

YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)14 Test (org.junit.jupiter.api.Test)12 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)11 YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)11 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)10 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)6 ArrayList (java.util.ArrayList)6 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)3 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)2 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)2 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)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 YarnLockLineAnalyzer (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer)1 YarnLockEntryParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser)1 YarnLockDependencySpecParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser)1 YarnLockEntrySectionParserSet (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet)1