From fab0b23a6127c7d7081556d59dcf1080d043dd90 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 21 Jun 2018 12:58:42 +0300 Subject: [PATCH] Unzip installed maps server at install time gitlab #1 Change-Id: I7de0ad8d8cbdb3e2d5f5e18503c42fe4899d5964 --- .../META-INF/MANIFEST.MF | 1 + .../district/maps/server/NodeJS.java | 19 +++++++++++++++++-- .../maps/server/TileserverMapnik.java | 12 ++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/org.simantics.maps.server/META-INF/MANIFEST.MF b/org.simantics.maps.server/META-INF/MANIFEST.MF index 7f773230..fb5c7779 100644 --- a/org.simantics.maps.server/META-INF/MANIFEST.MF +++ b/org.simantics.maps.server/META-INF/MANIFEST.MF @@ -23,3 +23,4 @@ Bundle-ClassPath: ., lib/zt-process-killer-1.6.jar Export-Package: org.simantics.district.maps.server, org.simantics.district.maps.server.prefs +Eclipse-BundleShape: dir diff --git a/org.simantics.maps.server/src/org/simantics/district/maps/server/NodeJS.java b/org.simantics.maps.server/src/org/simantics/district/maps/server/NodeJS.java index 5bbb5ec7..82fd4e54 100644 --- a/org.simantics.maps.server/src/org/simantics/district/maps/server/NodeJS.java +++ b/org.simantics.maps.server/src/org/simantics/district/maps/server/NodeJS.java @@ -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 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(); diff --git a/org.simantics.maps.server/src/org/simantics/district/maps/server/TileserverMapnik.java b/org.simantics.maps.server/src/org/simantics/district/maps/server/TileserverMapnik.java index 5b1e735c..b047626a 100644 --- a/org.simantics.maps.server/src/org/simantics/district/maps/server/TileserverMapnik.java +++ b/org.simantics.maps.server/src/org/simantics/district/maps/server/TileserverMapnik.java @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; import org.zeroturnaround.exec.ProcessExecutor; import org.zeroturnaround.exec.StartedProcess; -import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; +import org.zeroturnaround.exec.stream.slf4j.Slf4jDebugOutputStream; import org.zeroturnaround.process.PidProcess; import org.zeroturnaround.process.PidUtil; import org.zeroturnaround.process.Processes; @@ -76,7 +76,15 @@ public class TileserverMapnik { StartedProcess startedProcess = new ProcessExecutor().directory(serverRoot.resolve("tileserver-mapnik").toFile()).destroyOnExit().environment(getEnv()) .command(NodeJS.executable().toString(), getTessera().toString(), "-c", getConfigJson().toString(), "-p", Integer.toString(MapsServerPreferences.defaultPort())) - .redirectOutput(Slf4jStream.ofCaller().asDebug()).start(); + .redirectOutput(new Slf4jDebugOutputStream(LOGGER) { + + @Override + protected void processLine(String line) { + // Convert to UTF-8 string + String utf8Line = new String(line.getBytes(), StandardCharsets.UTF_8); + log.debug(utf8Line); + } + }).start(); Process nativeProcess = startedProcess.getProcess(); process = Processes.newStandardProcess(nativeProcess); -- 2.45.2