aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-20 20:52:57 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-20 20:53:52 +0200
commit97e7d751080fdc0b45845a066efc03bc7a14ac6c (patch)
treead3bbfdbb0ad12e4123feaff5f7a5af3fd0e8d1f /sonar-batch/src
parentcb2f76a16944e74801a7820c16a3201916392c31 (diff)
downloadsonarqube-97e7d751080fdc0b45845a066efc03bc7a14ac6c.tar.gz
sonarqube-97e7d751080fdc0b45845a066efc03bc7a14ac6c.zip
SONAR-3755 close issues when rule is disabled or deleted
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java10
8 files changed, 24 insertions, 49 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
index 6c0b44c03d9..151e1783b3e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
@@ -33,11 +33,13 @@ import java.util.Collection;
public class DefaultIssuable implements Issuable {
private final ScanIssues scanIssues;
+ private final IssueCache cache;
private final Component component;
- DefaultIssuable(Component component, ScanIssues scanIssues) {
+ DefaultIssuable(Component component, ScanIssues scanIssues, IssueCache cache) {
this.component = component;
this.scanIssues = scanIssues;
+ this.cache = cache;
}
@Override
@@ -53,7 +55,7 @@ public class DefaultIssuable implements Issuable {
@SuppressWarnings("unchecked")
@Override
public Collection<Issue> issues() {
- return (Collection)scanIssues.issues(component.key());
+ return (Collection)cache.byComponent(component.key());
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
index 8ad43865f77..3e13158a761 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
@@ -34,10 +34,12 @@ import javax.annotation.CheckForNull;
public class IssuableFactory extends PerspectiveBuilder<Issuable> {
private final ScanIssues scanIssues;
+ private final IssueCache cache;
- public IssuableFactory(ScanIssues scanIssues) {
+ public IssuableFactory(ScanIssues scanIssues, IssueCache cache) {
super(Issuable.class);
this.scanIssues = scanIssues;
+ this.cache = cache;
}
@CheckForNull
@@ -47,6 +49,6 @@ public class IssuableFactory extends PerspectiveBuilder<Issuable> {
if (component instanceof ResourceComponent) {
supported = Scopes.isHigherThanOrEquals(((ResourceComponent) component).scope(), Scopes.FILE);
}
- return supported ? new DefaultIssuable(component, scanIssues) : null;
+ return supported ? new DefaultIssuable(component, scanIssues, cache) : null;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
index bb9b10e62a9..ab06a7f9cca 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
@@ -19,17 +19,12 @@
*/
package org.sonar.batch.issue;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import org.sonar.api.BatchComponent;
-import org.sonar.api.issue.Issue;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.ActiveRule;
import org.sonar.core.issue.DefaultIssue;
-import java.util.Collection;
-
/**
* Central component to manage issues
*/
@@ -45,20 +40,6 @@ public class ScanIssues implements BatchComponent {
this.project = project;
}
- public Collection<DefaultIssue> issues(String componentKey) {
- return cache.byComponent(componentKey);
- }
-
- public Collection<DefaultIssue> issues() {
- return cache.all();
- }
-
- public ScanIssues addOrUpdate(DefaultIssue issue) {
- Preconditions.checkState(!Strings.isNullOrEmpty(issue.key()), "Missing issue key");
- cache.put(issue);
- return this;
- }
-
public boolean initAndAddIssue(DefaultIssue issue) {
ActiveRule activeRule = qProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule());
if (activeRule == null || activeRule.getRule() == null) {
@@ -75,8 +56,4 @@ public class ScanIssues implements BatchComponent {
return true;
}
- public boolean remove(Issue issue) {
- return cache.remove(issue);
- }
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
index f12c4dfd6a5..3a85c4c42bb 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
@@ -121,7 +121,7 @@ public final class PhaseExecutor {
persistenceManager.setDelayedMode(false);
if (module.isRoot()) {
- sonarReport.execute(sensorContext);
+ sonarReport.execute();
LOGGER.info("Store results in database");
for (ScanPersister persister : persisters) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java b/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
index f02a8c466be..d6e24c7aa63 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
@@ -35,6 +35,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.issue.ScanIssues;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.issue.DefaultIssue;
@@ -58,17 +59,17 @@ public class SonarReport implements BatchComponent {
private final ModuleFileSystem fileSystem;
private final Server server;
private final RuleI18nManager ruleI18nManager;
- private final ScanIssues scanIssues;
+ private final IssueCache issueCache;
- public SonarReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, ScanIssues scanIssues) {
+ public SonarReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, IssueCache issueCache) {
this.settings = settings;
this.fileSystem = fileSystem;
this.server = server;
this.ruleI18nManager = ruleI18nManager;
- this.scanIssues = scanIssues;
+ this.issueCache = issueCache;
}
- public void execute(SensorContext context) {
+ public void execute() {
if (settings.getBoolean(CoreProperties.DRY_RUN)) {
exportResults();
}
@@ -178,6 +179,6 @@ public class SonarReport implements BatchComponent {
@VisibleForTesting
Collection<DefaultIssue> getIssues() {
- return scanIssues.issues();
+ return issueCache.all();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
index 16358a6546f..f661546cb32 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
@@ -34,10 +34,11 @@ import static org.mockito.Mockito.mock;
public class IssuableFactoryTest {
ScanIssues issueFactory = mock(ScanIssues.class);
+ IssueCache cache = mock(IssueCache.class);
@Test
public void file_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(issueFactory);
+ IssuableFactory factory = new IssuableFactory(issueFactory, cache);
Component component = new ResourceComponent(new File("foo/bar.c"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
@@ -48,7 +49,7 @@ public class IssuableFactoryTest {
@Test
public void project_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(issueFactory);
+ IssuableFactory factory = new IssuableFactory(issueFactory, cache);
Component component = new ResourceComponent(new Project("Foo"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
@@ -59,7 +60,7 @@ public class IssuableFactoryTest {
@Test
public void java_file_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(issueFactory);
+ IssuableFactory factory = new IssuableFactory(issueFactory, cache);
Component component = new ResourceComponent(new JavaFile("bar.Foo"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
@@ -70,7 +71,7 @@ public class IssuableFactoryTest {
@Test
public void java_class_should_not_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(issueFactory);
+ IssuableFactory factory = new IssuableFactory(issueFactory, cache);
Component component = new ResourceComponent(JavaClass.create("bar", "Foo"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
index c19ae73fc02..730a0508faf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
@@ -43,12 +43,6 @@ public class ScanIssuesTest {
ScanIssues scanIssues = new ScanIssues(qProfile, cache, project);
@Test
- public void should_get_issues() throws Exception {
- scanIssues.issues("key");
- verify(cache).byComponent("key");
- }
-
- @Test
public void should_ignore_null_active_rule() throws Exception {
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(null);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
index 55253b35fb6..b0f3aed03ae 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
@@ -27,7 +27,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issue;
import org.sonar.api.platform.Server;
@@ -36,7 +35,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.issue.ScanIssues;
+import org.sonar.batch.issue.IssueCache;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.issue.DefaultIssue;
@@ -54,13 +53,12 @@ public class SonarReportTest {
@org.junit.Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
SonarReport sonarReport;
- SensorContext sensorContext = mock(SensorContext.class);
Resource resource = mock(Resource.class);
ModuleFileSystem fileSystem = mock(ModuleFileSystem.class);
Server server = mock(Server.class);
RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
Settings settings;
- ScanIssues scanIssues = mock(ScanIssues.class);
+ IssueCache issueCache = mock(IssueCache.class);
@Before
public void before() {
@@ -69,7 +67,7 @@ public class SonarReportTest {
settings = new Settings();
settings.setProperty(CoreProperties.DRY_RUN, true);
- sonarReport = new SonarReport(settings, fileSystem, server, ruleI18nManager, scanIssues);
+ sonarReport = new SonarReport(settings, fileSystem, server, ruleI18nManager, issueCache);
}
@Test
@@ -236,7 +234,7 @@ public class SonarReportTest {
settings.setProperty("sonar.report.export.path", "output.json");
when(fileSystem.workingDir()).thenReturn(sonarDirectory);
- sonarReport.execute(sensorContext);
+ sonarReport.execute();
assertThat(new File(sonarDirectory, "output.json")).exists();
}