* 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.plugins.core;
import com.google.common.collect.ImmutableList;
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter;
import org.sonar.plugins.core.measurefilters.ProjectFilter;
import org.sonar.plugins.core.notifications.alerts.NewAlerts;
-import org.sonar.plugins.core.notifications.reviews.ChangesInReviewAssignedToMeOrCreatedByMe;
-import org.sonar.plugins.core.notifications.reviews.NewFalsePositiveReview;
-import org.sonar.plugins.core.notifications.violations.NewViolationsOnFirstDifferentialPeriod;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
import org.sonar.plugins.core.sensors.*;
import org.sonar.plugins.core.timemachine.*;
import org.sonar.plugins.core.web.Lcom4Viewer;
import org.sonar.plugins.core.web.TestsViewer;
import org.sonar.plugins.core.widgets.*;
-import org.sonar.plugins.core.widgets.issues.ActionPlansWidget;
import org.sonar.plugins.core.widgets.issues.*;
-import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.ProjectReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.ReviewsPerDeveloperWidget;
import java.util.List;
NoSonarFilter.class,
DirectoriesDecorator.class,
FilesDecorator.class,
- ReviewNotifications.class,
IndexProjectPostJob.class,
ManualMeasureDecorator.class,
+++ /dev/null
-/*
- * 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.plugins.core.sensors;
-
-import org.sonar.api.BatchExtension;
-import org.sonar.api.database.model.User;
-import org.sonar.api.notifications.Notification;
-import org.sonar.api.notifications.NotificationManager;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.security.UserFinder;
-import org.sonar.core.review.ReviewDto;
-
-import javax.annotation.Nullable;
-
-public class ReviewNotifications implements BatchExtension {
- private NotificationManager notificationManager;
- private UserFinder userFinder;
-
- public ReviewNotifications(NotificationManager notificationManager, UserFinder userFinder) {
- this.notificationManager = notificationManager;
- this.userFinder = userFinder;
- }
-
- void notifyReopened(ReviewDto review, Project project, Resource resource) {
- Notification notification = createReviewNotification(review, project, resource)
- .setFieldValue("old.status", review.getStatus())
- .setFieldValue("new.status", ReviewDto.STATUS_REOPENED)
- .setFieldValue("old.resolution", review.getResolution())
- .setFieldValue("new.resolution", null);
- notificationManager.scheduleForSending(notification);
- }
-
- void notifyClosed(ReviewDto review, Project project, @Nullable Resource resource) {
- Notification notification = createReviewNotification(review, project, resource)
- .setFieldValue("old.status", review.getStatus())
- .setFieldValue("new.status", ReviewDto.STATUS_CLOSED);
- notificationManager.scheduleForSending(notification);
- }
-
- private Notification createReviewNotification(ReviewDto review, Project project, @Nullable Resource resource) {
- return new Notification("review-changed")
- .setDefaultMessage("Review #" + review.getId() + " has changed.")
- .setFieldValue("reviewId", String.valueOf(review.getId()))
- .setFieldValue("project", project.getRoot().getLongName())
- .setFieldValue("projectId", String.valueOf(project.getId()))
- .setFieldValue("resource", resource != null ? resource.getLongName() : null)
- .setFieldValue("title", review.getTitle())
- .setFieldValue("creator", getCreator(review))
- .setFieldValue("assignee", getAssignee(review));
- }
-
- private String getCreator(ReviewDto review) {
- if (review.getUserId() == null) { // no creator and in fact this should never happen in real-life, however happens during unit tests
- return null;
- }
- User user = userFinder.findById(review.getUserId());
- return user != null ? user.getLogin() : null;
- }
-
- private String getAssignee(ReviewDto review) {
- if (review.getAssigneeId() == null) { // not assigned
- return null;
- }
- User user = userFinder.findById(review.getAssigneeId().intValue());
- return user != null ? user.getLogin() : null;
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+
+
+}
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);
}
}
.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);
import org.sonar.api.utils.Paging;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.DefaultIssueComment;
+import org.sonar.core.issue.DefaultIssueQueryResult;
import org.sonar.core.issue.db.IssueChangeDao;
import org.sonar.core.issue.db.IssueDao;
import org.sonar.core.issue.db.IssueDto;
+++ /dev/null
-/*
- * 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.server.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;
- }
-
-
-}