aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-26 23:10:45 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-26 23:19:06 +0200
commita126ebcb5bbb83a92345174a86d7e194e445981e (patch)
tree00a5fd602ad3e7ed7da8fdc5ad9c92ffdcc1a658 /plugins/sonar-email-notifications-plugin/src
parenta686502af62bff2ae1fb43a479a444c96a0774e1 (diff)
downloadsonarqube-a126ebcb5bbb83a92345174a86d7e194e445981e.tar.gz
sonarqube-a126ebcb5bbb83a92345174a86d7e194e445981e.zip
SONAR-4283 implement the notification on new issues raised during project scan
Diffstat (limited to 'plugins/sonar-email-notifications-plugin/src')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java17
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java70
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java2
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java84
4 files changed, 7 insertions, 166 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
index 8c67ffb385f..ebf518fc7b1 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
@@ -19,25 +19,20 @@
*/
package org.sonar.plugins.emailnotifications;
-import org.sonar.plugins.emailnotifications.templates.reviews.ReviewEmailTemplate;
-
-import org.sonar.plugins.emailnotifications.templates.violations.NewViolationsEmailTemplate;
-
-import org.sonar.plugins.emailnotifications.templates.alerts.AlertsEmailTemplate;
-
import com.google.common.collect.ImmutableList;
import org.sonar.api.SonarPlugin;
+import org.sonar.plugins.emailnotifications.templates.alerts.AlertsEmailTemplate;
+import org.sonar.plugins.emailnotifications.templates.reviews.ReviewEmailTemplate;
import java.util.List;
public class EmailNotificationsPlugin extends SonarPlugin {
public List<?> getExtensions() {
return ImmutableList.of(
- EmailNotificationChannel.class,
+ EmailNotificationChannel.class,
- // Email templates
- NewViolationsEmailTemplate.class,
- ReviewEmailTemplate.class,
- AlertsEmailTemplate.class);
+ // Email templates
+ ReviewEmailTemplate.class,
+ AlertsEmailTemplate.class);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java
deleted file mode 100644
index e83e8b4968f..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.plugins.emailnotifications.templates.violations;
-
-import org.sonar.api.notifications.Notification;
-import org.sonar.api.config.EmailSettings;
-import org.sonar.plugins.emailnotifications.api.EmailMessage;
-import org.sonar.plugins.emailnotifications.api.EmailTemplate;
-
-/**
- * Creates email message for notification "new-violations".
- *
- * @since 2.10
- */
-public class NewViolationsEmailTemplate extends EmailTemplate {
-
- private EmailSettings configuration;
-
- public NewViolationsEmailTemplate(EmailSettings configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public EmailMessage format(Notification notification) {
- if (!"new-violations".equals(notification.getType())) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
-
- String projectName = notification.getFieldValue("projectName");
- String violationsCount = notification.getFieldValue("count");
- String fromDate = notification.getFieldValue("fromDate");
-
- sb.append("Project: ").append(projectName).append('\n');
- sb.append(violationsCount).append(" new violations introduced since ").append(fromDate).append('\n');
- appendFooter(sb, notification);
-
- EmailMessage message = new EmailMessage()
- .setMessageId("new-violations/" + notification.getFieldValue("projectId"))
- .setSubject("New violations for project " + projectName)
- .setMessage(sb.toString());
-
- return message;
- }
-
- private void appendFooter(StringBuilder sb, Notification notification) {
- String projectKey = notification.getFieldValue("projectKey");
- sb.append("\n")
- .append("See it in Sonar: ").append(configuration.getServerBaseURL()).append("/drilldown/measures/").append(projectKey)
- .append("?metric=new_violations&period=1\n");
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
index 6d30647d4f1..6b8750c783c 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
@@ -26,6 +26,6 @@ import static org.fest.assertions.Assertions.assertThat;
public class EmailNotificationsPluginTest {
@Test
public void should_get_extensions() {
- assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(4);
+ assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(3);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java
deleted file mode 100644
index 97f6c72feb2..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.plugins.emailnotifications.templates.violations;
-
-import org.sonar.plugins.emailnotifications.templates.violations.NewViolationsEmailTemplate;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.config.EmailSettings;
-import org.sonar.api.notifications.Notification;
-import org.sonar.plugins.emailnotifications.api.EmailMessage;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class NewViolationsEmailTemplateTest {
-
- private NewViolationsEmailTemplate template;
-
- @Before
- public void setUp() {
- EmailSettings configuration = mock(EmailSettings.class);
- when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
- template = new NewViolationsEmailTemplate(configuration);
- }
-
- @Test
- public void shouldNotFormatIfNotCorrectNotification() {
- Notification notification = new Notification("other-notif");
- EmailMessage message = template.format(notification);
- assertThat(message, nullValue());
- }
-
- /**
- * <pre>
- * Subject: New violations for project Foo
- * From: Sonar
- *
- * Project: Foo
- * 32 new violations introduced since 2012-01-02
- *
- * See it in Sonar: http://nemo.sonarsource.org/drilldown/measures/org.sonar.foo:foo?metric=new_violations&period=1
- * </pre>
- */
- @Test
- public void shouldFormatCommentAdded() {
- Notification notification = new Notification("new-violations")
- .setFieldValue("count", "32")
- .setFieldValue("projectName", "Foo")
- .setFieldValue("projectKey", "org.sonar.foo:foo")
- .setFieldValue("projectId", "45")
- .setFieldValue("fromDate", "2012-01-02");
-
- EmailMessage message = template.format(notification);
- assertThat(message.getMessageId(), is("new-violations/45"));
- assertThat(message.getSubject(), is("New violations for project Foo"));
- assertThat(message.getMessage(), is("" +
- "Project: Foo\n" +
- "32 new violations introduced since 2012-01-02\n" +
- "\n" +
- "See it in Sonar: http://nemo.sonarsource.org/drilldown/measures/org.sonar.foo:foo?metric=new_violations&period=1\n"));
- }
-
-}