Search in sources :

Example 1 with IllegalBinaryStateException

use of org.eclipse.n4js.binaries.IllegalBinaryStateException 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)

Example 2 with IllegalBinaryStateException

use of org.eclipse.n4js.binaries.IllegalBinaryStateException in project n4js by eclipse.

the class NpmManager method checkNPM.

/**
 * Checks the npm binary.
 */
private IStatus checkNPM() {
    final NpmBinary npmBinary = npmBinaryProvider.get();
    final IStatus npmBinaryStatus = npmBinary.validate();
    if (!npmBinaryStatus.isOK()) {
        return statusHelper.createError("npm binary invalid", new IllegalBinaryStateException(npmBinary, npmBinaryStatus));
    }
    return statusHelper.OK();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IllegalBinaryStateException(org.eclipse.n4js.binaries.IllegalBinaryStateException) NpmBinary(org.eclipse.n4js.binaries.nodejs.NpmBinary)

Aggregations

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