]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9984 Coverage per tests should be disabled for short living branches
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 17 Oct 2017 15:39:28 +0000 (17:39 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Oct 2017 09:38:56 +0000 (19:38 +1000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java [new file with mode: 0644]

index 43411c011c0c901789006e7a11fb156dc99d251a..b991c7656d8d8b860e65b09eebe9ce73516bfa9d 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail;
 import org.sonar.scanner.protocol.output.ScannerReport.Test;
 import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static java.util.stream.Collectors.toList;
@@ -44,14 +45,19 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep {
 
   private final InputComponentStore componentStore;
   private final TestPlanBuilder testPlanBuilder;
+  private final BranchConfiguration branchConfiguration;
 
-  public TestExecutionAndCoveragePublisher(InputComponentStore componentStore, TestPlanBuilder testPlanBuilder) {
+  public TestExecutionAndCoveragePublisher(InputComponentStore componentStore, TestPlanBuilder testPlanBuilder, BranchConfiguration branchConfiguration) {
     this.componentStore = componentStore;
     this.testPlanBuilder = testPlanBuilder;
+    this.branchConfiguration = branchConfiguration;
   }
 
   @Override
   public void publish(ScannerReportWriter writer) {
+    if (branchConfiguration.isShortLivingBranch()) {
+      return;
+    }
     final ScannerReport.Test.Builder testBuilder = ScannerReport.Test.newBuilder();
     final ScannerReport.CoverageDetail.Builder builder = ScannerReport.CoverageDetail.newBuilder();
     final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder = ScannerReport.CoverageDetail.CoveredFile.newBuilder();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java
new file mode 100644 (file)
index 0000000..426e7e9
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.report;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+public class TestExecutionAndCoveragePublisherTest {
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void do_nothing_for_short_living_branches() throws IOException {
+    BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
+    when(branchConfiguration.isShortLivingBranch()).thenReturn(true);
+    InputComponentStore componentStore = mock(InputComponentStore.class);
+    TestExecutionAndCoveragePublisher publisher = new TestExecutionAndCoveragePublisher(componentStore, null, branchConfiguration);
+    File outputDir = temp.newFolder();
+    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
+
+    publisher.publish(writer);
+
+    verifyZeroInteractions(componentStore);
+  }
+
+}