aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-27 19:05:54 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-27 19:06:01 +0200
commit43c9839354d12e4a25642511c1adcbbc50813331 (patch)
treed0d24002780c8173bd4fe30ce7a29fb3918eed04 /sonar-core
parent26a782fc420625f2428e172c2f847ed73750ecde (diff)
downloadsonarqube-43c9839354d12e4a25642511c1adcbbc50813331.tar.gz
sonarqube-43c9839354d12e4a25642511c1adcbbc50813331.zip
Fix conflicts
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java171
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueQueryResultTest.java5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java3
3 files changed, 175 insertions, 4 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java
new file mode 100644
index 00000000000..239d1b8d1e1
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java
@@ -0,0 +1,171 @@
+/*
+ * 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.core.issue;
+
+import com.google.common.collect.Maps;
+import org.sonar.api.component.Component;
+import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueQueryResult;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.user.User;
+import org.sonar.api.utils.Paging;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultIssueQueryResult implements IssueQueryResult {
+
+ private List<Issue> issues;
+ private final Map<RuleKey, Rule> rulesByKey = Maps.newHashMap();
+ private final Map<String, Component> componentsByKey = Maps.newHashMap();
+ private final Map<String, Component> projectsByKey = Maps.newHashMap();
+ private final Map<String, ActionPlan> actionPlansByKey = Maps.newHashMap();
+ private final Map<String, User> usersByLogin = Maps.newHashMap();
+ private boolean maxResultsReached;
+ private Paging paging;
+
+ public DefaultIssueQueryResult(List<Issue> issues){
+ this.issues = issues;
+ }
+
+ public DefaultIssueQueryResult addRules(Collection<Rule> rules){
+ for (Rule rule : rules) {
+ rulesByKey.put(rule.ruleKey(), rule);
+ }
+ return this;
+ }
+
+ public DefaultIssueQueryResult addComponents(Collection<Component> components){
+ for (Component component : components) {
+ componentsByKey.put(component.key(), component);
+ }
+ return this;
+ }
+
+ public DefaultIssueQueryResult addProjects(Collection<Component> projects){
+ for (Component project : projects) {
+ projectsByKey.put(project.key(), project);
+ }
+ return this;
+ }
+
+ public DefaultIssueQueryResult addActionPlans(Collection<ActionPlan> actionPlans){
+ for (ActionPlan actionPlan : actionPlans) {
+ actionPlansByKey.put(actionPlan.key(), actionPlan);
+ }
+ return this;
+ }
+
+ public DefaultIssueQueryResult addUsers(Collection<User> users){
+ for (User user : users) {
+ usersByLogin.put(user.login(), user);
+ }
+ return this;
+ }
+
+ public DefaultIssueQueryResult setMaxResultsReached(boolean maxResultsReached){
+ this.maxResultsReached = maxResultsReached;
+ return this;
+ }
+
+ public DefaultIssueQueryResult setPaging(Paging paging){
+ this.paging = paging;
+ return this;
+ }
+
+ @Override
+ public List<Issue> issues() {
+ return issues;
+ }
+
+ @Override
+ public Issue first() {
+ return issues != null && !issues.isEmpty() ? issues.get(0) : null;
+ }
+
+ @Override
+ public Rule rule(Issue issue) {
+ return rulesByKey.get(issue.ruleKey());
+ }
+
+ @Override
+ public Collection<Rule> rules() {
+ return rulesByKey.values();
+ }
+
+ @Override
+ public Component component(Issue issue) {
+ return componentsByKey.get(issue.componentKey());
+ }
+
+ @Override
+ public Collection<Component> components() {
+ return componentsByKey.values();
+ }
+
+ @Override
+ public Component project(Issue issue) {
+ return projectsByKey.get(issue.projectKey());
+ }
+
+ @Override
+ public Collection<Component> projects() {
+ return projectsByKey.values();
+ }
+
+ @Override
+ public ActionPlan actionPlan(Issue issue) {
+ return actionPlansByKey.get(issue.actionPlanKey());
+ }
+
+ @Override
+ public Collection<ActionPlan> actionPlans() {
+ return actionPlansByKey.values();
+ }
+
+ @Override
+ public Collection<User> users() {
+ return usersByLogin.values();
+ }
+
+ @Override
+ @CheckForNull
+ public User user(String login) {
+ return usersByLogin.get(login);
+ }
+
+ @Override
+ public boolean maxResultsReached() {
+ return maxResultsReached;
+ }
+
+ @Override
+ public Paging paging() {
+ return paging;
+ }
+
+
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueQueryResultTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueQueryResultTest.java
index c3241d569c6..b1018bd62a8 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueQueryResultTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueQueryResultTest.java
@@ -23,18 +23,19 @@ import org.junit.Test;
import org.sonar.api.issue.Issue;
import java.util.Arrays;
+import java.util.Collections;
import static org.fest.assertions.Assertions.assertThat;
public class DefaultIssueQueryResultTest {
@Test
public void test_first_issue() {
- DefaultIssueQueryResult result = new DefaultIssueQueryResult();
+ DefaultIssueQueryResult result = new DefaultIssueQueryResult(Collections.<Issue>emptyList());
assertThat(result.first()).isNull();
Issue first = new DefaultIssue();
Issue second = new DefaultIssue();
- result.setIssues(Arrays.asList(first, second));
+ result = new DefaultIssueQueryResult(Arrays.asList(first, second));
assertThat(result.first()).isSameAs(first);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
index 42c404ada63..34789bb72ce 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
@@ -76,8 +76,7 @@ public class IssueNotificationsTest {
.setFieldDiff(context, "status", "OPEN", "RESOLVED")
.setComponentKey("struts:Action")
.setProjectKey("struts");
- DefaultIssueQueryResult queryResult = new DefaultIssueQueryResult();
- queryResult.setIssues(Arrays.<Issue>asList(issue));
+ DefaultIssueQueryResult queryResult = new DefaultIssueQueryResult(Arrays.<Issue>asList(issue));
queryResult.addProjects(Arrays.<Component>asList(new Project("struts")));
Notification notification = issueNotifications.sendChanges(issue, context, queryResult);