Search in sources :

Example 1 with YarnWorkspaces

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();
    }
}
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 YarnWorkspaces

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);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) LinkedList(java.util.LinkedList) YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) WorkspacePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) YarnWorkspace(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with YarnWorkspaces

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);
}
Also used : YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) YarnWorkspace(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)3 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)2 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)2 YarnWorkspace (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace)2 LinkedList (java.util.LinkedList)2 NotNull (org.jetbrains.annotations.NotNull)2 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)1 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)1 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)1 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)1 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)1 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)1 NameVersion (com.synopsys.integration.util.NameVersion)1 IOException (java.io.IOException)1