From: Simon Brandhof Date: Fri, 22 May 2015 08:59:23 +0000 (+0200) Subject: SONAR-6567 disable extension point NotificationDispatcher in batch X-Git-Tag: 5.2-RC1~1866 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b15cb8e004d119a44189e4808ff98fe49a9a66e7;p=sonarqube.git SONAR-6567 disable extension point NotificationDispatcher in batch Currently it's only removed from API. Will be removed from batch after that events are in Compute Engine (for change of quality gate status) --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java index 4662dfb7fab..b6c4bd93d1a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java @@ -24,6 +24,9 @@ import org.sonar.api.notifications.*; import java.util.Collection; import java.util.Map; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; /** * This dispatcher means: "notify me each new alert event". diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java index d2e921fd916..6a65353af0a 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java @@ -24,8 +24,8 @@ import com.google.common.collect.Multimap; import org.junit.Test; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationManager; import static org.mockito.Mockito.*; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java index 674b68ba43e..7c6b68cba55 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java @@ -28,7 +28,7 @@ import com.google.common.collect.Lists; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.IssueChangeContext; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationManager; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.utils.log.Logger; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 5eccb7e9e4e..dae69ccf3f4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -27,7 +27,7 @@ import org.sonar.api.issue.ActionPlan; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.IssueChangeContext; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationManager; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.rules.Rule; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java index e12e2715864..b38eb2f855b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java @@ -25,6 +25,9 @@ import org.sonar.api.notifications.*; import javax.annotation.Nullable; import java.util.Collection; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; /** * This dispatcher means: "notify me when a change is done on an issue that is assigned to me or reported by me". diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java index 16b3de6fc05..e4f0a5f81d9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java @@ -27,6 +27,9 @@ import org.sonar.api.notifications.*; import java.util.Collection; import java.util.Map; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; /** * This dispatcher means: "notify me when an issue is resolved as false positive or won't fix". diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java index b5d3237ded5..3810279554f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java @@ -24,6 +24,9 @@ import com.google.common.collect.Multimap; import org.sonar.api.notifications.*; import java.util.Collection; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; /** * This dispatcher means: "notify me when new issues are introduced during project analysis" diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java index c8a9726b6b2..e346b1af744 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java @@ -24,6 +24,9 @@ import org.sonar.api.notifications.*; import java.util.Collection; import java.util.Map; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; /** * This dispatcher means: "notify me when new issues are introduced during project analysis" diff --git a/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java index 976a97e652f..cf43dca0c31 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java @@ -22,7 +22,7 @@ package org.sonar.server.notifications; import com.google.common.collect.Lists; import org.sonar.api.server.ServerSide; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationDispatcherMetadata; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; diff --git a/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java index c4def6da424..e13137ebead 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java @@ -38,7 +38,7 @@ import org.sonar.api.server.ServerSide; import org.sonar.api.config.Settings; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcher; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.notification.DefaultNotificationManager; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java index de0a0cd79e9..fdcefadb1ba 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java @@ -27,6 +27,9 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.notifications.*; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java index 73b8979d22f..4f42809dfb7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java @@ -25,9 +25,9 @@ import org.junit.Test; import org.sonar.api.issue.Issue; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationDispatcherMetadata; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java deleted file mode 100644 index 937da1b1398..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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. - */ -///* -// * SonarQube, open source software quality management tool. -// * Copyright (C) 2008-2014 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.notification; -// -//import org.junit.Before; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.runners.MockitoJUnitRunner; -//import org.sonar.api.issue.internal.DefaultIssue; -//import org.sonar.api.issue.internal.IssueChangeContext; -//import org.sonar.api.notifications.Notification; -//import org.sonar.api.notifications.NotificationManager; -//import org.sonar.api.resources.File; -//import org.sonar.api.resources.Project; -//import org.sonar.core.component.ResourceComponent; -//import org.sonar.server.notifications.NotificationService; -// -//import java.util.Date; -// -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.mockito.Mockito.mock; -// -//@RunWith(MockitoJUnitRunner.class) -//public class IssueNotificationsTest { -// -// @Mock -// NotificationManager manager; -// -// IssueNotifications issueNotifications; -// -// @Before -// public void setUp() throws Exception { -// issueNotifications = new IssueNotifications(manager, mock(NotificationService.class)); -// } -// -// // @Test -// // public void should_send_new_issues() throws Exception { -// // Date date = DateUtils.parseDateTime("2013-05-18T13:00:03+0200"); -// // Project project = new Project("struts").setAnalysisDate(date); -// // IssuesBySeverity issuesBySeverity = mock(IssuesBySeverity.class); -// // when(issuesBySeverity.size()).thenReturn(42); -// // when(issuesBySeverity.issues("MINOR")).thenReturn(10); -// // Notification notification = issueNotifications.sendNewIssues(project, issuesBySeverity); -// // -// // assertThat(notification.getFieldValue("count")).isEqualTo("42"); -// // assertThat(notification.getFieldValue("count-MINOR")).isEqualTo("10"); -// // assertThat(DateUtils.parseDateTime(notification.getFieldValue("projectDate"))).isEqualTo(date); -// // Mockito.verify(manager).scheduleForSending(notification); -// // } -// -// @Test -// public void should_send_changes() throws Exception { -// IssueChangeContext context = IssueChangeContext.createScan(new Date()); -// DefaultIssue issue = new DefaultIssue() -// .setMessage("the message") -// .setKey("ABCDE") -// .setAssignee("freddy") -// .setFieldChange(context, "resolution", null, "FIXED") -// .setFieldChange(context, "status", "OPEN", "RESOLVED") -// .setFieldChange(context, "assignee", "simon", null) -// .setSendNotifications(true) -// .setComponentKey("struts:Action") -// .setProjectKey("struts"); -// -// Notification notification = issueNotifications.sendChanges(issue, "charlie", null, new Project("struts"), null, null, false); -// -// assertThat(notification.getFieldValue("message")).isEqualTo("the message"); -// assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE"); -// assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action"); -// assertThat(notification.getFieldValue("componentName")).isNull(); -// assertThat(notification.getFieldValue("old.resolution")).isNull(); -// assertThat(notification.getFieldValue("new.resolution")).isEqualTo("FIXED"); -// assertThat(notification.getFieldValue("old.status")).isEqualTo("OPEN"); -// assertThat(notification.getFieldValue("new.status")).isEqualTo("RESOLVED"); -// assertThat(notification.getFieldValue("old.assignee")).isEqualTo("simon"); -// assertThat(notification.getFieldValue("new.assignee")).isNull(); -// Mockito.verify(manager).scheduleForSending(notification); -// } -// -// @Test -// public void should_send_changes_with_comment() throws Exception { -// DefaultIssue issue = new DefaultIssue() -// .setMessage("the message") -// .setKey("ABCDE") -// .setAssignee("freddy") -// .setComponentKey("struts:Action") -// .setProjectKey("struts"); -// Notification notification = issueNotifications.sendChanges(issue, "charlie", null, new Project("struts"), null, "I don't know how to fix it?", false); -// -// assertThat(notification.getFieldValue("message")).isEqualTo("the message"); -// assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE"); -// assertThat(notification.getFieldValue("comment")).isEqualTo("I don't know how to fix it?"); -// Mockito.verify(manager).scheduleForSending(notification); -// } -// -// @Test -// public void should_send_changes_with_component_name() throws Exception { -// IssueChangeContext context = IssueChangeContext.createScan(new Date()); -// DefaultIssue issue = new DefaultIssue() -// .setMessage("the message") -// .setKey("ABCDE") -// .setAssignee("freddy") -// .setFieldChange(context, "resolution", null, "FIXED") -// .setSendNotifications(true) -// .setComponentKey("struts:Action.java") -// .setProjectKey("struts"); -// Notification notification = issueNotifications.sendChanges(issue, "charlie", null, new Project("struts"), -// new ResourceComponent(File.create("Action.java", "Action.java", null, false).setEffectiveKey("struts:Action.java")), null, false); -// -// assertThat(notification.getFieldValue("message")).isEqualTo("the message"); -// assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE"); -// assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action.java"); -// assertThat(notification.getFieldValue("componentName")).isEqualTo("Action.java"); -// assertThat(notification.getFieldValue("old.resolution")).isNull(); -// assertThat(notification.getFieldValue("new.resolution")).isEqualTo("FIXED"); -// Mockito.verify(manager).scheduleForSending(notification); -// } -// -// @Test -// public void should_not_send_changes_if_no_diffs() throws Exception { -// DefaultIssue issue = new DefaultIssue() -// .setMessage("the message") -// .setKey("ABCDE") -// .setComponentKey("struts:Action") -// .setProjectKey("struts"); -// issueNotifications.sendChanges(issue, "charlie", null, new Project("struts"), null, null, false); -// -// Mockito.verifyZeroInteractions(manager); -// } -//} - diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java index 5bf25f7e65f..9173ef7227c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java @@ -26,8 +26,8 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationManager; import static org.mockito.Mockito.*; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java index 53d13441758..656d3bb4231 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java @@ -25,8 +25,8 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationManager; import static org.mockito.Mockito.*; diff --git a/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationCenterTest.java b/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationCenterTest.java index 604efb86d35..ecd6ef52117 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationCenterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationCenterTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationDispatcherMetadata; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java index 9534400e47a..c818dee6eac 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java @@ -26,7 +26,7 @@ import org.mockito.stubbing.Answer; import org.sonar.api.config.Settings; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcher; import org.sonar.core.notification.DefaultNotificationManager; import org.sonar.core.properties.PropertiesDao; import org.sonar.jpa.session.DatabaseSessionFactory; diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/GenerateQualityGateEvents.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/GenerateQualityGateEvents.java index 030571ce8d5..3b7c7a4b48d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/GenerateQualityGateEvents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/GenerateQualityGateEvents.java @@ -30,7 +30,7 @@ import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metric.Level; import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationManager; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; @@ -85,7 +85,7 @@ public class GenerateQualityGateEvents implements Decorator { private void checkQualityGateStatusChange(Resource resource, DecoratorContext context, Measure currentStatus, Measure pastStatus) { String alertText = currentStatus.getAlertText(); Level alertLevel = currentStatus.getDataAsLevel(); - String alertName = null; + String alertName; boolean isNewAlert = true; if (pastStatus != null && pastStatus.getDataAsLevel() != alertLevel) { // The alert status has changed diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java index 5cf93a9d419..ec10ba85a5c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java @@ -28,7 +28,7 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationManager; +import org.sonar.core.notification.NotificationManager; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; diff --git a/sonar-core/src/main/java/org/sonar/core/notification/DefaultNotificationManager.java b/sonar-core/src/main/java/org/sonar/core/notification/DefaultNotificationManager.java index e6776438549..99dbf58c3e2 100644 --- a/sonar-core/src/main/java/org/sonar/core/notification/DefaultNotificationManager.java +++ b/sonar-core/src/main/java/org/sonar/core/notification/DefaultNotificationManager.java @@ -30,8 +30,6 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.RequiresDB; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; import org.sonar.api.utils.SonarException; import org.sonar.core.notification.db.NotificationQueueDao; import org.sonar.core.notification.db.NotificationQueueDto; diff --git a/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcher.java b/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcher.java new file mode 100644 index 00000000000..33a127af77f --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcher.java @@ -0,0 +1,130 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.ExtensionPoint; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.server.ServerSide; + +/** + *

