use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnLockHeaderSectionParser method parseSection.
@Override
public int parseSection(YarnLockEntryBuilder entryBuilder, List<String> yarnLockLines, int lineIndexOfStartOfSection) {
String line = yarnLockLines.get(lineIndexOfStartOfSection).trim();
line = StringUtils.removeEnd(line, ":").trim();
line = yarnLockLineAnalyzer.unquote(line);
if ("__metadata".equals(line)) {
entryBuilder.setMetadataEntry(true);
} else {
StringTokenizer tokenizer = TokenizerFactory.createHeaderTokenizer(line);
while (tokenizer.hasMoreTokens()) {
String rawEntryString = tokenizer.nextToken().trim();
String entryString = StringUtils.removeEnd(rawEntryString, ":").trim();
String unquotedEntryString = yarnLockLineAnalyzer.unquote(entryString);
YarnLockEntryId entry = parseSingleEntry(unquotedEntryString);
logger.trace("Entry header ID: name: {}, version: {}", entry.getName(), entry.getVersion());
entryBuilder.addId(entry);
}
}
return lineIndexOfStartOfSection;
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnTransformer method buildGraphForProjectOrWorkspace.
private DependencyGraph buildGraphForProjectOrWorkspace(YarnLockResult yarnLockResult, NullSafePackageJson projectOrWorkspacePackageJson, List<NameVersion> externalDependencies) throws MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
addRootNodesToGraph(graphBuilder, projectOrWorkspacePackageJson, yarnLockResult.getWorkspaceData());
for (YarnLockEntry entry : yarnLockResult.getYarnLock().getEntries()) {
for (YarnLockEntryId entryId : entry.getIds()) {
LazyId id = generateComponentDependencyId(entryId.getName(), entryId.getVersion());
graphBuilder.setDependencyInfo(id, entryId.getName(), entry.getVersion(), generateComponentExternalId(entryId.getName(), entry.getVersion()));
addYarnLockDependenciesToGraph(yarnLockResult, graphBuilder, entry, id);
}
}
return graphBuilder.build(getLazyBuilderHandler(externalDependencies));
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnLockParserTest method assertEntry.
void assertEntry(YarnLock yarnLock, String idName, String idVersion, String resolvedVersion, YarnLockDependency... dependencies) {
boolean found = false;
for (YarnLockEntry entry : yarnLock.getEntries()) {
for (YarnLockEntryId entryId : entry.getIds()) {
if (entryId.getName().equals(idName) && entryId.getVersion().equals(idVersion)) {
found = true;
assertEquals(resolvedVersion, entry.getVersion(), "Yarn entry should have found correct resolved version.");
assertEquals(dependencies.length, entry.getDependencies().size(), "Yarn entry should have found correct number of dependencies.");
for (YarnLockDependency dependency : dependencies) {
boolean dFound = false;
for (YarnLockDependency entryDependency : entry.getDependencies()) {
if (entryDependency.getName().equals(dependency.getName()) && entryDependency.getVersion().equals(dependency.getVersion()) && entryDependency.isOptional() == dependency.isOptional()) {
dFound = true;
break;
}
}
assertTrue(dFound, "Could not find yarn dependency for entry " + idName + " with name " + dependency.getName() + " and version " + dependency.getVersion() + " and optional " + dependency.isOptional() + ".");
}
}
}
}
assertTrue(found, "Could not find yarn lock entry with name " + idName + " and version " + idVersion + ".");
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method buildTestYarnLockResult.
@NotNull
private YarnLockResult buildTestYarnLockResult(List<NameVersion> workspacesThatAreDependencies, List<NameVersion> workspacesThatAreNotDependencies, boolean yarn1project) {
PackageJson rawPackageJson = new PackageJson();
rawPackageJson.dependencies = new HashMap<>();
rawPackageJson.dependencies.put("foo", "fooFuzzyVersion-1.0");
for (NameVersion workspace : workspacesThatAreDependencies) {
rawPackageJson.dependencies.put(workspace.getName(), workspace.getVersion());
}
rawPackageJson.devDependencies.put("bar", "barFuzzyVersion-1.0");
NullSafePackageJson packageJson = new NullSafePackageJson(rawPackageJson);
// yarn.lock: foo and bar both depend on yarn
List<YarnLockEntryId> yarnLockEntryIdsFoo = Collections.singletonList(new YarnLockEntryId("foo", "fooFuzzyVersion-1.0"));
List<YarnLockEntryId> yarnLockEntryIdsBar = Collections.singletonList(new YarnLockEntryId("bar", "barFuzzyVersion-1.0"));
List<YarnLockEntryId> yarnLockEntryIdsYarn = Collections.singletonList(new YarnLockEntryId("yarn", "^1.22.4"));
List<YarnLockDependency> dependencyRefToYarn = Collections.singletonList(new YarnLockDependency("yarn", "^1.22.4", false));
List<YarnLockEntry> yarnLockEntries = new LinkedList<>();
if (!yarn1project) {
List<YarnLockEntryId> projectEntryIds = Collections.singletonList(new YarnLockEntryId("project", "1.0.0"));
List<YarnLockDependency> projectDependencies = new LinkedList<>();
projectDependencies.add(new YarnLockDependency("foo", "fooFuzzyVersion-1.0", false));
projectDependencies.add(new YarnLockDependency("bar", "barFuzzyVersion-1.0", false));
for (NameVersion workspaceThatIsDependency : workspacesThatAreDependencies) {
projectDependencies.add(new YarnLockDependency(workspaceThatIsDependency.getName(), workspaceThatIsDependency.getVersion(), false));
}
yarnLockEntries.add(new YarnLockEntry(false, projectEntryIds, "1.0.0", projectDependencies));
}
Collection<YarnWorkspace> workspacesByName = new LinkedList<>();
List<NameVersion> allWorkspaces = new LinkedList<>(workspacesThatAreDependencies);
allWorkspaces.addAll(workspacesThatAreNotDependencies);
for (NameVersion workspace : allWorkspaces) {
String workspaceDepName = workspace.getName() + WORKSPACE_DEP_SUFFIX;
String workspaceDevDepName = workspace.getName() + "-dev" + WORKSPACE_DEP_SUFFIX;
addWorkspacePackageJson(workspacesByName, workspace, workspaceDepName, workspaceDevDepName);
if (!yarn1project) {
addWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDepName);
}
addDependencyOfWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDepName);
addDependencyOfWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDevDepName);
}
yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsFoo, "1.0", dependencyRefToYarn));
yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsBar, "1.0", dependencyRefToYarn));
yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsYarn, "1.22.5", new LinkedList<>()));
String yarnLockVersion = null;
if (!yarn1project) {
yarnLockVersion = "4";
}
YarnLock yarnLock = new YarnLock(yarnLockVersion, yarn1project, yarnLockEntries);
YarnWorkspaces workspaceData = new YarnWorkspaces(workspacesByName);
return new YarnLockResult(packageJson, workspaceData, yarnLock);
}
use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId in project synopsys-detect by blackducksoftware.
the class YarnLockHeaderSectionParserTest method testParserHandlesMissingSymbol.
@Test
void testParserHandlesMissingSymbol() {
String line = "example, example@1";
List<String> lines = Arrays.asList(line);
Assertions.assertTrue(yarnLockParser.applies(line));
YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
yarnLockParser.parseSection(builder, lines, 0);
// Complete the builder requirements and build the entry
builder.setVersion("testVersion");
YarnLockEntry entry = builder.build();
List<YarnLockEntryId> ids = entry.getIds();
Assertions.assertEquals(2, ids.size());
Assertions.assertEquals("example", ids.get(0).getName());
Assertions.assertEquals("", ids.get(0).getVersion());
Assertions.assertEquals("example", ids.get(1).getName());
Assertions.assertEquals("1", ids.get(1).getVersion());
}
Aggregations