From d963ab5619aa75d28b7cc981f0615c67f73d1fd5 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 5 Jul 2012 12:21:12 +0200 Subject: [PATCH] SONAR-3593 move EmailSettings to org.sonar.api.conf --- .../emailnotifications/EmailNotificationChannel.java | 8 ++++---- .../newviolations/NewViolationsEmailTemplate.java | 2 +- .../emailnotifications/reviews/ReviewEmailTemplate.java | 2 +- .../emailnotifications/EmailNotificationChannelTest.java | 4 ++-- .../newviolations/NewViolationsEmailTemplateTest.java | 2 +- .../reviews/ReviewEmailTemplateTest.java | 2 +- .../java/org/sonar/batch/bootstrap/BootstrapModule.java | 2 +- .../org/sonar/api/{platform => config}/EmailSettings.java | 6 +++--- .../sonar/api/{platform => config}/EmailSettingsTest.java | 5 +++-- .../src/main/java/org/sonar/server/platform/Platform.java | 2 +- .../app/controllers/email_configuration_controller.rb | 2 +- 11 files changed, 19 insertions(+), 18 deletions(-) rename sonar-plugin-api/src/main/java/org/sonar/api/{platform => config}/EmailSettings.java (96%) rename sonar-plugin-api/src/test/java/org/sonar/api/{platform => config}/EmailSettingsTest.java (92%) diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java index 382e9ce4f95..febacbd68bc 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java +++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java @@ -24,10 +24,10 @@ import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.config.EmailSettings; import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.platform.EmailSettings; import org.sonar.api.security.UserFinder; import org.sonar.api.utils.SonarException; import org.sonar.plugins.emailnotifications.api.EmailMessage; @@ -175,13 +175,13 @@ public class EmailNotificationChannel extends NotificationChannel { email.setHostName(configuration.getSmtpHost()); if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "SSL")) { email.setSSL(true); - email.setSslSmtpPort(configuration.getSmtpPort()); + email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort())); // this port is not used except in EmailException message, that's why it's set with the same value than SSL port. // It prevents from getting bad message. - email.setSmtpPort(Integer.parseInt(configuration.getSmtpPort())); + email.setSmtpPort(configuration.getSmtpPort()); } else if (StringUtils.isBlank(configuration.getSecureConnection())) { - email.setSmtpPort(Integer.parseInt(configuration.getSmtpPort())); + email.setSmtpPort(configuration.getSmtpPort()); } else { throw new SonarException("Unknown type of SMTP secure connection: " + configuration.getSecureConnection()); } diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java index 8db4314562c..2294b368e34 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java +++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java @@ -20,7 +20,7 @@ package org.sonar.plugins.emailnotifications.newviolations; import org.sonar.api.notifications.Notification; -import org.sonar.api.platform.EmailSettings; +import org.sonar.api.config.EmailSettings; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.plugins.emailnotifications.api.EmailTemplate; diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java index 93a41c9b7c8..57da295f6eb 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java +++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java @@ -20,9 +20,9 @@ package org.sonar.plugins.emailnotifications.reviews; import org.apache.commons.lang.StringUtils; +import org.sonar.api.config.EmailSettings; import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; -import org.sonar.api.platform.EmailSettings; import org.sonar.api.security.UserFinder; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.plugins.emailnotifications.api.EmailTemplate; diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java index 3940b7d7809..3cba1e0fc0a 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java +++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java @@ -23,7 +23,7 @@ import org.apache.commons.mail.EmailException; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.sonar.api.platform.EmailSettings; +import org.sonar.api.config.EmailSettings; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.subethamail.wiser.Wiser; import org.subethamail.wiser.WiserMessage; @@ -187,7 +187,7 @@ public class EmailNotificationChannelTest { private void configure() { when(configuration.getSmtpHost()).thenReturn("localhost"); - when(configuration.getSmtpPort()).thenReturn(Integer.toString(port)); + when(configuration.getSmtpPort()).thenReturn(port); when(configuration.getFrom()).thenReturn("server@nowhere"); when(configuration.getPrefix()).thenReturn("[SONAR]"); when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org"); diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java index 43b0368e636..3bd32290422 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java +++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java @@ -21,8 +21,8 @@ package org.sonar.plugins.emailnotifications.newviolations; import org.junit.Before; import org.junit.Test; +import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; -import org.sonar.api.platform.EmailSettings; import org.sonar.plugins.emailnotifications.api.EmailMessage; import static org.hamcrest.Matchers.is; diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java index d9605a36935..3e52167e9d1 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java +++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java @@ -21,9 +21,9 @@ package org.sonar.plugins.emailnotifications.reviews; import org.junit.Before; import org.junit.Test; +import org.sonar.api.config.EmailSettings; import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; -import org.sonar.api.platform.EmailSettings; import org.sonar.api.security.UserFinder; import org.sonar.plugins.emailnotifications.api.EmailMessage; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index 60c05bf6d59..61a01cb36cf 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -21,7 +21,7 @@ package org.sonar.batch.bootstrap; import org.apache.commons.configuration.PropertiesConfiguration; import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.platform.EmailSettings; +import org.sonar.api.config.EmailSettings; import org.sonar.api.utils.HttpDownloader; import org.sonar.batch.FakeMavenPluginExecutor; import org.sonar.batch.MavenPluginExecutor; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java similarity index 96% rename from sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java rename to sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java index 23eaac6816b..d2c81647511 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java @@ -17,7 +17,7 @@ * 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.platform; +package org.sonar.api.config; import com.google.common.base.Objects; import org.sonar.api.BatchComponent; @@ -56,8 +56,8 @@ public class EmailSettings implements BatchComponent, ServerComponent { return get(SMTP_HOST, SMTP_HOST_DEFAULT); } - public String getSmtpPort() { - return get(SMTP_PORT, SMTP_PORT_DEFAULT); + public int getSmtpPort() { + return Integer.parseInt(get(SMTP_PORT, SMTP_PORT_DEFAULT)); } public String getSecureConnection() { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java similarity index 92% rename from sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java rename to sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java index f548b2fdb1f..c9609816394 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java @@ -17,11 +17,12 @@ * 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.platform; +package org.sonar.api.config; import org.junit.Before; import org.junit.Test; import org.sonar.api.CoreProperties; +import org.sonar.api.config.EmailSettings; import org.sonar.api.config.Settings; import static org.fest.assertions.Assertions.assertThat; @@ -37,7 +38,7 @@ public class EmailSettingsTest { @Test public void should_return_default_values() { assertThat(emailSettings.getSmtpHost()).isEqualTo(""); - assertThat(emailSettings.getSmtpPort()).isEqualTo("25"); + assertThat(emailSettings.getSmtpPort()).isEqualTo(25); assertThat(emailSettings.getSmtpUsername()).isEmpty(); assertThat(emailSettings.getSmtpPassword()).isEmpty(); assertThat(emailSettings.getSecureConnection()).isEmpty(); diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index e0d9f48858a..e318db2b625 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -19,7 +19,7 @@ */ package org.sonar.server.platform; -import org.sonar.api.platform.EmailSettings; +import org.sonar.api.config.EmailSettings; import org.apache.commons.configuration.BaseConfiguration; import org.slf4j.LoggerFactory; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb index e5c77a7e50d..8e5fd6d5e1b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb @@ -65,7 +65,7 @@ class EmailConfigurationController < ApplicationController private def configuration - java_facade.getComponentByClassname('emailnotifications', 'org.sonar.api.platform.EmailSettings').class + java_facade.getComponentByClassname('emailnotifications', 'org.sonar.api.config.EmailSettings').class end end -- 2.39.5