From: Julien HENRY Date: Tue, 17 Oct 2017 15:39:28 +0000 (+0200) Subject: SONAR-9984 Coverage per tests should be disabled for short living branches X-Git-Tag: 6.7-RC1~147 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f181b82977897bd09c3cb9106c98ecd7369550ad;p=sonarqube.git SONAR-9984 Coverage per tests should be disabled for short living branches --- 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); + } + +}