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;
}
Aggregations