]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6567 disable extension point NotificationDispatcher in batch
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 22 May 2015 08:59:23 +0000 (10:59 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 22 May 2015 12:24:53 +0000 (14:24 +0200)
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)

34 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java
server/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationCenterTest.java
server/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java
sonar-batch/src/main/java/org/sonar/batch/qualitygate/GenerateQualityGateEvents.java
sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java
sonar-core/src/main/java/org/sonar/core/notification/DefaultNotificationManager.java
sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcher.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/notification/NotificationDispatcherMetadata.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/notification/NotificationManager.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java
sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java
sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcher.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationManager.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java [deleted file]

index 4662dfb7fabdd5cd50762755a1c706ddb3b6dcbe..b6c4bd93d1ac045652b3ee1b1ce67891c11d0662 100644 (file)
@@ -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".
index d2e921fd9166eef4e8a917d21225c92bfb6c7621..6a65353af0aecc76d887d9b5e36f89939f8c2dfe 100644 (file)
@@ -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.*;
 
index 674b68ba43e426bb5a93ca2dfc780083702b21c1..7c6b68cba554f044c4772ab9e4689b4a63fcc402 100644 (file)
@@ -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;
index 5eccb7e9e4ede7ecea8fece7a86f92ae2dcf4bdb..dae69ccf3f4fbcc9f14a064403ce08fbcce30fb2 100644 (file)
@@ -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;
index e12e2715864c6f31e35844748f6b81e0507fdb4a..b38eb2f855b7ea7717e218cdb6ee52c7d2923935 100644 (file)
@@ -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".
index 16b3de6fc05d50aaedc9d87e895836f11e088647..e4f0a5f81d9c201e46ab2bdb7f304f7ee69f1547 100644 (file)
@@ -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".
index b5d3237ded56647197812f7b446b9c61284a3e8b..3810279554f71a1a195d37cc5ce1428de75892ee 100644 (file)
@@ -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"
index c8a9726b6b2bad2034459f6e1462bce824863b88..e346b1af744240eb22bc71757f30525627f4aadb 100644 (file)
@@ -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"
index 976a97e652f77f68ab397657e84acf55b237e54f..cf43dca0c31c62d5bd08ff590ddedb27d2f44420 100644 (file)
@@ -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;
 
index c4def6da4243d4fcd18c173b144ee389e3d4e2f6..e13137ebead82f0b293ec0cc5ff18763effca2b6 100644 (file)
@@ -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;
index de0a0cd79e9fa1bdfc191fa6d2a30549ba4595de..fdcefadb1bae5e82219b5d85b54d21f6cb5d81f2 100644 (file)
@@ -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.*;
index 73b8979d22f3110443ed813e8be31c0711274496..4f42809dfb7c91ddcb238db8e5426140cdb6668e 100644 (file)
@@ -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 (file)
index 937da1b..0000000
+++ /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);
-//  }
-//}
-
index 5bf25f7e65fdb1f701a44df00c00988b85b4b0ee..9173ef7227c86f1f08e008a1a33c2215f2a71bd8 100644 (file)
@@ -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.*;
 
index 53d134417586b0323e1a9c9317124539b54a16fc..656d3bb4231a487561e7a25b94fe80cc8f55ec46 100644 (file)
@@ -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.*;
 
index 604efb86d352902ef5d7619b9a27fb96b22487df..ecd6ef521177bd995cfae97b4b443b10d54b838c 100644 (file)
@@ -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;
 
