Search in sources :

Example 1 with NodeJsBinary

use of org.eclipse.n4js.binaries.nodejs.NodeJsBinary in project n4js by eclipse.

the class NodeRunner method run.

@Override
public Process run(RunConfiguration runConfig, IExecutor executor) {
    final NodeJsBinary nodeJsBinary = nodeJsBinaryProvider.get();
    final IStatus status = nodeJsBinary.validate();
    if (!status.isOK()) {
        Exceptions.sneakyThrow(new IllegalBinaryStateException(nodeJsBinary, status));
    }
    Process process = null;
    String[] cmds = new String[0];
    try {
        NodeRunOptions runOptions = createRunOptions(runConfig);
        Path workingDirectory = FileUtils.createTempDirectory("N4JSNodeRun");
        NodeEngineCommandBuilder cb = commandBuilderProvider.get();
        cmds = cb.createCmds(runOptions, workingDirectory);
        final Collection<String> paths = newLinkedHashSet();
        paths.addAll(newArrayList(Splitter.on(NODE_PATH_SEP).omitEmptyStrings().trimResults().split(runConfig.getCustomEnginePath())));
        if (runConfig.getAdditionalPath() != null && !runConfig.getAdditionalPath().isEmpty())
            paths.add(runConfig.getAdditionalPath());
        paths.add(workingDirectory.resolve("node_modules").toAbsolutePath().toString());
        String nodePaths = on(NODE_PATH_SEP).join(paths);
        Map<String, String> env = new LinkedHashMap<>();
        env.put(NODE_PATH, nodePaths);
        env = nodeJsBinary.updateEnvironment(env);
        process = executor.exec(cmds, workingDirectory.toFile(), env);
    } catch (IOException | RuntimeException | ExecutionException e) {
        LOGGER.error(e);
    }
    return process;
}
Also used : Path(java.nio.file.Path) IStatus(org.eclipse.core.runtime.IStatus) IllegalBinaryStateException(org.eclipse.n4js.binaries.IllegalBinaryStateException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) NodeJsBinary(org.eclipse.n4js.binaries.nodejs.NodeJsBinary) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 IStatus (org.eclipse.core.runtime.IStatus)1 IllegalBinaryStateException (org.eclipse.n4js.binaries.IllegalBinaryStateException)1 NodeJsBinary (org.eclipse.n4js.binaries.nodejs.NodeJsBinary)1