Search in sources :

Example 1 with YarnWorkspaceProject

use of org.eclipse.n4js.tests.codegen.YarnWorkspaceProject in project n4js by eclipse.

the class TestWorkspaceManager method createYarnProject.

private Project createYarnProject(Map<String, ? extends Map<String, ? extends CharSequence>> projectsModulesContents) {
    YarnWorkspaceProject yarnProject = new YarnWorkspaceProject(YARN_TEST_PROJECT, VENDOR, VENDOR_NAME);
    Multimap<String, String> dependencies = HashMultimap.create();
    for (String projectNameWithSelector : projectsModulesContents.keySet()) {
        Map<String, ? extends CharSequence> moduleContents = projectsModulesContents.get(projectNameWithSelector);
        String prjName = projectNameWithSelector;
        if (prjName.startsWith(CFG_NODE_MODULES)) {
            prjName = prjName.substring(CFG_NODE_MODULES.length());
            Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.NodeModule);
            yarnProject.addNodeModuleProject(project);
        } else if (prjName.startsWith(CFG_WORKSPACES_FOLDER)) {
            int idxCFG = CFG_WORKSPACES_FOLDER.length();
            int idxSlash = prjName.indexOf("/");
            String wsFolder = prjName.substring(idxCFG, idxSlash);
            prjName = prjName.substring(idxSlash + 1);
            Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.Member);
            yarnProject.addMemberProject(wsFolder, project);
        } else if (prjName.equals(CFG_YARN_PROJECT)) {
            if (moduleContents.containsKey(N4JSGlobals.PACKAGE_JSON)) {
                yarnProject.setProjectDescriptionContent(moduleContents.get(N4JSGlobals.PACKAGE_JSON).toString());
            }
        } else {
            Project project = createSimpleProject(prjName, moduleContents, dependencies, ProjectKind.Member);
            yarnProject.addMemberProject(project);
        }
    }
    setDependencies(yarnProject, dependencies);
    // apply default values
    boolean haveMemberRequiringN4jsRuntime = IterableExtensions.exists(yarnProject.getMemberProjects(), p -> N4JSGlobals.PROJECT_TYPES_REQUIRING_N4JS_RUNTIME.contains(p.getType()));
    if (haveMemberRequiringN4jsRuntime) {
        if (yarnProject.getNodeModuleProject(N4JS_RUNTIME) == null) {
            yarnProject.addNodeModuleProject(N4JS_RUNTIME_FAKE);
        }
    }
    return yarnProject;
}
Also used : YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) Project(org.eclipse.n4js.tests.codegen.Project) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject)

Example 2 with YarnWorkspaceProject

use of org.eclipse.n4js.tests.codegen.YarnWorkspaceProject in project n4js by eclipse.

the class TestWorkspaceManager method getProjectRootFailSafe.

private File getProjectRootFailSafe(String projectName) {
    if (!isCreated()) {
        return null;
    }
    Path projectNamePath = projectNameToRelativePath(projectName);
    Path createdProjectNamePath = projectNameToRelativePath(createdProject.getName());
    Path createdProjectPath = getRoot().toPath().resolve(createdProjectNamePath);
    if (projectName.equals(createdProject.getName())) {
        return createdProjectPath.toFile();
    }
    if (createdProject instanceof YarnWorkspaceProject) {
        Project containedProject = ((YarnWorkspaceProject) createdProject).getMemberProject(projectName);
        if (containedProject != null) {
            return createdProjectPath.resolve(YarnWorkspaceProject.PACKAGES).resolve(projectNamePath).toFile();
        }
    }
    Project nodeModuleProject = createdProject.getNodeModuleProject(projectName);
    if (nodeModuleProject != null) {
        return createdProjectPath.resolve(N4JSGlobals.NODE_MODULES).resolve(projectNamePath).toFile();
    }
    if (createdProject instanceof YarnWorkspaceProject) {
        for (Project containedProject : ((YarnWorkspaceProject) createdProject).getMemberProjects()) {
            Project containedNodeModuleProject = createdProject.getNodeModuleProject(projectName);
            if (containedNodeModuleProject != null) {
                Path containedProjectNamePath = projectNameToRelativePath(containedProject.getName());
                return createdProjectPath.resolve(YarnWorkspaceProject.PACKAGES).resolve(containedProjectNamePath).resolve(N4JSGlobals.NODE_MODULES).resolve(projectNamePath).toFile();
            }
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) Project(org.eclipse.n4js.tests.codegen.Project) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject)

Example 3 with YarnWorkspaceProject

use of org.eclipse.n4js.tests.codegen.YarnWorkspaceProject in project n4js by eclipse.

the class XtSetupParser method parseWorkspace.

private static XtWorkspace parseWorkspace(TokenStream tokens, File xtFile, String xtFileContent) {
    WorkspaceBuilder builder = new WorkspaceBuilder(new BuilderInfo());
    YarnProjectBuilder yarnProjectBuilder = builder.addYarnProject(TestWorkspaceManager.YARN_TEST_PROJECT);
    LOOP: while (tokens.hasNext()) {
        switch(tokens.next()) {
            case "Project":
            case "JavaProject":
                parseProject(tokens, xtFile, xtFileContent, yarnProjectBuilder);
                break;
            case "}":
                break LOOP;
            default:
                Preconditions.checkState(false, ERROR + "Unexpected token in Workspace: " + tokens.lookLast() + " in file " + xtFile.getPath());
        }
    }
    XtWorkspace xtWorkspace = builder.build(new XtWorkspace());
    if (xtWorkspace.getProjects().size() == 1 && xtWorkspace.getProjects().get(0) instanceof YarnWorkspaceProject && ((YarnWorkspaceProject) xtWorkspace.getProjects().get(0)).getMemberProjects().size() == 1) {
        YarnWorkspaceProject yarnWorkspaceProject = (YarnWorkspaceProject) xtWorkspace.getProjects().get(0);
        if (yarnWorkspaceProject.getMemberProjects().size() == 1) {
            Project project = yarnWorkspaceProject.getMemberProjects().iterator().next();
            xtWorkspace.clearProjects();
            xtWorkspace.addProject(project);
        }
    }
    xtWorkspace.moduleNameOfXtFile = ((BuilderInfo) builder.builderInfo).moduleNameOfXtFile;
    return xtWorkspace;
}
Also used : WorkspaceBuilder(org.eclipse.n4js.tests.codegen.WorkspaceBuilder) YarnProjectBuilder(org.eclipse.n4js.tests.codegen.WorkspaceBuilder.YarnProjectBuilder) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) Project(org.eclipse.n4js.tests.codegen.Project) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject)

