use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.
the class YarnLockDependencySpecParser method parse.
public Optional<YarnLockDependency> parse(String dependencySpec, boolean optional) {
StringTokenizer tokenizer = TokenizerFactory.createDependencySpecTokenizer(dependencySpec);
String name = yarnLockLineAnalyzer.unquote(tokenizer.nextToken());
// version formats vary; see YarnLockDependencySpecParserTest
String version = yarnLockLineAnalyzer.unquote(tokenizer.nextToken("").trim());
if (version.startsWith(":")) {
version = version.substring(1).trim();
}
version = yarnLockLineAnalyzer.unquote(version);
logger.trace("\tdependency: name: {}, version: {} (optional: {})", name, version, optional);
if (!hasSkippableProtocol(name, version)) {
return Optional.of(new YarnLockDependency(name, version, optional));
}
return Optional.empty();
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.
the class YarnLockParserTest method testThatYarnLockVersionsResolveAsExpected.
@Test
void testThatYarnLockVersionsResolveAsExpected() {
List<String> yarnLockText = new ArrayList<>();
yarnLockText.add("http-proxy@^1.8.1:");
yarnLockText.add(" version \"1.16.2\"");
yarnLockText.add(" resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/http-proxy/-/http-proxy-1.16.2.tgz#06dff292952bf64dbe8471fa9df73066d4f37742\"");
yarnLockText.add(" dependencies:");
yarnLockText.add(" eventemitter3 \"1.x.x\"");
yarnLockText.add(" requires-port \"1.x.x\"");
yarnLockText.add("http-server@^0.9.0:");
yarnLockText.add(" version \"0.9.0\"");
yarnLockText.add(" resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/http-server/-/http-server-0.9.0.tgz#8f1b06bdc733618d4dc42831c7ba1aff4e06001a\"");
YarnLockParser yarnLockParser = createYarnLockParser();
YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
assertEntry(yarnLock, "http-proxy", "^1.8.1", "1.16.2", new YarnLockDependency("eventemitter3", "1.x.x", false), new YarnLockDependency("requires-port", "1.x.x", false));
assertEntry(yarnLock, "http-server", "^0.9.0", "0.9.0");
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.
the class YarnLockParserTest method testThatDependenciesWithQuotesAreResolvedCorrectly.
@Test
void testThatDependenciesWithQuotesAreResolvedCorrectly() {
List<String> yarnLockText = new ArrayList<>();
yarnLockText.add("\"cssstyle@>= 0.2.37 < 0.3.0\":");
yarnLockText.add(" version \"0.2.37\"");
yarnLockText.add(" resolved \"http://nexus/nexus3/repository/npm-all/cssstyle/-/cssstyle-0.2.37.tgz#541097234cb2513c83ceed3acddc27ff27987d54\"");
yarnLockText.add(" dependencies:");
yarnLockText.add(" cssom \"0.3.x\"");
YarnLockParser yarnLockParser = createYarnLockParser();
YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
assertEntry(yarnLock, "cssstyle", ">= 0.2.37 < 0.3.0", "0.2.37", new YarnLockDependency("cssom", "0.3.x", false));
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.
the class YarnLockParserTest method testThatMultipleDepsPerLineCanBeHandledCorrectly.
@Test
void testThatMultipleDepsPerLineCanBeHandledCorrectly() {
List<String> yarnLockText = new ArrayList<>();
yarnLockText.add("debug@2, debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@~2.6.4, debug@~2.6.6:");
yarnLockText.add(" version \"2.6.9\"");
yarnLockText.add(" resolved \"http://nexus/nexus3/repository/npm-all/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f\"");
yarnLockText.add(" dependencies:");
yarnLockText.add(" ms \"2.0.0\"");
YarnLockParser yarnLockParser = createYarnLockParser();
YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
assertEntry(yarnLock, "debug", "2", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
assertEntry(yarnLock, "debug", "2.6.9", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
assertEntry(yarnLock, "debug", "^2.2.0", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
assertEntry(yarnLock, "debug", "^2.3.3", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
assertEntry(yarnLock, "debug", "~2.6.4", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
assertEntry(yarnLock, "debug", "~2.6.6", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency in project synopsys-detect by blackducksoftware.
the class YarnLockParserTest method testThatYarnParsesSemiColon.
@Test
void testThatYarnParsesSemiColon() {
List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
" version: 1.0.0", " dependencies:", " some-peer: ^10.0.0");
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());
}
Aggregations