diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-01 23:15:37 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-05 09:54:05 +0200 |
commit | 7329c0cb612dbcb22f0122803639668d634ea056 (patch) | |
tree | c89eebc95f0b152cd837b054f29d0eb4210defd2 | |
parent | 0da7194795513bb7c5dff08ff8197aae17182719 (diff) | |
download | sonarqube-7329c0cb612dbcb22f0122803639668d634ea056.tar.gz sonarqube-7329c0cb612dbcb22f0122803639668d634ea056.zip |
SONAR-6370 merge sonar-email-notifications-plugin into server module
13 files changed, 64 insertions, 212 deletions
diff --git a/plugins/sonar-email-notifications-plugin/pom.xml b/plugins/sonar-email-notifications-plugin/pom.xml deleted file mode 100644 index 830da5e0747..00000000000 --- a/plugins/sonar-email-notifications-plugin/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar</artifactId> - <version>5.2-SNAPSHOT</version> - <relativePath>../..</relativePath> - </parent> - - <groupId>org.codehaus.sonar.plugins</groupId> - <artifactId>sonar-email-notifications-plugin</artifactId> - <packaging>sonar-plugin</packaging> - - <name>SonarQube :: Plugins :: Email Notifications</name> - <description>Email Notifications</description> - - <dependencies> - <dependency> - <groupId>com.google.code.findbugs</groupId> - <artifactId>jsr305</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-plugin-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-email</artifactId> - <version>1.3.2</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <scope>provided</scope> - </dependency> - - <!-- unit tests --> - <dependency> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-testing-harness</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.subethamail</groupId> - <artifactId>subethasmtp</artifactId> - <version>3.1.7</version> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-packaging-maven-plugin</artifactId> - <configuration> - <pluginName>Email notifications</pluginName> - <pluginClass>org.sonar.plugins.emailnotifications.EmailNotificationsPlugin</pluginClass> - <useChildFirstClassLoader>true</useChildFirstClassLoader> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-enforcer-plugin</artifactId> - <executions> - <execution> - <id>enforce-plugin-size</id> - <goals> - <goal>enforce</goal> - </goals> - <phase>verify</phase> - <configuration> - <rules> - <requireFilesSize> - <maxsize>620000</maxsize> - <minsize>590000</minsize> - <files> - <file>${project.build.directory}/${project.build.finalName}.jar</file> - </files> - </requireFilesSize> - </rules> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> 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 deleted file mode 100644 index fefc33e2916..00000000000 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java +++ /dev/null @@ -1,35 +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.plugins.emailnotifications; - -import java.util.Arrays; -import java.util.List; -import org.sonar.api.SonarPlugin; - -public class EmailNotificationsPlugin extends SonarPlugin { - @Override - public List getExtensions() { - return Arrays.asList( - EmailNotificationChannel.class, - - // Email templates - AlertsEmailTemplate.class); - } -} 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 deleted file mode 100644 index 1043f27773e..00000000000 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java +++ /dev/null @@ -1,31 +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.plugins.emailnotifications; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EmailNotificationsPluginTest { - @Test - public void should_get_extensions() { - assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(2); - } -} @@ -27,7 +27,6 @@ <module>sonar-plugin-api</module> <module>server</module> <module>sonar-testing-harness</module> - <module>plugins/sonar-email-notifications-plugin</module> <module>plugins/sonar-xoo-plugin</module> <module>plugins/sonar-batch-maven-plugin</module> </modules> @@ -756,6 +755,11 @@ <version>1.8</version> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-email</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> @@ -1105,6 +1109,13 @@ <artifactId>lz4</artifactId> <version>1.3.0</version> </dependency> + <dependency> + <groupId>org.subethamail</groupId> + <artifactId>subethasmtp</artifactId> + <version>3.1.7</version> + <scope>test</scope> + </dependency> + <!-- tomcat --> diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml index d948b80cefb..56b43e11efa 100644 --- a/server/sonar-server/pom.xml +++ b/server/sonar-server/pom.xml @@ -134,6 +134,10 @@ <artifactId>commons-dbutils</artifactId> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-email</artifactId> + </dependency> + <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> @@ -222,6 +226,12 @@ <artifactId>reflections</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.subethamail</groupId> + <artifactId>subethasmtp</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/AlertsEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/AlertsEmailTemplate.java index 2ea0faf34f2..0ea9c3c5544 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/AlertsEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/AlertsEmailTemplate.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.server.notifications.email; import org.apache.commons.lang.StringUtils; import org.sonar.api.config.EmailSettings; @@ -60,9 +60,9 @@ public class AlertsEmailTemplate extends EmailTemplate { // And finally return the email that will be sent return new EmailMessage() - .setMessageId("alerts/" + projectId) - .setSubject(subject) - .setMessage(messageBody); + .setMessageId("alerts/" + projectId) + .setSubject(subject) + .setMessage(messageBody); } private static String generateSubject(String projectName, String alertLevel, boolean isNewAlert) { diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java index a11154370cb..20303871339 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java @@ -17,8 +17,10 @@ * 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; +package org.sonar.server.notifications.email; +import java.net.MalformedURLException; +import java.net.URL; import org.apache.commons.lang.StringUtils; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; @@ -33,9 +35,6 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.plugins.emailnotifications.api.EmailTemplate; -import java.net.MalformedURLException; -import java.net.URL; - /** * References: * <ul> diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/package-info.java index db67dd7df17..a81d297b0c7 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/package-info.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.plugins.emailnotifications; +package org.sonar.server.notifications.email; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index c8b5f739899..eb78b0ffb89 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -172,6 +172,8 @@ import org.sonar.server.metric.CoreCustomMetrics; import org.sonar.server.metric.ws.MetricsWsModule; import org.sonar.server.notifications.NotificationCenter; import org.sonar.server.notifications.NotificationService; +import org.sonar.server.notifications.email.AlertsEmailTemplate; +import org.sonar.server.notifications.email.EmailNotificationChannel; import org.sonar.server.permission.InternalPermissionService; import org.sonar.server.permission.InternalPermissionTemplateService; import org.sonar.server.permission.PermissionFinder; @@ -619,6 +621,8 @@ public class PlatformLevel4 extends PlatformLevel { DoNotFixNotificationDispatcher.class, DoNotFixNotificationDispatcher.newMetadata(), NewIssuesNotificationFactory.class, + EmailNotificationChannel.class, + AlertsEmailTemplate.class, // issue filters IssueFilterService.class, diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/AlertsEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/AlertsEmailTemplateTest.java index 5b42a2a5953..3834df8b9e8 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/AlertsEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/AlertsEmailTemplateTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.server.notifications.email; import org.junit.Before; import org.junit.Test; diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java index 02c43eb00d2..d3e2144fd08 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java @@ -17,9 +17,14 @@ * 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; +package org.sonar.server.notifications.email; +import java.io.IOException; +import java.net.ServerSocket; +import java.util.List; +import javax.mail.internet.MimeMessage; import org.apache.commons.mail.EmailException; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -30,12 +35,6 @@ import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.subethamail.wiser.Wiser; import org.subethamail.wiser.WiserMessage; -import javax.mail.internet.MimeMessage; - -import java.io.IOException; -import java.net.ServerSocket; -import java.util.List; - import static junit.framework.Assert.fail; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -87,10 +86,10 @@ public class EmailNotificationChannelTest { assertThat(messages).hasSize(1); MimeMessage email = messages.get(0).getMimeMessage(); - assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube <server@nowhere>"); - assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); - assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube"); + Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + Assertions.assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube <server@nowhere>"); + Assertions.assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); + Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube"); assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube."); } @@ -114,7 +113,7 @@ public class EmailNotificationChannelTest { .setSubject("Foo") .setMessage("Bar"); channel.deliver(emailMessage); - assertThat(server.getMessages()).isEmpty(); + Assertions.assertThat(server.getMessages()).isEmpty(); } @Test @@ -133,17 +132,17 @@ public class EmailNotificationChannelTest { MimeMessage email = messages.get(0).getMimeMessage(); - assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - assertThat(email.getHeader("In-Reply-To", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); - assertThat(email.getHeader("References", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); + Assertions.assertThat(email.getHeader("In-Reply-To", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); + Assertions.assertThat(email.getHeader("References", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); - assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); - assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); + Assertions.assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); + Assertions.assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); - assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" <server@nowhere>"); - assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); - assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3"); + Assertions.assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" <server@nowhere>"); + Assertions.assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); + Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3"); assertThat((String) email.getContent()).startsWith("I'll take care of this violation."); } @@ -161,17 +160,17 @@ public class EmailNotificationChannelTest { MimeMessage email = messages.get(0).getMimeMessage(); - assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - assertThat(email.getHeader("In-Reply-To", null)).isNull(); - assertThat(email.getHeader("References", null)).isNull(); + Assertions.assertThat(email.getHeader("In-Reply-To", null)).isNull(); + Assertions.assertThat(email.getHeader("References", null)).isNull(); - assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); - assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); + Assertions.assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); + Assertions.assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); - assertThat(email.getHeader("From", null)).isEqualTo("SonarQube <server@nowhere>"); - assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); - assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo"); + Assertions.assertThat(email.getHeader("From", null)).isEqualTo("SonarQube <server@nowhere>"); + Assertions.assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); + Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo"); assertThat((String) email.getContent()).startsWith("Bar"); } @@ -199,7 +198,7 @@ public class EmailNotificationChannelTest { fail("An SSL exception was expected a a proof that STARTTLS is enabled"); } catch (EmailException e) { // We don't have a SSL certificate so we are expecting a SSL error - assertThat(e.getCause().getMessage()).isEqualTo("Could not convert socket to TLS"); + Assertions.assertThat(e.getCause().getMessage()).isEqualTo("Could not convert socket to TLS"); } } diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 78acbb41190..bde9dd65e19 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -89,14 +89,7 @@ <scope>provided</scope> </dependency> - <!-- core plugins --> - <dependency> - <groupId>org.codehaus.sonar.plugins</groupId> - <artifactId>sonar-email-notifications-plugin</artifactId> - <version>${project.version}</version> - <type>sonar-plugin</type> - <scope>provided</scope> - </dependency> + <!-- default plugins --> <dependency> <groupId>org.codehaus.sonar-plugins.java</groupId> <artifactId>sonar-java-plugin</artifactId> diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index 1412a8efdd0..c48f2b7263e 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -212,7 +212,6 @@ <createDependencyReducedPom>true</createDependencyReducedPom> <artifactSet> <excludes> - <exclude>org.codehaus.sonar.plugins:sonar-email-notifications-plugin</exclude> <exclude>org.codehaus.woodstox:woodstox-core-lgpl</exclude> <exclude>org.codehaus.woodstox:stax2-api</exclude> <exclude>org.codehaus.staxmate:staxmate</exclude> |