use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class NpmLockfilePackager method parseAndTransform.
public NpmPackagerResult parseAndTransform(@Nullable String packageJsonText, String lockFileText, List<NameVersion> externalDependencies) {
PackageJson packageJson = Optional.ofNullable(packageJsonText).map(content -> gson.fromJson(content, PackageJson.class)).orElse(null);
PackageLock packageLock = gson.fromJson(lockFileText, PackageLock.class);
NpmDependencyConverter dependencyConverter = new NpmDependencyConverter(externalIdFactory);
NpmProject project = dependencyConverter.convertLockFile(packageLock, packageJson);
DependencyGraph dependencyGraph = graphTransformer.transform(packageLock, project, externalDependencies);
ExternalId projectId = projectIdTransformer.transform(packageJson, packageLock);
CodeLocation codeLocation = new CodeLocation(dependencyGraph, projectId);
return new NpmPackagerResult(projectId.getName(), projectId.getVersion(), codeLocation);
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class YarnTransformerTest method addWorkspacePackageJson.
private void addWorkspacePackageJson(Collection<YarnWorkspace> workspacesByName, NameVersion workspaceNameVersion, String workspaceDepName, String workspaceDevDepName) {
PackageJson rawWorkspacePackageJson = new PackageJson();
rawWorkspacePackageJson.name = workspaceNameVersion.getName();
rawWorkspacePackageJson.version = workspaceNameVersion.getVersion();
rawWorkspacePackageJson.dependencies = new HashMap<>();
rawWorkspacePackageJson.dependencies.put(workspaceDepName, workspaceNameVersion.getVersion());
rawWorkspacePackageJson.devDependencies.put(workspaceDevDepName, workspaceNameVersion.getVersion());
NullSafePackageJson workspacePackageJson = new NullSafePackageJson(rawWorkspacePackageJson);
WorkspacePackageJson locatedWorkspacePackageJson = new WorkspacePackageJson(null, workspacePackageJson, "packages/" + workspaceNameVersion.getName());
YarnWorkspace workspace = new YarnWorkspace(locatedWorkspacePackageJson);
workspacesByName.add(workspace);
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson 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.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class NpmOutputParserTest method npmCliDependencyFinder.
@Test
public void npmCliDependencyFinder() {
NpmCliParser parser = new NpmCliParser(new ExternalIdFactory(), EnumListFilter.excludeNone());
String testIn = String.join(System.lineSeparator(), Arrays.asList("{", " \"name\": \"node-js\",", " \"version\": \"0.2.0\",", " \"dependencies\": {", " \"upper-case\": {", " \"version\": \"1.1.3\",", " \"from\": \"upper-case@latest\",", " \"resolved\": \"https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz\"", " },", " \"xml2js\": {", " \"version\": \"0.4.17\",", " \"from\": \"xml2js@latest\",", " \"resolved\": \"https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz\",", " \"dependencies\": {", " \"sax\": {", " \"version\": \"1.2.2\",", " \"from\": \"sax@>=0.6.0\",", " \"resolved\": \"https://registry.npmjs.org/sax/-/sax-1.2.2.tgz\"", " },", " \"xmlbuilder\": {", " \"version\": \"4.2.1\",", " \"from\": \"xmlbuilder@>=4.1.0 <5.0.0\",", " \"resolved\": \"https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz\",", " \"dependencies\": {", " \"lodash\": {", " \"version\": \"4.17.4\",", " \"from\": \"lodash@>=4.0.0 <5.0.0\",", " \"resolved\": \"https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz\"", " }", " }", " }", " }", " }", " }", "}"));
NpmDependencyTypeFilter npmDependencyTypeFilter = new NpmDependencyTypeFilter(Collections.emptySet(), Collections.emptySet(), true, true);
PackageJson packageJson = new PackageJson();
NpmPackagerResult result = parser.convertNpmJsonFileToCodeLocation(testIn, packageJson);
Assertions.assertEquals("node-js", result.getProjectName());
Assertions.assertEquals("0.2.0", result.getProjectVersion());
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, result.getCodeLocation().getDependencyGraph());
graphAssert.hasRootSize(2);
graphAssert.hasRootDependency("xml2js", "0.4.17");
graphAssert.hasRootDependency("upper-case", "1.1.3");
graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "xmlbuilder", "4.2.1");
graphAssert.hasParentChildRelationship("xml2js", "0.4.17", "sax", "1.2.2");
graphAssert.hasParentChildRelationship("xmlbuilder", "4.2.1", "lodash", "4.17.4");
}
use of com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson in project synopsys-detect by blackducksoftware.
the class PackageJsonExtractorTest method extractWithNoDevOrPeerDependencies.
@Test
void extractWithNoDevOrPeerDependencies() {
PackageJson packageJson = createPackageJson();
Extraction extraction = createExtractor(NpmDependencyType.DEV, NpmDependencyType.PEER).extract(packageJson);
assertEquals(1, extraction.getCodeLocations().size());
CodeLocation codeLocation = extraction.getCodeLocations().get(0);
DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
graphAssert.hasRootDependency(testDep1);
graphAssert.hasRootDependency(testDep2);
graphAssert.hasNoDependency(testDevDep1);
graphAssert.hasNoDependency(testDevDep2);
graphAssert.hasRootSize(2);
}
Aggregations