diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeAndNPMInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeAndNPMInstaller.java index 548065a84..d7df71283 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeAndNPMInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeAndNPMInstaller.java @@ -77,7 +77,7 @@ private boolean nodeIsAlreadyInstalled() { NodeExecutorConfig executorConfig = new InstallNodeExecutorConfig(config); File nodeFile = executorConfig.getNodePath(); if(nodeFile.exists()){ - final String version = new NodeExecutor(executorConfig, Arrays.asList("--version")).executeAndGetResult(); + final String version = new NodeExecutor(executorConfig, Arrays.asList("--version")).executeAndGetResult(logger); if(version.equals(nodeVersion)){ logger.info("Node " + version + " is already installed."); diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeExecutor.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeExecutor.java index e5101cdb3..8d15284f6 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeExecutor.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeExecutor.java @@ -12,15 +12,12 @@ public NodeExecutor(NodeExecutorConfig config, List arguments){ final String node = config.getNodePath().getAbsolutePath(); List localPaths = new ArrayList(); localPaths.add(config.getNodePath().getParent()); - this.executor = new ProcessExecutor( - config.getWorkingDirectory(), - localPaths, - Utils.prepend(node, arguments), - config.getPlatform()); + this.executor = new ProcessExecutor(config.getWorkingDirectory(), localPaths, node, arguments, + config.getPlatform()); } - public String executeAndGetResult() throws ProcessExecutionException { - return executor.executeAndGetResult(); + public String executeAndGetResult(final Logger logger) throws ProcessExecutionException { + return executor.executeAndGetResult(logger); } public int executeAndRedirectOutput(final Logger logger) throws ProcessExecutionException { diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ProcessExecutor.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ProcessExecutor.java index 3931a1f1a..ab5e297c3 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ProcessExecutor.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ProcessExecutor.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -36,22 +35,23 @@ final class ProcessExecutor { private CommandLine commandLine; private final Executor executor; - public ProcessExecutor(File workingDirectory, List paths, List command, Platform platform) { - this(workingDirectory, paths, command, platform, 0); + public ProcessExecutor(File workingDirectory, List paths, String executable, List arguments, + Platform platform) { + this(workingDirectory, paths, executable, arguments, platform, 0); } - public ProcessExecutor(File workingDirectory, List paths, List command, Platform platform, - long timeoutInSeconds) { + public ProcessExecutor(File workingDirectory, List paths, String executable, List arguments, + Platform platform, long timeoutInSeconds) { this.environment = createEnvironment(paths, platform); - this.commandLine = createCommandLine(command); + this.commandLine = createCommandLine(executable, arguments); this.executor = createExecutor(workingDirectory, timeoutInSeconds); } - public String executeAndGetResult() throws ProcessExecutionException { + public String executeAndGetResult(final Logger logger) throws ProcessExecutionException { ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); - int exitValue = execute(stdout, stderr); + int exitValue = execute(logger, stdout, stderr); if (exitValue == 0) { return stdout.toString().trim(); } else { @@ -63,15 +63,20 @@ public int executeAndRedirectOutput(final Logger logger) throws ProcessExecution OutputStream stdout = new LoggerOutputStream(logger, 0); OutputStream stderr = new LoggerOutputStream(logger, 1); - return execute(stdout, stderr); + return execute(logger, stdout, stderr); } - private int execute(OutputStream stdout, OutputStream stderr) throws ProcessExecutionException { + private int execute(final Logger logger, final OutputStream stdout, final OutputStream stderr) + throws ProcessExecutionException { + logger.debug("Executing command line {}", commandLine); try { ExecuteStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr); executor.setStreamHandler(streamHandler); - return executor.execute(commandLine, environment); + int exitValue = executor.execute(commandLine, environment); + logger.debug("Exit value {}", exitValue); + + return exitValue; } catch (ExecuteException e) { if (executor.getWatchdog() != null && executor.getWatchdog().killedProcess()) { throw new ProcessExecutionException("Process killed after timeout"); @@ -107,12 +112,11 @@ private Map createEnvironment(List paths, Platform platf return environment; } - private CommandLine createCommandLine(List command) { - Iterator args = command.iterator(); - CommandLine commmandLine = new CommandLine(args.next()); + private CommandLine createCommandLine(String executable, List arguments) { + CommandLine commmandLine = new CommandLine(executable); - while(args.hasNext()) { - commmandLine.addArgument(args.next()); + for (String argument : arguments) { + commmandLine.addArgument(argument); } return commmandLine;