2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.plugins.core.issue.notification;
22 import org.sonar.api.batch.PostJob;
23 import org.sonar.api.batch.SensorContext;
24 import org.sonar.api.resources.Project;
25 import org.sonar.api.rules.Rule;
26 import org.sonar.api.rules.RuleFinder;
27 import org.sonar.batch.issue.IssueCache;
28 import org.sonar.core.issue.DefaultIssue;
29 import org.sonar.core.issue.IssueChangeContext;
30 import org.sonar.core.issue.IssueNotifications;
35 public class SendIssueNotificationsPostJob implements PostJob {
37 private final IssueCache issueCache;
38 private final IssueNotifications notifications;
39 private final RuleFinder ruleFinder;
41 public SendIssueNotificationsPostJob(IssueCache issueCache, IssueNotifications notifications, RuleFinder ruleFinder) {
42 this.issueCache = issueCache;
43 this.notifications = notifications;
44 this.ruleFinder = ruleFinder;
48 public void executeOn(Project project, SensorContext context) {
49 sendNotifications(project);
52 private void sendNotifications(Project project) {
54 IssueChangeContext context = IssueChangeContext.createScan(project.getAnalysisDate());
55 for (DefaultIssue issue : issueCache.all()) {
56 if (issue.isNew() && issue.resolution() == null) {
59 if (issue.isChanged() && issue.diffs() != null) {
60 Rule rule = ruleFinder.findByKey(issue.ruleKey());
61 // TODO warning - rules with status REMOVED are currently ignored, but should not
63 notifications.sendChanges(issue, context, rule, project, null);
68 notifications.sendNewIssues(project, newIssues);