]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8093 PostProjectAnalysisTasksExecutor do not stop if task fails 1264/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 19 Sep 2016 12:08:45 +0000 (14:08 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 19 Sep 2016 12:59:56 +0000 (14:59 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java

index 1fed2f087ceb0603045ce3958a8dc62155668adf..9b27f00b00dcd0daf43ff14d1f5724845dddf8b3 100644 (file)
@@ -32,6 +32,8 @@ import org.sonar.api.ce.posttask.Project;
 import org.sonar.api.ce.posttask.QualityGate;
 import org.sonar.api.ce.posttask.ScannerContext;
 import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
 import org.sonar.server.computation.task.projectanalysis.qualitygate.Condition;
@@ -53,6 +55,8 @@ import static org.sonar.api.ce.posttask.CeTask.Status.SUCCESS;
 public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor.Listener {
   private static final PostProjectAnalysisTask[] NO_POST_PROJECT_ANALYSIS_TASKS = new PostProjectAnalysisTask[0];
 
+  private static final Logger LOG = Loggers.get(PostProjectAnalysisTasksExecutor.class);
+
   private final org.sonar.ce.queue.CeTask ceTask;
   private final AnalysisMetadataHolder analysisMetadataHolder;
   private final QualityGateHolder qualityGateHolder;
@@ -93,7 +97,15 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
 
     ProjectAnalysis projectAnalysis = createProjectAnalysis(allStepsExecuted ? SUCCESS : FAILED);
     for (PostProjectAnalysisTask postProjectAnalysisTask : postProjectAnalysisTasks) {
+      executeTask(projectAnalysis, postProjectAnalysisTask);
+    }
+  }
+
+  private static void executeTask(ProjectAnalysis projectAnalysis, PostProjectAnalysisTask postProjectAnalysisTask) {
+    try {
       postProjectAnalysisTask.finished(projectAnalysis);
+    } catch (Exception e) {
+      LOG.error("Execution of task " + postProjectAnalysisTask.getClass() + " failed", e);
     }
   }
 
index 46134497eda4407622766a78b4b5e3bbdbfe81f3..304b624d9256f0ba7f220c86e1a3a16623427377 100644 (file)
@@ -50,6 +50,8 @@ import static com.google.common.collect.ImmutableList.of;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.data.MapEntry.entry;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -234,6 +236,29 @@ public class PostProjectAnalysisTasksExecutorTest {
     assertThat(scannerContext.getProperties()).containsExactly(entry("foo", "bar"));
   }
 
+  @Test
+  @UseDataProvider("booleanValues")
+  public void finished_does_not_fail_if_listener_throws_exception_and_execute_subsequent_listeners(boolean allStepsExecuted) {
+    PostProjectAnalysisTask postProjectAnalysisTask1 = mock(PostProjectAnalysisTask.class);
+    PostProjectAnalysisTask postProjectAnalysisTask2 = mock(PostProjectAnalysisTask.class);
+    PostProjectAnalysisTask postProjectAnalysisTask3 = mock(PostProjectAnalysisTask.class);
+    InOrder inOrder = inOrder(postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3);
+
+    doThrow(new RuntimeException("Faking a listener throws an exception"))
+        .when(postProjectAnalysisTask2)
+        .finished(any(PostProjectAnalysisTask.ProjectAnalysis.class));
+
+    new PostProjectAnalysisTasksExecutor(
+        ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader,
+        system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3})
+        .finished(allStepsExecuted);
+
+    inOrder.verify(postProjectAnalysisTask1).finished(projectAnalysisArgumentCaptor.capture());
+    inOrder.verify(postProjectAnalysisTask2).finished(projectAnalysisArgumentCaptor.capture());
+    inOrder.verify(postProjectAnalysisTask3).finished(projectAnalysisArgumentCaptor.capture());
+    inOrder.verifyNoMoreInteractions();
+  }
+
   @DataProvider
   public static Object[][] booleanValues() {
     return new Object[][] {