]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9590 add working dir to log of launched command
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 18 Aug 2017 12:38:23 +0000 (14:38 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 5 Sep 2017 12:24:12 +0000 (14:24 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java

index aa5c6117c00cfcdc3cd4462e2fc4679c50791556..bc19b2a2a6971d6d1fb2e3ce692fb3d690d7d947 100644 (file)
@@ -35,12 +35,12 @@ import java.util.stream.Collectors;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.process.ProcessId;
 import org.sonar.process.command.AbstractCommand;
 import org.sonar.process.command.EsCommand;
 import org.sonar.process.command.JavaCommand;
 import org.sonar.process.sharedmemoryfile.AllProcessesCommands;
 import org.sonar.process.sharedmemoryfile.ProcessCommands;
-import org.sonar.process.ProcessId;
 
 import static java.lang.String.format;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
@@ -82,9 +82,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
     try {
       writeConfFiles(esCommand);
       ProcessBuilder processBuilder = create(esCommand);
-      if (LOG.isInfoEnabled()) {
-        LOG.info("Launch process[{}]: {}", processId.getKey(), String.join(" ", processBuilder.command()));
-      }
+      logLaunchedCommand(esCommand, processBuilder);
 
       process = processBuilder.start();
 
@@ -123,9 +121,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
       ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex());
 
       ProcessBuilder processBuilder = create(javaCommand);
-      if (LOG.isInfoEnabled()) {
-        LOG.info("Launch process[{}]: {}", processId.getKey(), String.join(" ", processBuilder.command()));
-      }
+      logLaunchedCommand(javaCommand, processBuilder);
       process = processBuilder.start();
       return new ProcessCommandsProcessMonitor(process, processId, commands);
     } catch (Exception e) {
@@ -137,6 +133,15 @@ public class ProcessLauncherImpl implements ProcessLauncher {
     }
   }
 
+  private static <T extends AbstractCommand> void logLaunchedCommand(AbstractCommand<T> command, ProcessBuilder processBuilder) {
+    if (LOG.isInfoEnabled()) {
+      LOG.info("Launch process[{}] from [{}]: {}",
+        command.getProcessId(),
+        command.getWorkDir().getAbsolutePath(),
+        String.join(" ", processBuilder.command()));
+    }
+  }
+
   private ProcessBuilder create(EsCommand esCommand) {
     List<String> commands = new ArrayList<>();
     commands.add(esCommand.getExecutable().getAbsolutePath());