]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 log stderr of subprocesses
authorEric Hartmann <hartmann.eric@gmail.com>
Tue, 8 Aug 2017 13:58:32 +0000 (15:58 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/application/process/AbstractProcessMonitor.java
server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessMonitor.java
server/sonar-process-monitor/src/main/java/org/sonar/application/process/SQProcess.java
server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java
server/sonar-process-monitor/src/test/java/org/sonar/application/process/SQProcessTest.java

index d5d761234da1dd05f0842f446bafb75f882da60b..f778b6e354f752db709ea7c21cce9be77dbfaec5 100644 (file)
@@ -45,6 +45,10 @@ abstract class AbstractProcessMonitor implements ProcessMonitor {
     return process.getInputStream();
   }
 
+  public InputStream getErrorStream() {
+    return process.getErrorStream();
+  }
+
   public void closeStreams() {
     closeQuietly(process.getInputStream());
     closeQuietly(process.getOutputStream());
index 81260cf5ec6c0a9f29bceda5967e904ccf5e66f2..9a88393ef10b2d8fc51db171cd16dde544ee9944 100644 (file)
@@ -29,6 +29,11 @@ public interface ProcessMonitor {
    */
   InputStream getInputStream();
 
+  /**
+   * @see Process#getErrorStream()
+   */
+  InputStream getErrorStream();
+
   /**
    * Closes the streams {@link Process#getInputStream()}, {@link Process#getOutputStream()}
    * and {@link Process#getErrorStream()}.
index 26f8d91713f845d2f855023b16d6ebe4216e5050..6aa7a29bac1fc21a4b4e3c9f9aa12a62ab6dbf97 100644 (file)
@@ -43,7 +43,8 @@ public class SQProcess {
   private final long watcherDelayMs;
 
   private ProcessMonitor process;
-  private StreamGobbler gobbler;
+  private StreamGobbler stdOutGobbler;
+  private StreamGobbler stdErrGobbler;
   private final StopWatcher stopWatcher;
   private final EventWatcher eventWatcher;
   // keep flag so that the operational event is sent only once
@@ -71,8 +72,10 @@ public class SQProcess {
       lifecycle.tryToMoveTo(Lifecycle.State.STOPPED);
       throw e;
     }
-    this.gobbler = new StreamGobbler(process.getInputStream(), processId.getKey());
-    this.gobbler.start();
+    this.stdOutGobbler = new StreamGobbler(process.getInputStream(), processId.getKey());
+    this.stdOutGobbler.start();
+    this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), processId.getKey());
+    this.stdErrGobbler.start();
     this.stopWatcher.start();
     this.eventWatcher.start();
     // Could be improved by checking the status "up" in shared memory.
@@ -143,9 +146,13 @@ public class SQProcess {
       waitForDown();
       process.closeStreams();
     }
-    if (gobbler != null) {
-      StreamGobbler.waitUntilFinish(gobbler);
-      gobbler.interrupt();
+    if (stdOutGobbler != null) {
+      StreamGobbler.waitUntilFinish(stdOutGobbler);
+      stdOutGobbler.interrupt();
+    }
+    if (stdErrGobbler != null) {
+      StreamGobbler.waitUntilFinish(stdErrGobbler);
+      stdErrGobbler.interrupt();
     }
     lifecycle.tryToMoveTo(Lifecycle.State.STOPPED);
   }
index d8335fcdf939c8bb9cfc5ba8d9f26d20c678e325..c2a94d039f768f9f24d1822e19d5c91b1f14f82b 100644 (file)
@@ -403,6 +403,11 @@ public class SchedulerImplTest {
       return mock(InputStream.class, Mockito.RETURNS_MOCKS);
     }
 
+    @Override
+    public InputStream getErrorStream() {
+      return mock(InputStream.class, Mockito.RETURNS_MOCKS);
+    }
+
     @Override
     public void closeStreams() {
     }
index c7eb9e2660865f14e3563e19779122a378556649..004ef445d3842ee7a50a2872b002a29124641795 100644 (file)
@@ -261,6 +261,7 @@ public class SQProcessTest {
 
     private final CountDownLatch alive = new CountDownLatch(1);
     private final InputStream inputStream = mock(InputStream.class, Mockito.RETURNS_MOCKS);
+    private final InputStream errorStream = mock(InputStream.class, Mockito.RETURNS_MOCKS);
     private boolean streamsClosed = false;
     private boolean operational = false;
     private boolean askedForRestart = false;
@@ -272,6 +273,11 @@ public class SQProcessTest {
       return inputStream;
     }
 
+    @Override
+    public InputStream getErrorStream() {
+      return errorStream;
+    }
+
     @Override
     public void closeStreams() {
       streamsClosed = true;