]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.maps.server/src/org/simantics/district/maps/server/NodeJS.java
Unzip installed maps server at install time
[simantics/district.git] / org.simantics.maps.server / src / org / simantics / district / maps / server / NodeJS.java
index 5bbb5ec72a19e5d87f0ce5a7cc6f1fa5b99cd4a9..82fd4e54dc37555391968c76cdc3ab66bef9e890 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.district.maps.server;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -10,14 +11,18 @@ import java.util.List;
 import java.util.concurrent.TimeoutException;
 
 import org.simantics.district.maps.server.utils.EnvUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.zeroturnaround.exec.InvalidExitValueException;
 import org.zeroturnaround.exec.ProcessExecutor;
+import org.zeroturnaround.exec.stream.slf4j.Slf4jInfoOutputStream;
 import org.zeroturnaround.exec.stream.slf4j.Slf4jStream;
 
 public class NodeJS {
 
     public static final String NODEJS_VERSION = "v4.8.0";
-    
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeJS.class);
     private static final String NODE = "node";
     
     private static Path nodeJSFolder() throws IOException, URISyntaxException {
@@ -49,10 +54,20 @@ public class NodeJS {
     }
 
     public static int npm(OutputStream output, String... args) throws InvalidExitValueException, IOException, InterruptedException, TimeoutException, URISyntaxException {
+        LOGGER.info("Executing npm with args {}", Arrays.toString(args));
         List<String> actualArgs = new ArrayList<>();
         actualArgs.add(npmExecutable().toString());
         actualArgs.addAll(Arrays.asList(args));
-        ProcessExecutor exec = new ProcessExecutor().command(actualArgs).redirectOutput(Slf4jStream.ofCaller().asInfo()).destroyOnExit();
+        ProcessExecutor exec = new ProcessExecutor().command(actualArgs).redirectOutput(new Slf4jInfoOutputStream(LOGGER) {
+            
+            @Override
+            protected void processLine(String line) {
+                // Convert to UTF-8 string
+                String utf8Line = new String(line.getBytes(), StandardCharsets.UTF_8);
+                log.info(utf8Line);
+            }
+        }).destroyOnExit();
+        
         if (output != null)
             exec.redirectOutputAlsoTo(output);
         return exec.execute().getExitValue();