+ * Plugins should extend this class to provide logic to determine which users are interested in receiving notifications, + * along with which delivery channels they selected. + *

+ * For example: + * + * + * @since 2.10 + */ +@ServerSide +@ExtensionPoint +public abstract class NotificationDispatcher { + + private final String notificationType; + + /** + * Additional information related to the notification, which will be used + * to know who should receive the notification. + */ + public interface Context { + /** + * This method is not used any longer. Calling it will result in an {@link UnsupportedOperationException}. + * + * @deprecated Use {@link #addUser(String, NotificationChannel)} instead. + */ + @Deprecated + void addUser(String userLogin); + + /** + * Adds a user that will be notified through the given notification channel. + * + * @param userLogin the user login + * @param notificationChannel the notification channel to use for this user + */ + void addUser(String userLogin, NotificationChannel notificationChannel); + } + + /** + * Creates a new dispatcher for notifications of the given type. + * + * @param notificationType the type of notifications handled by this dispatcher + */ + public NotificationDispatcher(String notificationType) { + this.notificationType = notificationType; + } + + /** + * Creates a new generic dispatcher, used for any kind of notification. + *

+ * Should be avoided and replaced by the other constructor - as it is easier to understand that a + * dispatcher listens for a specific type of notification. + */ + public NotificationDispatcher() { + this(""); + } + + /** + * The unique key of this dispatcher. By default it's the class name without the package prefix. + *

+ * The related label in l10n bundles is 'notification.dispatcher.', for example 'notification.dispatcher.NewFalsePositive'. + */ + public String getKey() { + return getClass().getSimpleName(); + } + + /** + * @since 5.1 + */ + public String getType() { + return notificationType; + } + + /** + *

+ * Performs the dispatch. + *

+ */ + public final void performDispatch(Notification notification, Context context) { + if (StringUtils.equals(notification.getType(), notificationType) || StringUtils.equals("", notificationType)) { + dispatch(notification, context); + } + } + + /** + *

+ * Implements the logic that defines which users will receive the notification. + *

+ * The purpose of this method is to populate the context object with users, based on the type of notification and the content of the notification. + */ + public abstract void dispatch(Notification notification, Context context); + + @Override + public String toString() { + return getKey(); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcherMetadata.java b/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcherMetadata.java new file mode 100644 index 00000000000..2eb04a59c21 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcherMetadata.java @@ -0,0 +1,102 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import com.google.common.collect.Maps; +import java.util.Map; +import org.sonar.api.server.ServerSide; + +/** + *

+ * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order + * to tell more about them. + *

+ * Instances of these classes must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}. + * + * @since 3.5 + */ +@ServerSide +public final class NotificationDispatcherMetadata { + + public static final String GLOBAL_NOTIFICATION = "globalNotification"; + public static final String PER_PROJECT_NOTIFICATION = "perProjectNotification"; + + private String dispatcherKey; + private Map properties; + + private NotificationDispatcherMetadata(String dispatcherKey) { + this.dispatcherKey = dispatcherKey; + this.properties = Maps.newHashMap(); + } + + /** + * Creates a new metadata instance for the given dispatcher. + *

+ * By default the key is the class name without package. It can be changed by overriding + * {@link NotificationDispatcher#getKey()}. + */ + public static NotificationDispatcherMetadata create(String dispatcherKey) { + return new NotificationDispatcherMetadata(dispatcherKey); + } + + /** + * Sets a property on this metadata object. + */ + public NotificationDispatcherMetadata setProperty(String key, String value) { + properties.put(key, value); + return this; + } + + /** + * Gives the property for the given key. + */ + public String getProperty(String key) { + return properties.get(key); + } + + /** + * Returns the unique key of the dispatcher. + */ + public String getDispatcherKey() { + return dispatcherKey; + } + + @Override + public String toString() { + return dispatcherKey; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationDispatcherMetadata that = (NotificationDispatcherMetadata) o; + return dispatcherKey.equals(that.dispatcherKey); + } + + @Override + public int hashCode() { + return dispatcherKey.hashCode(); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/notification/NotificationManager.java b/sonar-core/src/main/java/org/sonar/core/notification/NotificationManager.java new file mode 100644 index 00000000000..f9b5e0a8489 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/notification/NotificationManager.java @@ -0,0 +1,80 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import com.google.common.collect.Multimap; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.server.ServerSide; +import org.sonar.api.batch.InstantiationStrategy; + +import javax.annotation.Nullable; + +import java.util.List; + +/** + *

+ * The notification manager receives notifications and is in charge of storing them so that they are processed by the notification service. + *

+ *

+ * Pico provides an instance of this class, and plugins just need to create notifications and pass them to this manager with + * the {@link NotificationManager#scheduleForSending(Notification)} method. + *

+ * + * @since 2.10 + */ +@ServerSide +@BatchSide +@InstantiationStrategy(InstantiationStrategy.PER_BATCH) +public interface NotificationManager { + + /** + * Receives a notification and stores it so that it is processed by the notification service. + * + * @param notification the notification. + */ + void scheduleForSending(Notification notification); + + /** + * Receives notifications and stores them so that they are processed by the notification service. + * + * @param notifications the notifications. + * @since 3.7.1 + */ + void scheduleForSending(List notifications); + + /** + *

+ * Returns the list of users who subscribed to the given dispatcher, along with the notification channels (email, twitter, ...) that they choose + * for this dispatcher. + *

+ *

+ * The resource ID can be null in case of notifications that have nothing to do with a specific project (like system notifications). + *

+ * + * @param dispatcher the dispatcher for which this list of users is requested + * @param resourceId the optional resource which is concerned by this request + * @return the list of user login along with the subscribed channels + */ + Multimap findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, @Nullable Integer resourceId); + + Multimap findNotificationSubscribers(NotificationDispatcher dispatcher, @Nullable String componentKey); +} diff --git a/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java b/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java index 9e1dae9de30..c5e60e1afa5 100644 --- a/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java @@ -28,7 +28,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; import org.sonar.core.notification.db.NotificationQueueDao; import org.sonar.core.notification.db.NotificationQueueDto; import org.sonar.core.properties.PropertiesDao; diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java new file mode 100644 index 00000000000..dcd80b4c08d --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java @@ -0,0 +1,44 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; + +public class NotificationChannelTest { + + @Test + public void defaultMethods() { + NotificationChannel channel = new FakeNotificationChannel(); + assertThat(channel.getKey(), is("FakeNotificationChannel")); + assertThat(channel.toString(), is("FakeNotificationChannel")); + } + + class FakeNotificationChannel extends NotificationChannel { + @Override + public void deliver(Notification notification, String username) { + } + } + +} diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java new file mode 100644 index 00000000000..c19e5453be6 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java @@ -0,0 +1,46 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NotificationDispatcherMetadataTest { + + private NotificationDispatcherMetadata metadata; + + @Before + public void init() { + metadata = NotificationDispatcherMetadata.create("NewViolations").setProperty("global", "true"); + } + + @Test + public void shouldReturnDispatcherKey() { + assertThat(metadata.getDispatcherKey()).isEqualTo("NewViolations"); + } + + @Test + public void shouldReturnProperty() { + assertThat(metadata.getProperty("global")).isEqualTo("true"); + assertThat(metadata.getProperty("per-project")).isNull(); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java new file mode 100644 index 00000000000..89296125536 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java @@ -0,0 +1,101 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.notification; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class NotificationDispatcherTest { + + @Mock + private NotificationChannel channel; + + @Mock + private Notification notification; + + @Mock + private NotificationDispatcher.Context context; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + when(notification.getType()).thenReturn("event1"); + } + + @Test + public void defaultMethods() { + NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher(); + assertThat(dispatcher.getKey(), is("FakeGenericNotificationDispatcher")); + assertThat(dispatcher.toString(), is("FakeGenericNotificationDispatcher")); + } + + @Test + public void shouldAlwaysRunDispatchForGenericDispatcher() { + NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher(); + dispatcher.performDispatch(notification, context); + + verify(context, times(1)).addUser("user1", channel); + } + + @Test + public void shouldNotAlwaysRunDispatchForSpecificDispatcher() { + NotificationDispatcher dispatcher = new FakeSpecificNotificationDispatcher(); + + // a "event1" notif is sent + dispatcher.performDispatch(notification, context); + verify(context, never()).addUser("user1", channel); + + // now, a "specific-event" notif is sent + when(notification.getType()).thenReturn("specific-event"); + dispatcher.performDispatch(notification, context); + verify(context, times(1)).addUser("user1", channel); + } + + class FakeGenericNotificationDispatcher extends NotificationDispatcher { + @Override + public void dispatch(Notification notification, Context context) { + context.addUser("user1", channel); + } + } + + class FakeSpecificNotificationDispatcher extends NotificationDispatcher { + + public FakeSpecificNotificationDispatcher() { + super("specific-event"); + } + + @Override + public void dispatch(Notification notification, Context context) { + context.addUser("user1", channel); + } + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java index 0666e7260f1..6f947a29299 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java @@ -28,11 +28,8 @@ import java.io.Serializable; import java.util.Map; /** - *

* This class represents a notification that will be delivered to users. This is a general concept and it has no - * knowledge of the possible ways to be delivered (see {@link NotificationChannel}) or of the users who should - * receive it (see {@link NotificationDispatcher}). - *

+ * knowledge of the possible ways to be delivered (see {@link NotificationChannel}). *

* When creating a new notification, it is strongly advised to give a default message that can be used by channels * that don't want to specifically format messages for different notification types. You can use diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcher.java b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcher.java deleted file mode 100644 index 1bffbee522a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcher.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.ExtensionPoint; -import org.sonar.api.server.ServerSide; - -/** - *

- * Plugins should extend this class to provide logic to determine which users are interested in receiving notifications, - * along with which delivery channels they selected. - *

- * For example: - *
    - *
  • notify me by email when someone comments an issue reported by me
  • - *
  • notify me by twitter when someone comments an issue assigned to me
  • - *
  • notify me by Jabber when someone mentions me in an issue comment
  • - *
  • send me by SMS when there are system notifications (like password reset, account creation, ...)
  • - *
- * - * @since 2.10 - */ -@ServerSide -@ExtensionPoint -public abstract class NotificationDispatcher { - - private final String notificationType; - - /** - * Additional information related to the notification, which will be used - * to know who should receive the notification. - */ - public interface Context { - /** - * This method is not used any longer. Calling it will result in an {@link UnsupportedOperationException}. - * - * @deprecated Use {@link #addUser(String, NotificationChannel)} instead. - */ - @Deprecated - void addUser(String userLogin); - - /** - * Adds a user that will be notified through the given notification channel. - * - * @param userLogin the user login - * @param notificationChannel the notification channel to use for this user - */ - void addUser(String userLogin, NotificationChannel notificationChannel); - } - - /** - * Creates a new dispatcher for notifications of the given type. - * - * @param notificationType the type of notifications handled by this dispatcher - */ - public NotificationDispatcher(String notificationType) { - this.notificationType = notificationType; - } - - /** - * Creates a new generic dispatcher, used for any kind of notification. - *

- * Should be avoided and replaced by the other constructor - as it is easier to understand that a - * dispatcher listens for a specific type of notification. - */ - public NotificationDispatcher() { - this(""); - } - - /** - * The unique key of this dispatcher. By default it's the class name without the package prefix. - *

- * The related label in l10n bundles is 'notification.dispatcher.', for example 'notification.dispatcher.NewFalsePositive'. - */ - public String getKey() { - return getClass().getSimpleName(); - } - - /** - * @since 5.1 - */ - public String getType() { - return notificationType; - } - - /** - *

- * Performs the dispatch. - *

- */ - public final void performDispatch(Notification notification, Context context) { - if (StringUtils.equals(notification.getType(), notificationType) || StringUtils.equals("", notificationType)) { - dispatch(notification, context); - } - } - - /** - *

- * Implements the logic that defines which users will receive the notification. - *

- * The purpose of this method is to populate the context object with users, based on the type of notification and the content of the notification. - */ - public abstract void dispatch(Notification notification, Context context); - - @Override - public String toString() { - return getKey(); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java deleted file mode 100644 index 37f73510385..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import com.google.common.collect.Maps; -import org.sonar.api.ExtensionPoint; -import org.sonar.api.server.ServerSide; - -import java.util.Map; - -/** - *

- * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order - * to tell more about them. - *

- * Instances of these classes must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}. - * - * @since 3.5 - */ -@ServerSide -@ExtensionPoint -public final class NotificationDispatcherMetadata { - - public static final String GLOBAL_NOTIFICATION = "globalNotification"; - public static final String PER_PROJECT_NOTIFICATION = "perProjectNotification"; - - private String dispatcherKey; - private Map properties; - - private NotificationDispatcherMetadata(String dispatcherKey) { - this.dispatcherKey = dispatcherKey; - this.properties = Maps.newHashMap(); - } - - /** - * Creates a new metadata instance for the given dispatcher. - *

- * By default the key is the class name without package. It can be changed by overriding - * {@link org.sonar.api.notifications.NotificationDispatcher#getKey()}. - */ - public static NotificationDispatcherMetadata create(String dispatcherKey) { - return new NotificationDispatcherMetadata(dispatcherKey); - } - - /** - * Sets a property on this metadata object. - */ - public NotificationDispatcherMetadata setProperty(String key, String value) { - properties.put(key, value); - return this; - } - - /** - * Gives the property for the given key. - */ - public String getProperty(String key) { - return properties.get(key); - } - - /** - * Returns the unique key of the dispatcher. - */ - public String getDispatcherKey() { - return dispatcherKey; - } - - @Override - public String toString() { - return dispatcherKey; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - NotificationDispatcherMetadata that = (NotificationDispatcherMetadata) o; - return dispatcherKey.equals(that.dispatcherKey); - } - - @Override - public int hashCode() { - return dispatcherKey.hashCode(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationManager.java b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationManager.java deleted file mode 100644 index ce67d176fbf..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationManager.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import com.google.common.collect.Multimap; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; -import org.sonar.api.batch.InstantiationStrategy; - -import javax.annotation.Nullable; - -import java.util.List; - -/** - *

- * The notification manager receives notifications and is in charge of storing them so that they are processed by the notification service. - *

- *

- * Pico provides an instance of this class, and plugins just need to create notifications and pass them to this manager with - * the {@link NotificationManager#scheduleForSending(Notification)} method. - *

- * - * @since 2.10 - */ -@ServerSide -@BatchSide -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public interface NotificationManager { - - /** - * Receives a notification and stores it so that it is processed by the notification service. - * - * @param notification the notification. - */ - void scheduleForSending(Notification notification); - - /** - * Receives notifications and stores them so that they are processed by the notification service. - * - * @param notifications the notifications. - * @since 3.7.1 - */ - void scheduleForSending(List notifications); - - /** - *

- * Returns the list of users who subscribed to the given dispatcher, along with the notification channels (email, twitter, ...) that they choose - * for this dispatcher. - *

- *

- * The resource ID can be null in case of notifications that have nothing to do with a specific project (like system notifications). - *

- * - * @param dispatcher the dispatcher for which this list of users is requested - * @param resourceId the optional resource which is concerned by this request - * @return the list of user login along with the subscribed channels - */ - Multimap findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, @Nullable Integer resourceId); - - Multimap findNotificationSubscribers(NotificationDispatcher dispatcher, @Nullable String componentKey); -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java deleted file mode 100644 index 0d2efb28f65..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class NotificationChannelTest { - - @Test - public void defaultMethods() { - NotificationChannel channel = new FakeNotificationChannel(); - assertThat(channel.getKey(), is("FakeNotificationChannel")); - assertThat(channel.toString(), is("FakeNotificationChannel")); - } - - class FakeNotificationChannel extends NotificationChannel { - @Override - public void deliver(Notification notification, String username) { - } - } - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java deleted file mode 100644 index 7acb3059132..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import org.junit.Before; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class NotificationDispatcherMetadataTest { - - private NotificationDispatcherMetadata metadata; - - @Before - public void init() { - metadata = NotificationDispatcherMetadata.create("NewViolations").setProperty("global", "true"); - } - - @Test - public void shouldReturnDispatcherKey() { - assertThat(metadata.getDispatcherKey()).isEqualTo("NewViolations"); - } - - @Test - public void shouldReturnProperty() { - assertThat(metadata.getProperty("global")).isEqualTo("true"); - assertThat(metadata.getProperty("per-project")).isNull(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java deleted file mode 100644 index 1925fed6e85..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api.notifications; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class NotificationDispatcherTest { - - @Mock - private NotificationChannel channel; - - @Mock - private Notification notification; - - @Mock - private NotificationDispatcher.Context context; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - when(notification.getType()).thenReturn("event1"); - } - - @Test - public void defaultMethods() { - NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher(); - assertThat(dispatcher.getKey(), is("FakeGenericNotificationDispatcher")); - assertThat(dispatcher.toString(), is("FakeGenericNotificationDispatcher")); - } - - @Test - public void shouldAlwaysRunDispatchForGenericDispatcher() { - NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher(); - dispatcher.performDispatch(notification, context); - - verify(context, times(1)).addUser("user1", channel); - } - - @Test - public void shouldNotAlwaysRunDispatchForSpecificDispatcher() { - NotificationDispatcher dispatcher = new FakeSpecificNotificationDispatcher(); - - // a "event1" notif is sent - dispatcher.performDispatch(notification, context); - verify(context, never()).addUser("user1", channel); - - // now, a "specific-event" notif is sent - when(notification.getType()).thenReturn("specific-event"); - dispatcher.performDispatch(notification, context); - verify(context, times(1)).addUser("user1", channel); - } - - class FakeGenericNotificationDispatcher extends NotificationDispatcher { - @Override - public void dispatch(Notification notification, Context context) { - context.addUser("user1", channel); - } - } - - class FakeSpecificNotificationDispatcher extends NotificationDispatcher { - - public FakeSpecificNotificationDispatcher() { - super("specific-event"); - } - - @Override - public void dispatch(Notification notification, Context context) { - context.addUser("user1", channel); - } - } - -}