Search in sources :

Example 1 with NodeProcessBuilder

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

the class UpdateShippedCode method runNpmInstall.

private static void runNpmInstall(File workingDirectory) {
    // Initialize DI
    Injector injector = N4JSStandaloneSetup.doSetup();
    final NodeBinaryLocatorHelper locator = injector.getInstance(NodeBinaryLocatorHelper.class);
    final NodeProcessBuilder nodeProcessBuilder = injector.getInstance(NodeProcessBuilder.class);
    println("Running \"" + N4JSGlobals.NPM_INSTALL + "\" in folder \"" + workingDirectory + "\"");
    final String npmBinaryPath = locator.findNodePath();
    if (npmBinaryPath == null || npmBinaryPath.isEmpty()) {
        println("");
        println("Could not identify location of node.");
        println("!!! IMPORTANT !!!");
        println("You have to manually run \"" + N4JSGlobals.NPM_INSTALL + "\" in folder " + workingDirectory);
        println("");
        return;
    }
    println("Identified npm path at: " + npmBinaryPath);
    try {
        String npm = npmBinaryPath + File.separator + N4JSGlobals.NPM;
        final String[] cmd = new String[] { npm, "install" };
        println("Invoking: " + String.join(" ", cmd));
        println("  in working directory: " + workingDirectory);
        ProcessBuilder pb = nodeProcessBuilder.getNpmInstallProcessBuilder(workingDirectory, "", true);
        final Process p = pb.start();
        p.waitFor();
        println(N4JSGlobals.NPM_INSTALL + " finished.");
    } catch (Throwable th) {
        println("Error while running \"" + N4JSGlobals.NPM_INSTALL + "\"");
        th.printStackTrace();
        throw new RuntimeException(th);
    }
}
Also used : Injector(com.google.inject.Injector) NodeProcessBuilder(org.eclipse.n4js.binaries.nodejs.NodeProcessBuilder) NodeBinaryLocatorHelper(org.eclipse.n4js.binaries.nodejs.NodeBinaryLocatorHelper) NodeProcessBuilder(org.eclipse.n4js.binaries.nodejs.NodeProcessBuilder)

Aggregations

Injector (com.google.inject.Injector)1 NodeBinaryLocatorHelper (org.eclipse.n4js.binaries.nodejs.NodeBinaryLocatorHelper)1 NodeProcessBuilder (org.eclipse.n4js.binaries.nodejs.NodeProcessBuilder)1