Example 4 with YarnWorkspaceProject

use of org.eclipse.n4js.tests.codegen.YarnWorkspaceProject in project n4js by eclipse.

the class TestWorkspaceManager method getProjectRootContaining.

/**
 * For this method, it is sufficient if the given file is located somewhere inside a project; strict
 * {@link SourceFolderSnapshot#contains(URI) containment in a source folder} is *not* required.
 *
 * @return the root folder of the project containing the given file or <code>null</code>.
 */
public File getProjectRootContaining(File file) {
    List<Project> allProjects = new ArrayList<>();
    if (createdProject instanceof YarnWorkspaceProject) {
        allProjects.addAll(((YarnWorkspaceProject) createdProject).getMemberProjects());
    } else {
        allProjects.add(createdProject);
    }
    Path filePath = file.toPath();
    Path resultPath = null;
    for (Project project : allProjects) {
        File projectRoot = getProjectRoot(project.getName());
        if (projectRoot != null) {
            Path projectRootPath = projectRoot.toPath();
            if (filePath.startsWith(projectRootPath)) {
                if (resultPath == null || projectRootPath.getNameCount() > resultPath.getNameCount()) {
                    resultPath = projectRootPath;
                }
            }
        }
    }
    return resultPath != null ? resultPath.toFile() : null;
}
Also used : Path(java.nio.file.Path) Project(org.eclipse.n4js.tests.codegen.Project) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with YarnWorkspaceProject

use of org.eclipse.n4js.tests.codegen.YarnWorkspaceProject in project n4js by eclipse.

the class TestWorkspaceManager method setDependencies.

private void setDependencies(YarnWorkspaceProject yarnProject, Multimap<String, String> dependencies) {
    for (String projectName : dependencies.keySet()) {
        Collection<String> projectDependencies = dependencies.get(projectName);
        Project project = yarnProject.getMemberProject(projectName);
        if (project == null) {
            project = yarnProject.getNodeModuleProject(projectName);
            if (project == null) {
                throw new IllegalStateException("unknown project: " + projectName);
            }
        }
        for (String projectDependency : projectDependencies) {
            Project dependency = yarnProject.getMemberProject(projectDependency);
            if (dependency == null) {
                dependency = yarnProject.getNodeModuleProject(projectDependency);
                if (dependency == null) {
                    // -> this might be a valid test case, so ignore this problem
                    continue;
                }
            }
            project.addProjectDependency(dependency.getName());
        }
    }
}
Also used : Project(org.eclipse.n4js.tests.codegen.Project) YarnWorkspaceProject(org.eclipse.n4js.tests.codegen.YarnWorkspaceProject)

Aggregations

Project (org.eclipse.n4js.tests.codegen.Project)5 YarnWorkspaceProject (org.eclipse.n4js.tests.codegen.YarnWorkspaceProject)5 Path (java.nio.file.Path)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 WorkspaceBuilder (org.eclipse.n4js.tests.codegen.WorkspaceBuilder)1 YarnProjectBuilder (org.eclipse.n4js.tests.codegen.WorkspaceBuilder.YarnProjectBuilder)1