use of com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces 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();
}
}
use of com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces 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.workspace.YarnWorkspaces in project synopsys-detect by blackducksoftware.
the class YarnLockExtractor method collectWorkspaceData.
@NotNull
private YarnWorkspaces collectWorkspaceData(File dir) throws IOException {
Collection<YarnWorkspace> curLevelWorkspaces = packageJsonFiles.readWorkspacePackageJsonFiles(dir);
Collection<YarnWorkspace> allWorkspaces = new LinkedList<>(curLevelWorkspaces);
for (YarnWorkspace workspace : curLevelWorkspaces) {
Collection<YarnWorkspace> treeBranchWorkspacePackageJsons = packageJsonFiles.readWorkspacePackageJsonFiles(workspace.getWorkspacePackageJson().getDir());
allWorkspaces.addAll(treeBranchWorkspacePackageJsons);
}
return new YarnWorkspaces(allWorkspaces);
}
Aggregations