index 9534400e47a5d985625ac52d1404b6da6ac9a762..c818dee6eacc680fb21b4943590e89e9fd514cf3 100644 (file)
@@ -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;
index 030571ce8d58520860182b00787b1f7d09e2da14..3b7c7a4b48d4424c30530c3ab3cd9d0c5cf0810d 100644 (file)
@@ -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
index 5cf93a9d419e24fae24804c7f8e8f19947cf6111..ec10ba85a5c3a527ceee20dc390043f64a8bdba5 100644 (file)
@@ -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;
index e677643854990c4290be18e60afb5f7dcaa0db1e..99dbf58c3e228e172dfed07fecdede62a81dc819 100644 (file)
@@ -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 (file)
index 0000000..33a127a
--- /dev/null
@@ -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;
+
+/**
+ * <p>
+ * Plugins should extend this class to provide logic to determine which users are interested in receiving notifications,
+ * along with which delivery channels they selected.
+ * </p>
+ * For example:
+ * <ul>
+ * <li>notify me by email when someone comments an issue reported by me</li>
+ * <li>notify me by twitter when someone comments an issue assigned to me</li>
+ * <li>notify me by Jabber when someone mentions me in an issue comment</li>
+ * <li>send me by SMS when there are system notifications (like password reset, account creation, ...)</li>
+ * </ul> 
+ * 
+ * @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. 
+   * <p/>
+   * 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.
+   * <p/>
+   * The related label in l10n bundles is 'notification.dispatcher.<key>', for example 'notification.dispatcher.NewFalsePositive'.
+   */
+  public String getKey() {
+    return getClass().getSimpleName();
+  }
+
+  /**
+   * @since 5.1
+   */
+  public String getType() {
+    return notificationType;
+  }
+
+  /**
+   * <p>
+   * Performs the dispatch.
+   * </p>
+   */
+  public final void performDispatch(Notification notification, Context context) {
+    if (StringUtils.equals(notification.getType(), notificationType) || StringUtils.equals("", notificationType)) {
+      dispatch(notification, context);
+    }
+  }
+
+  /**
+   * <p>
+   * Implements the logic that defines which users will receive the notification.
+   * </p>
+   * 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 (file)
index 0000000..2eb04a5
--- /dev/null
@@ -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;
+
+/**
+ * <p>
+ * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order
+ * to tell more about them.
+ * <p/>
+ * 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<String, String> properties;
+
+  private NotificationDispatcherMetadata(String dispatcherKey) {
+    this.dispatcherKey = dispatcherKey;
+    this.properties = Maps.newHashMap();
+  }
+
+  /**
+   * Creates a new metadata instance for the given dispatcher.
+   * <p/>
+   * 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 (file)
index 0000000..f9b5e0a
--- /dev/null
@@ -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;
+
+/**
+ * <p>
+ * The notification manager receives notifications and is in charge of storing them so that they are processed by the notification service.
+ * </p>
+ * <p>
+ * 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.
+ * </p>
+ *
+ * @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<Notification> notifications);
+
+  /**
+   * <p>
+   * Returns the list of users who subscribed to the given dispatcher, along with the notification channels (email, twitter, ...) that they choose
+   * for this dispatcher.
+   * </p>
+   * <p>
+   * The resource ID can be null in case of notifications that have nothing to do with a specific project (like system notifications).
+   * </p>
+   *
+   * @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<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, @Nullable Integer resourceId);
+
+  Multimap<String, NotificationChannel> findNotificationSubscribers(NotificationDispatcher dispatcher, @Nullable String componentKey);
+}
index 9e1dae9de30c7f1502b3c3993f165b580273cdb5..c5e60e1afa5bd3fdbf332a980bf3cf54fad6727d 100644 (file)
@@ -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 (file)
index 0000000..dcd80b4
--- /dev/null
@@ -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 (file)
index 0000000..c19e545
--- /dev/null
@@ -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 (file)
index 0000000..8929612
--- /dev/null
@@ -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);
+    }
+  }
+
+}
index 0666e7260f12b7eeab135b06e2d05cd5429f32a4..6f947a29299f9be216e9c16242a74a4f72ccdd46 100644 (file)
@@ -28,11 +28,8 @@ import java.io.Serializable;
 import java.util.Map;
 
 /**
- * <p>
  * 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}).
- * </p>
+ * knowledge of the possible ways to be delivered (see {@link NotificationChannel}).
  * <p>
  * 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 (file)
index 1bffbee..0000000
+++ /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;
-
-/**
- * <p>
- * Plugins should extend this class to provide logic to determine which users are interested in receiving notifications,
- * along with which delivery channels they selected.
- * </p>
- * For example:
- * <ul>
- * <li>notify me by email when someone comments an issue reported by me</li>
- * <li>notify me by twitter when someone comments an issue assigned to me</li>
- * <li>notify me by Jabber when someone mentions me in an issue comment</li>
- * <li>send me by SMS when there are system notifications (like password reset, account creation, ...)</li>
- * </ul> 
- * 
- * @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. 
-   * <p/>
-   * 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.
-   * <p/>
-   * The related label in l10n bundles is 'notification.dispatcher.<key>', for example 'notification.dispatcher.NewFalsePositive'.
-   */
-  public String getKey() {
-    return getClass().getSimpleName();
-  }
-
-  /**
-   * @since 5.1
-   */
-  public String getType() {
-    return notificationType;
-  }
-
-  /**
-   * <p>
-   * Performs the dispatch.
-   * </p>
-   */
-  public final void performDispatch(Notification notification, Context context) {
-    if (StringUtils.equals(notification.getType(), notificationType) || StringUtils.equals("", notificationType)) {
-      dispatch(notification, context);
-    }
-  }
-
-  /**
-   * <p>
-   * Implements the logic that defines which users will receive the notification.
-   * </p>
-   * 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 (file)
index 37f7351..0000000
+++ /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;
-
-/**
- * <p>
- * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order
- * to tell more about them.
- * <p/>
- * 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<String, String> properties;
-
-  private NotificationDispatcherMetadata(String dispatcherKey) {
-    this.dispatcherKey = dispatcherKey;
-    this.properties = Maps.newHashMap();
-  }
-
-  /**
-   * Creates a new metadata instance for the given dispatcher.
-   * <p/>
-   * 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 (file)
index ce67d17..0000000
+++ /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;
-
-/**
- * <p>
- * The notification manager receives notifications and is in charge of storing them so that they are processed by the notification service.
- * </p>
- * <p>
- * 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.
- * </p>
- *
- * @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<Notification> notifications);
-
-  /**
-   * <p>
-   * Returns the list of users who subscribed to the given dispatcher, along with the notification channels (email, twitter, ...) that they choose
-   * for this dispatcher.
-   * </p>
-   * <p>
-   * The resource ID can be null in case of notifications that have nothing to do with a specific project (like system notifications).
-   * </p>
-   *
-   * @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<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, @Nullable Integer resourceId);
-
-  Multimap<String, NotificationChannel> 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 (file)
index 0d2efb2..0000000
+++ /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 (file)
index 7acb305..0000000
+++ /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 (file)
index 1925fed..0000000
+++ /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);
-    }
-  }
-
-}