Search in sources :

Example 1 with SystemExitException

use of org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException in project n4js by eclipse.

the class InProcessExecuter method n4jsc.

/**
 * Calls main entry point of N4jsc with the given args. Checks that the given exit code equals the actual exit code
 * of the invocation. Removes {@link N4jscOptions#USAGE} text if desired.
 */
protected CliCompileResult n4jsc(Path workDir, String[] args, CliCompileResult cliResult) {
    Stopwatch sw = Stopwatch.createStarted();
    try {
        setRedirections();
        cliResult.workingDir = workDir.toString();
        N4jscMain.main(workDir, args);
        cliResult.exitCode = 0;
    } catch (SystemExitException e) {
        cliResult.exitCode = e.status;
    } catch (Exception e) {
        cliResult.exception = e;
        if (cliResult.exitCode == ProcessResult.NO_EXIT_CODE) {
            cliResult.exitCode = -1;
        }
    } finally {
        cliResult.duration = sw.stop().elapsed(TimeUnit.MILLISECONDS);
        cliResult.stdOut = systemOutRedirecter.getSystemOut();
        cliResult.errOut = systemOutRedirecter.getSystemErr();
        if (isEnabledBackend) {
            N4jscTestLanguageClient callback = (N4jscTestLanguageClient) N4jscFactory.getLanguageClient();
            cliResult.issues = callback.issues;
            cliResult.errors = callback.errors;
            cliResult.warnings = callback.warnings;
            cliResult.transpiledFiles = callback.transpiledFiles;
            cliResult.deletedFilesCount = callback.getDeletionsCount();
            // save projects
            Injector injector = N4jscFactory.getOrCreateInjector();
            XWorkspaceManager workspaceManager = injector.getInstance(XWorkspaceManager.class);
            Set<? extends ProjectConfigSnapshot> projects = workspaceManager.getProjectConfigs();
            Map<String, String> projectMap = new TreeMap<>();
            for (ProjectConfigSnapshot pConfig : projects) {
                Path projectPath = URIUtils.toPath(pConfig.getPath());
                Path relativeProjectPath = workDir.relativize(projectPath);
                projectMap.put(pConfig.getName(), relativeProjectPath.toString());
            }
            cliResult.projects = projectMap;
        }
        unsetRedirections();
    }
    return cliResult;
}
Also used : Path(java.nio.file.Path) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Injector(com.google.inject.Injector) SystemExitException(org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException) Stopwatch(com.google.common.base.Stopwatch) TreeMap(java.util.TreeMap) SystemExitException(org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException) XWorkspaceManager(org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Injector (com.google.inject.Injector)1 Path (java.nio.file.Path)1 TreeMap (java.util.TreeMap)1 SystemExitException (org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException)1 XWorkspaceManager (org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager)1 ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)1