summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-01-06 17:53:20 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-01-06 18:04:45 +0100
commitbbe7929881d6c2a79bb69dd8cf19b5a6884360b7 (patch)
tree2b537a723bf05ba034b4f9605ef705f2687e82a4 /plugins
parent37bc37986738411fec19925b3c745b78f115c6ee (diff)
downloadsonarqube-bbe7929881d6c2a79bb69dd8cf19b5a6884360b7.tar.gz
sonarqube-bbe7929881d6c2a79bb69dd8cf19b5a6884360b7.zip
SONAR-5912 refactor SendIssueNotificationPostJob
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java41
1 files changed, 30 insertions, 11 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
index 3fe3c0cdfa2..6dd705e21bd 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
@@ -58,22 +58,41 @@ public class SendIssueNotificationsPostJob implements PostJob {
private void sendNotifications(Project project) {
IssuesBySeverity newIssues = new IssuesBySeverity();
IssueChangeContext context = IssueChangeContext.createScan(project.getAnalysisDate());
- Map<DefaultIssue, Rule> shouldSentNotification = new LinkedHashMap<DefaultIssue, Rule>();
+ Map<DefaultIssue, Rule> changedIssuesRuleMap = new LinkedHashMap<>();
for (DefaultIssue issue : issueCache.all()) {
- if (issue.isNew() && issue.resolution() == null) {
+ if (isNew(issue)) {
newIssues.add(issue);
+ } else if (hasChangedAndNeedNotification(issue)) {
+ addIssueToMap(issue, changedIssuesRuleMap);
}
- if (!issue.isNew() && issue.isChanged() && issue.mustSendNotifications()) {
- Rule rule = ruleFinder.findByKey(issue.ruleKey());
- // TODO warning - rules with status REMOVED are currently ignored, but should not
- if (rule != null) {
- shouldSentNotification.put(issue, rule);
- }
- }
}
- if (!shouldSentNotification.isEmpty()) {
- notifications.sendChanges(shouldSentNotification, context, project, null, null);
+ sendChangedIssues(project, context, changedIssuesRuleMap);
+ sendNewIssues(project, newIssues);
+ }
+
+ private void addIssueToMap(DefaultIssue issue, Map<DefaultIssue, Rule> changedIssuesRuleMap) {
+ Rule rule = ruleFinder.findByKey(issue.ruleKey());
+ // TODO warning - rules with status REMOVED are currently ignored, but should not
+ if (rule != null) {
+ changedIssuesRuleMap.put(issue, rule);
+ }
+ }
+
+ private boolean isNew(DefaultIssue issue) {
+ return issue.isNew() && issue.resolution() == null;
+ }
+
+ private boolean hasChangedAndNeedNotification(DefaultIssue issue) {
+ return !issue.isNew() && issue.isChanged() && issue.mustSendNotifications();
+ }
+
+ private void sendChangedIssues(Project project, IssueChangeContext context, Map<DefaultIssue, Rule> changedIssuesRuleMap) {
+ if (!changedIssuesRuleMap.isEmpty()) {
+ notifications.sendChanges(changedIssuesRuleMap, context, project, null, null);
}
+ }
+
+ private void sendNewIssues(Project project, IssuesBySeverity newIssues) {
if (!newIssues.isEmpty()) {
notifications.sendNewIssues(project, newIssues);
}