Browse Source

fix issues callback with multiple analysis

tags/5.2-RC1
Duarte Meneses 8 years ago
parent
commit
8ea927b076

+ 1
- 2
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java View File

@@ -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;
}


+ 10
- 0
sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java View File

@@ -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;
}

}


+ 102
- 0
sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesPreviewMediumTest.java View File

@@ -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);
}
}
}

Loading…
Cancel
Save