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.issue.internal.DefaultIssue;
25 import org.sonar.api.issue.internal.IssueChangeContext;
26 import org.sonar.api.resources.Project;
27 import org.sonar.api.rules.Rule;
28 import org.sonar.api.rules.RuleFinder;
29 import org.sonar.batch.issue.IssueCache;
30 import org.sonar.core.DryRunIncompatible;
31 import org.sonar.core.issue.IssueNotifications;
37 public class SendIssueNotificationsPostJob implements PostJob {
39 private final IssueCache issueCache;
40 private final IssueNotifications notifications;
41 private final RuleFinder ruleFinder;
43 public SendIssueNotificationsPostJob(IssueCache issueCache, IssueNotifications notifications, RuleFinder ruleFinder) {
44 this.issueCache = issueCache;
45 this.notifications = notifications;
46 this.ruleFinder = ruleFinder;
50 public void executeOn(Project project, SensorContext context) {
51 sendNotifications(project);
54 private void sendNotifications(Project project) {
56 IssueChangeContext context = IssueChangeContext.createScan(project.getAnalysisDate());
57 for (DefaultIssue issue : issueCache.all()) {
58 if (issue.isNew() && issue.resolution() == null) {
61 if (!issue.isNew() && issue.isChanged() && issue.mustSendNotifications()) {
62 Rule rule = ruleFinder.findByKey(issue.ruleKey());
63 // TODO warning - rules with status REMOVED are currently ignored, but should not
65 notifications.sendChanges(issue, context, rule, project, null);
70 notifications.sendNewIssues(project, newIssues);