summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-09-23 17:26:16 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-09-23 17:27:59 +0200
commitc35c6ba856dc4270e4c29233919c6bf5a06a648b (patch)
tree1a334bdccf1888fad8cfccad1df19740e6d005e1
parent38b47dc6dec25d251a0b89498fd13de59931c1f6 (diff)
downloadsonarqube-c35c6ba856dc4270e4c29233919c6bf5a06a648b.tar.gz
sonarqube-c35c6ba856dc4270e4c29233919c6bf5a06a648b.zip
SONAR-4689 Batch API to get issues of the current project
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java67
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java (renamed from sonar-batch/src/main/java/org/sonar/batch/issue/DefaultModuleIssues.java)38
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/DefaultProjectIssuesTest.java64
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/issue/DefaultModuleIssuesTest.java)39
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/ProjectIssues.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/ModuleIssues.java)16
13 files changed, 183 insertions, 91 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index ca8cf60059c..4d4a47d6df2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -49,7 +49,7 @@ import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.ResourceFilters;
import org.sonar.batch.issue.DeprecatedViolations;
-import org.sonar.batch.issue.DefaultModuleIssues;
+import org.sonar.batch.issue.ModuleIssues;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.component.ScanGraph;
@@ -82,7 +82,7 @@ public class DefaultIndex extends SonarIndex {
private Map<Resource, Map<Resource, Dependency>> incomingDependenciesByResource = Maps.newHashMap();
private ProjectTree projectTree;
private final DeprecatedViolations deprecatedViolations;
- private DefaultModuleIssues moduleIssues;
+ private ModuleIssues moduleIssues;
public DefaultIndex(PersistenceManager persistence, DefaultResourceCreationLock lock, ProjectTree projectTree, MetricFinder metricFinder,
ScanGraph graph, DeprecatedViolations deprecatedViolations) {
@@ -124,7 +124,7 @@ public class DefaultIndex extends SonarIndex {
return currentProject;
}
- public void setCurrentProject(Project project, ResourceFilters resourceFilters, DefaultModuleIssues moduleIssues) {
+ public void setCurrentProject(Project project, ResourceFilters resourceFilters, ModuleIssues moduleIssues) {
this.currentProject = project;
// the following components depend on the current module, so they need to be reloaded.
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 5b7c4c8092c..98665d60bbd 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,11 @@ import java.util.List;
*/
public class DefaultIssuable implements Issuable {
- private final DefaultModuleIssues moduleIssues;
+ private final ModuleIssues moduleIssues;
private final IssueCache cache;
private final Component component;
- DefaultIssuable(Component component, DefaultModuleIssues moduleIssues, IssueCache cache) {
+ DefaultIssuable(Component component, ModuleIssues moduleIssues, IssueCache cache) {
this.component = component;
this.moduleIssues = moduleIssues;
this.cache = cache;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java
new file mode 100644
index 00000000000..3e3154fc010
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java
@@ -0,0 +1,67 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.issue;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.ProjectIssues;
+import org.sonar.api.issue.internal.DefaultIssue;
+
+import javax.annotation.Nullable;
+
+/**
+ * Expose list of issues for the current project
+ * @since 4.0
+ */
+public class DefaultProjectIssues implements ProjectIssues {
+
+ private final IssueCache cache;
+
+ public DefaultProjectIssues(IssueCache cache) {
+ this.cache = cache;
+ }
+
+ @Override
+ public Iterable<Issue> issues() {
+ return (Iterable) Iterables.filter(cache.all(), new ResolvedPredicate(false));
+ }
+
+ @Override
+ public Iterable<Issue> resolvedIssues() {
+ return (Iterable) Iterables.filter(cache.all(), new ResolvedPredicate(true));
+ }
+
+ private static class ResolvedPredicate implements Predicate<DefaultIssue> {
+ private final boolean resolved;
+
+ private ResolvedPredicate(boolean resolved) {
+ this.resolved = resolved;
+ }
+
+ @Override
+ public boolean apply(@Nullable DefaultIssue issue) {
+ if (issue != null) {
+ return resolved ? issue.resolution() != null : issue.resolution() == null;
+ }
+ return false;
+ }
+ }
+}
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 cd34582c24c..b1c791f4069 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
@@ -33,10 +33,10 @@ import javax.annotation.CheckForNull;
*/
public class IssuableFactory extends PerspectiveBuilder<Issuable> {
- private final DefaultModuleIssues moduleIssues;
+ private final ModuleIssues moduleIssues;
private final IssueCache cache;
- public IssuableFactory(DefaultModuleIssues moduleIssues, IssueCache cache) {
+ public IssuableFactory(ModuleIssues moduleIssues, IssueCache cache) {
super(Issuable.class);
this.moduleIssues = moduleIssues;
this.cache = cache;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 1bc61bd4846..7bef92697a9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -19,10 +19,6 @@
*/
package org.sonar.batch.issue;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.ModuleIssues;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
@@ -36,14 +32,14 @@ import javax.annotation.Nullable;
/**
* Initialize the issues raised during scan.
*/
-public class DefaultModuleIssues implements ModuleIssues {
+public class ModuleIssues {
private final RulesProfile qProfile;
private final IssueCache cache;
private final Project project;
private final IssueFilters filters;
- public DefaultModuleIssues(RulesProfile qProfile, IssueCache cache, Project project, IssueFilters filters) {
+ public ModuleIssues(RulesProfile qProfile, IssueCache cache, Project project, IssueFilters filters) {
this.qProfile = qProfile;
this.cache = cache;
this.project = project;
@@ -90,34 +86,4 @@ public class DefaultModuleIssues implements ModuleIssues {
}
return false;
}
-
- @Override
- public Iterable<Issue> issues() {
- return (Iterable) Iterables.filter(cache.all(), new ModulePredicate(project, false));
- }
-
- @Override
- public Iterable<Issue> resolvedIssues() {
- return (Iterable) Iterables.filter(cache.all(), new ModulePredicate(project, true));
- }
-
- private static class ModulePredicate implements Predicate<DefaultIssue> {
- private final boolean resolved;
- private final String key;
- private final String keyPrefix;
-
- private ModulePredicate(Project project, boolean resolved) {
- this.resolved = resolved;
- this.key = project.getEffectiveKey();
- this.keyPrefix = project.getEffectiveKey() + ":";
- }
-
- @Override
- public boolean apply(@Nullable DefaultIssue issue) {
- if (issue != null && (issue.componentKey().equals(key) || issue.componentKey().startsWith(keyPrefix))) {
- return resolved ? issue.resolution() != null : issue.resolution()==null;
- }
- return false;
- }
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index 543f01e2940..b97118be253 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.scan;
-import org.sonar.core.measure.MeasurementFilters;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
@@ -31,7 +29,13 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.batch.*;
+import org.sonar.batch.DefaultProjectClasspath;
+import org.sonar.batch.DefaultSensorContext;
+import org.sonar.batch.DefaultTimeMachine;
+import org.sonar.batch.ProfileProvider;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
@@ -42,11 +46,16 @@ import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.issue.IssuableFactory;
import org.sonar.batch.issue.IssueFilters;
-import org.sonar.batch.issue.DefaultModuleIssues;
+import org.sonar.batch.issue.ModuleIssues;
import org.sonar.batch.phases.PhaseExecutor;
import org.sonar.batch.phases.PhasesTimeProfiler;
-import org.sonar.batch.scan.filesystem.*;
+import org.sonar.batch.scan.filesystem.DeprecatedFileSystemAdapter;
+import org.sonar.batch.scan.filesystem.ExclusionFilters;
+import org.sonar.batch.scan.filesystem.FileSystemLogger;
+import org.sonar.batch.scan.filesystem.LanguageFilters;
+import org.sonar.batch.scan.filesystem.ModuleFileSystemProvider;
import org.sonar.core.component.ScanPerspectives;
+import org.sonar.core.measure.MeasurementFilters;
public class ModuleScanContainer extends ComponentContainer {
private static final Logger LOG = LoggerFactory.getLogger(ModuleScanContainer.class);
@@ -113,11 +122,10 @@ public class ModuleScanContainer extends ComponentContainer {
new ProfileProvider(),
// issues
- DefaultModuleIssues.class,
IssuableFactory.class,
+ ModuleIssues.class,
- ScanPerspectives.class
- );
+ ScanPerspectives.class);
}
private void addExtensions() {
@@ -140,7 +148,7 @@ public class ModuleScanContainer extends ComponentContainer {
DefaultIndex index = getComponentByType(DefaultIndex.class);
index.setCurrentProject(module,
getComponentByType(ResourceFilters.class),
- getComponentByType(DefaultModuleIssues.class));
+ getComponentByType(ModuleIssues.class));
getComponentByType(PhaseExecutor.class).execute(module);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 9bc0c43c940..7992aab42ea 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -52,6 +52,7 @@ import org.sonar.batch.index.MemoryOptimizer;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.index.SnapshotCache;
import org.sonar.batch.index.SourcePersister;
+import org.sonar.batch.issue.DefaultProjectIssues;
import org.sonar.batch.issue.DeprecatedViolations;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.issue.IssuePersister;
@@ -143,6 +144,7 @@ public class ProjectScanContainer extends ComponentContainer {
ScanIssueStorage.class,
IssuePersister.class,
IssueNotifications.class,
+ DefaultProjectIssues.class,
// tests
TestPlanPerspectiveLoader.class,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index 2431cefbbb5..cd039e17d9a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -39,7 +39,7 @@ import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.ResourceFilters;
import org.sonar.batch.issue.DeprecatedViolations;
-import org.sonar.batch.issue.DefaultModuleIssues;
+import org.sonar.batch.issue.ModuleIssues;
import org.sonar.core.component.ScanGraph;
import static com.google.common.collect.Lists.newArrayList;
@@ -77,7 +77,7 @@ public class DefaultIndexTest {
rule = Rule.create("repoKey", "ruleKey", "Rule");
rule.setId(1);
rulesProfile.activateRule(rule, null);
- index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[]{filter}), mock(DefaultModuleIssues.class));
+ index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[]{filter}), mock(ModuleIssues.class));
index.doStart(project);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
index f66cc03aa16..24a12f98c0f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
public class DefaultIssuableTest {
- DefaultModuleIssues moduleIssues = mock(DefaultModuleIssues.class);
+ ModuleIssues moduleIssues = mock(ModuleIssues.class);
IssueCache cache = mock(IssueCache.class);
Component component = mock(Component.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultProjectIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultProjectIssuesTest.java
new file mode 100644
index 00000000000..17a4c4e591a
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultProjectIssuesTest.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.issue;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DefaultProjectIssuesTest {
+
+ static final RuleKey SQUID_RULE_KEY = RuleKey.of("squid", "AvoidCycle");
+
+ IssueCache cache = mock(IssueCache.class);
+ DefaultProjectIssues projectIssues = new DefaultProjectIssues(cache);
+
+ @Test
+ public void should_get_all_issues() throws Exception {
+ DefaultIssue issueOnModule = new DefaultIssue().setKey("1").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core");
+ DefaultIssue issueInModule = new DefaultIssue().setKey("2").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action");
+ DefaultIssue resolvedIssueInModule = new DefaultIssue().setKey("3").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action")
+ .setResolution(Issue.RESOLUTION_FIXED);
+
+ DefaultIssue issueOnRoot = new DefaultIssue().setKey("4").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts");
+ DefaultIssue issueInRoot = new DefaultIssue().setKey("5").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts:FileInRoot");
+ when(cache.all()).thenReturn(Arrays.<DefaultIssue> asList(
+ issueOnRoot, issueInRoot,
+ issueOnModule, issueInModule, resolvedIssueInModule
+ ));
+
+ // unresolved issues
+ List<Issue> issues = Lists.newArrayList(projectIssues.issues());
+ assertThat(issues).containsOnly(issueOnRoot, issueInRoot, issueInModule, issueOnModule);
+
+ List<Issue> resolvedIssues = Lists.newArrayList(projectIssues.resolvedIssues());
+ assertThat(resolvedIssues).containsOnly(resolvedIssueInModule);
+ }
+}
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 65e4b5d706c..1fc8e129ee3 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,7 +34,7 @@ import static org.mockito.Mockito.mock;
public class IssuableFactoryTest {
- DefaultModuleIssues moduleIssues = mock(DefaultModuleIssues.class);
+ ModuleIssues moduleIssues = mock(ModuleIssues.class);
IssueCache cache = mock(IssueCache.class, Mockito.RETURNS_MOCKS);
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index 27f14f4bcd0..2fc2f8d2543 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -19,12 +19,10 @@
*/
package org.sonar.batch.issue;
-import com.google.common.collect.Lists;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.JavaFile;
@@ -37,15 +35,19 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
-import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
-public class DefaultModuleIssuesTest {
+public class ModuleIssuesTest {
static final RuleKey SQUID_RULE_KEY = RuleKey.of("squid", "AvoidCycle");
@@ -53,7 +55,7 @@ public class DefaultModuleIssuesTest {
RulesProfile qProfile = mock(RulesProfile.class);
Project project = mock(Project.class);
IssueFilters filters = mock(IssueFilters.class);
- DefaultModuleIssues moduleIssues = new DefaultModuleIssues(qProfile, cache, project, filters);
+ ModuleIssues moduleIssues = new ModuleIssues(qProfile, cache, project, filters);
@Before
public void setUp() {
@@ -182,27 +184,4 @@ public class DefaultModuleIssuesTest {
verifyZeroInteractions(cache);
}
- @Test
- public void should_get_module_issues() throws Exception {
- DefaultIssue issueOnModule = new DefaultIssue().setKey("1").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core");
- DefaultIssue issueInModule = new DefaultIssue().setKey("2").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action");
- DefaultIssue resolvedIssueInModule = new DefaultIssue().setKey("3").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action").setResolution(Issue.RESOLUTION_FIXED);
-
- when(cache.all()).thenReturn(Arrays.<DefaultIssue>asList(
- // issue on root module
- new DefaultIssue().setKey("4").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts"),
-
- // issue in root module
- new DefaultIssue().setKey("5").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts:FileInRoot"),
-
- issueOnModule, issueInModule, resolvedIssueInModule
- ));
-
- // unresolved issues
- List<Issue> issues = Lists.newArrayList(moduleIssues.issues());
- assertThat(issues).containsOnly(issueInModule, issueOnModule);
-
- List<Issue> resolvedIssues = Lists.newArrayList(moduleIssues.resolvedIssues());
- assertThat(resolvedIssues).containsOnly(resolvedIssueInModule);
- }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/ModuleIssues.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/ProjectIssues.java
index 2f1a974f51c..36659896d68 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/ModuleIssues.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/ProjectIssues.java
@@ -20,22 +20,28 @@
package org.sonar.api.issue;
import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.PostJob;
+
+import static org.sonar.api.batch.InstantiationStrategy.PER_BATCH;
/**
- * Used by batch components to get the issues of the current module. It does not allow
- * to get issues of all project modules.
+ * Used by batch components to get the issues of the project. You have to wait for all
+ * issues to have been computed (for example in a {@link PostJob}) to be sure all issues have
+ * been computed.
*
* @since 4.0
*/
-public interface ModuleIssues extends BatchComponent {
+@InstantiationStrategy(PER_BATCH)
+public interface ProjectIssues extends BatchComponent {
/**
- * All the unresolved issues of the current module, including the issues reported by end-users.
+ * All the unresolved issues of the project, including the issues reported by end-users.
*/
Iterable<Issue> issues();
/**
- * All the issues of this module that have been marked as resolved during this scan
+ * All the issues of this project that have been marked as resolved during this scan
*/
Iterable<Issue> resolvedIssues();
}