aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-30 15:08:34 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-30 15:23:22 +0100
commitc91f6e066a0d4917b2cbace325db9ac6a12c2913 (patch)
treeca2fc6dc23954c5a561ddbe9115dc75aec10a7bf /sonar-plugin-api
parent8f9dacd45c67012dae0dc06df4f2baa483164bc6 (diff)
downloadsonarqube-c91f6e066a0d4917b2cbace325db9ac6a12c2913.tar.gz
sonarqube-c91f6e066a0d4917b2cbace325db9ac6a12c2913.zip
SONAR-3959 Add NotificationDispatcherMetadata class
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java81
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java46
2 files changed, 127 insertions, 0 deletions
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
new file mode 100644
index 00000000000..a5dafc6e4d2
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/NotificationDispatcherMetadata.java
@@ -0,0 +1,81 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.notifications;
+
+import com.google.common.collect.Maps;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.SonarPlugin;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order
+ * to tell more about them.
+ * <br/>
+ * Instances of those classes must be passed to Pico container (generally in the
+ * {@link SonarPlugin#getExtensions()} method implementation).
+ * </p>
+ *
+ * @since 3.5
+ */
+public final class NotificationDispatcherMetadata implements ServerExtension {
+
+ 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.
+ */
+ 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;
+ }
+
+}
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
new file mode 100644
index 00000000000..b585a0f6cef
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherMetadataTest.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.notifications;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.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();
+ }
+}