diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-07-31 17:31:27 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-07-31 17:37:28 +0200 |
commit | 8ea927b076a9447ce401b9c65ed8d3c0e93b05c6 (patch) | |
tree | 5faaf113d0b93e97ff08c06cc248efb5b68f2bfe /sonar-batch | |
parent | 6541bd8d9b7a73ad0f5bd19a7f535fe1c05ef9bd (diff) | |
download | sonarqube-8ea927b076a9447ce401b9c65ed8d3c0e93b05c6.tar.gz sonarqube-8ea927b076a9447ce401b9c65ed8d3c0e93b05c6.zip |
fix issues callback with multiple analysis
Diffstat (limited to 'sonar-batch')
3 files changed, 113 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java index 94065d8a2d3..d28ff6cf2ac 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java @@ -110,8 +110,7 @@ public final class Batch { */ public Batch executeTask(Map<String, String> analysisProperties, IssueListener issueListener) { checkStarted(); - components.add(issueListener); - bootstrapContainer.executeAnalysis(analysisProperties, components); + bootstrapContainer.executeAnalysis(analysisProperties, components, issueListener); return this; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java index 3f078b2b08f..88690a3bfcb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -181,6 +181,11 @@ public class BatchMediumTester { projectRefProvider.addFileData(moduleKey, path, fileData); return this; } + + public BatchMediumTesterBuilder setLastBuildDate(Date d) { + projectRefProvider.setLastAnalysisDate(d); + return this; + } public BatchMediumTesterBuilder mockServerIssue(ServerIssue issue) { serverIssues.getServerIssues().add(issue); @@ -346,6 +351,11 @@ public class BatchMediumTester { ref.addFileData(moduleKey, path, fileData); return this; } + + public FakeProjectRepositoriesLoader setLastAnalysisDate(Date d) { + ref.setLastAnalysisDate(d); + return this; + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesPreviewMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesPreviewMediumTest.java new file mode 100644 index 00000000000..6177d158ef0 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesPreviewMediumTest.java @@ -0,0 +1,102 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.mediumtest.issues; + +import org.junit.rules.TemporaryFolder; +import org.sonar.batch.bootstrapper.IssueListener; +import org.junit.After; +import org.junit.Before; +import com.google.common.collect.ImmutableMap; +import org.sonar.api.CoreProperties; +import org.sonar.batch.mediumtest.BatchMediumTester; +import org.sonar.batch.protocol.input.ActiveRule; +import org.sonar.xoo.XooPlugin; +import org.sonar.xoo.rule.XooRulesDefinition; +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.sonar.batch.mediumtest.TaskResult; + +import java.io.File; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class IssuesPreviewMediumTest { + @org.junit.Rule + public TemporaryFolder temp = new TemporaryFolder(); + + public BatchMediumTester testerPreview = BatchMediumTester.builder() + .registerPlugin("xoo", new XooPlugin()) + .addDefaultQProfile("xoo", "Sonar Way") + .addRules(new XooRulesDefinition()) + .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW)) + .activateRule(new ActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")) + .setLastBuildDate(new Date()) + .build(); + + @Before + public void prepare() { + testerPreview.start(); + } + + @After + public void stop() { + testerPreview.stop(); + } + + @Test + public void testIssueCallback() throws Exception { + File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI()); + File tmpDir = temp.newFolder(); + FileUtils.copyDirectory(projectDir, tmpDir); + IssueRecorder issueListener = new IssueRecorder(); + + TaskResult result1 = testerPreview + .newScanTask(new File(tmpDir, "sonar-project.properties")) + .setIssueListener(issueListener) + .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW) + .start(); + + assertThat(result1.trackedIssues()).hasSize(14); + assertThat(issueListener.issueList).hasSize(14); + issueListener = new IssueRecorder(); + + TaskResult result2 = testerPreview + .newScanTask(new File(tmpDir, "sonar-project.properties")) + .setIssueListener(issueListener) + .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW) + .start(); + + + assertThat(result2.trackedIssues()).hasSize(28); + assertThat(issueListener.issueList).hasSize(28); + } + + private class IssueRecorder implements IssueListener { + List<org.sonar.api.issue.Issue> issueList = new LinkedList<>(); + + @Override + public void handle(org.sonar.api.issue.Issue issue) { + issueList.add(issue); + } + } +} |