aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-10-17 17:39:28 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-10-20 19:38:56 +1000
commitf181b82977897bd09c3cb9106c98ecd7369550ad (patch)
tree2b89c47a905301e513fa65f72219ce59085a0c17 /sonar-scanner-engine/src
parentf185740ba7aa84579af60781ed9282e31fa4d94a (diff)
downloadsonarqube-f181b82977897bd09c3cb9106c98ecd7369550ad.tar.gz
sonarqube-f181b82977897bd09c3cb9106c98ecd7369550ad.zip
SONAR-9984 Coverage per tests should be disabled for short living branches
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java8
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java54
2 files changed, 61 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java
index 43411c011c0..b991c7656d8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java
@@ -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
index 00000000000..426e7e98ab5
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java
@@ -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);
+ }
+
+}