From: Simon Brandhof Date: Thu, 5 Jul 2012 10:21:12 +0000 (+0200) Subject: SONAR-3593 move EmailSettings to org.sonar.api.conf X-Git-Tag: 3.2~236 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d963ab5619aa75d28b7cc981f0615c67f73d1fd5;p=sonarqube.git SONAR-3593 move EmailSettings to org.sonar.api.conf --- 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/config/EmailSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java new file mode 100644 index 00000000000..d2c81647511 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java @@ -0,0 +1,90 @@ +/* + * 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.config; + +import com.google.common.base.Objects; +import org.sonar.api.BatchComponent; +import org.sonar.api.CoreProperties; +import org.sonar.api.ServerComponent; +import org.sonar.api.config.Settings; + +/** + * Ruby uses constants from this class. + * + * @since 3.2 + */ +public class EmailSettings implements BatchComponent, ServerComponent { + public static final String SMTP_HOST = "email.smtp_host.secured"; + public static final String SMTP_HOST_DEFAULT = ""; + public static final String SMTP_PORT = "email.smtp_port.secured"; + public static final String SMTP_PORT_DEFAULT = "25"; + public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured"; + public static final String SMTP_SECURE_CONNECTION_DEFAULT = ""; + public static final String SMTP_USERNAME = "email.smtp_username.secured"; + public static final String SMTP_USERNAME_DEFAULT = ""; + public static final String SMTP_PASSWORD = "email.smtp_password.secured"; + public static final String SMTP_PASSWORD_DEFAULT = ""; + public static final String FROM = "email.from"; + public static final String FROM_DEFAULT = "noreply@nowhere"; + public static final String PREFIX = "email.prefix"; + public static final String PREFIX_DEFAULT = "[SONAR]"; + + private final Settings settings; + + public EmailSettings(Settings settings) { + this.settings = settings; + } + + public String getSmtpHost() { + return get(SMTP_HOST, SMTP_HOST_DEFAULT); + } + + public int getSmtpPort() { + return Integer.parseInt(get(SMTP_PORT, SMTP_PORT_DEFAULT)); + } + + public String getSecureConnection() { + return get(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT); + } + + public String getSmtpUsername() { + return get(SMTP_USERNAME, SMTP_USERNAME_DEFAULT); + } + + public String getSmtpPassword() { + return get(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT); + } + + public String getFrom() { + return get(FROM, FROM_DEFAULT); + } + + public String getPrefix() { + return get(PREFIX, PREFIX_DEFAULT); + } + + public String getServerBaseURL() { + return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); + } + + private String get(String key, String defaultValue) { + return Objects.firstNonNull(settings.getString(key), defaultValue); + } +} 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/platform/EmailSettings.java deleted file mode 100644 index 23eaac6816b..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.platform; - -import com.google.common.base.Objects; -import org.sonar.api.BatchComponent; -import org.sonar.api.CoreProperties; -import org.sonar.api.ServerComponent; -import org.sonar.api.config.Settings; - -/** - * Ruby uses constants from this class. - * - * @since 3.2 - */ -public class EmailSettings implements BatchComponent, ServerComponent { - public static final String SMTP_HOST = "email.smtp_host.secured"; - public static final String SMTP_HOST_DEFAULT = ""; - public static final String SMTP_PORT = "email.smtp_port.secured"; - public static final String SMTP_PORT_DEFAULT = "25"; - public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured"; - public static final String SMTP_SECURE_CONNECTION_DEFAULT = ""; - public static final String SMTP_USERNAME = "email.smtp_username.secured"; - public static final String SMTP_USERNAME_DEFAULT = ""; - public static final String SMTP_PASSWORD = "email.smtp_password.secured"; - public static final String SMTP_PASSWORD_DEFAULT = ""; - public static final String FROM = "email.from"; - public static final String FROM_DEFAULT = "noreply@nowhere"; - public static final String PREFIX = "email.prefix"; - public static final String PREFIX_DEFAULT = "[SONAR]"; - - private final Settings settings; - - public EmailSettings(Settings settings) { - this.settings = settings; - } - - public String getSmtpHost() { - return get(SMTP_HOST, SMTP_HOST_DEFAULT); - } - - public String getSmtpPort() { - return get(SMTP_PORT, SMTP_PORT_DEFAULT); - } - - public String getSecureConnection() { - return get(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT); - } - - public String getSmtpUsername() { - return get(SMTP_USERNAME, SMTP_USERNAME_DEFAULT); - } - - public String getSmtpPassword() { - return get(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT); - } - - public String getFrom() { - return get(FROM, FROM_DEFAULT); - } - - public String getPrefix() { - return get(PREFIX, PREFIX_DEFAULT); - } - - public String getServerBaseURL() { - return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); - } - - private String get(String key, String defaultValue) { - return Objects.firstNonNull(settings.getString(key), defaultValue); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java new file mode 100644 index 00000000000..c9609816394 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java @@ -0,0 +1,49 @@ +/* + * 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.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; + +public class EmailSettingsTest { + EmailSettings emailSettings; + + @Before + public void setUp() { + emailSettings = new EmailSettings(new Settings()); + } + + @Test + public void should_return_default_values() { + assertThat(emailSettings.getSmtpHost()).isEqualTo(""); + assertThat(emailSettings.getSmtpPort()).isEqualTo(25); + assertThat(emailSettings.getSmtpUsername()).isEmpty(); + assertThat(emailSettings.getSmtpPassword()).isEmpty(); + assertThat(emailSettings.getSecureConnection()).isEmpty(); + assertThat(emailSettings.getFrom()).isEqualTo("noreply@nowhere"); + assertThat(emailSettings.getPrefix()).isEqualTo("[SONAR]"); + assertThat(emailSettings.getServerBaseURL()).isEqualTo(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); + } +} 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/platform/EmailSettingsTest.java deleted file mode 100644 index f548b2fdb1f..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.platform; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; - -import static org.fest.assertions.Assertions.assertThat; - -public class EmailSettingsTest { - EmailSettings emailSettings; - - @Before - public void setUp() { - emailSettings = new EmailSettings(new Settings()); - } - - @Test - public void should_return_default_values() { - assertThat(emailSettings.getSmtpHost()).isEqualTo(""); - assertThat(emailSettings.getSmtpPort()).isEqualTo("25"); - assertThat(emailSettings.getSmtpUsername()).isEmpty(); - assertThat(emailSettings.getSmtpPassword()).isEmpty(); - assertThat(emailSettings.getSecureConnection()).isEmpty(); - assertThat(emailSettings.getFrom()).isEqualTo("noreply@nowhere"); - assertThat(emailSettings.getPrefix()).isEqualTo("[SONAR]"); - assertThat(emailSettings.getServerBaseURL()).isEqualTo(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); - } -} 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