]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3593 move EmailSettings to org.sonar.api.conf
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Jul 2012 10:21:12 +0000 (12:21 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Jul 2012 10:21:29 +0000 (12:21 +0200)
13 files changed:
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java [deleted file]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb

index 382e9ce4f95ddfb420691984664cb0299fb642a1..febacbd68bc147368e7e6350a93840e206b29da4 100644 (file)
@@ -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());
       }
index 8db4314562ccce8a4e057d6ec775fdeceed71f54..2294b368e34e7f64961efb49d91ce2c08f3022d4 100644 (file)
@@ -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;
 
index 93a41c9b7c81be2787c4fe8f0622aed0c224e427..57da295f6eb0d0449222489be82a13aaeb731dd0 100644 (file)
@@ -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;
index 3940b7d780966f47fcf61c615e8c9a901a0e7ab4..3cba1e0fc0a944f02c419eda7725795a74935418 100644 (file)
@@ -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");
index 43b0368e6368e35d9b8d501f214e4ba062ffdcce..3bd3229042290d01473d2933771fee5aee56d004 100644 (file)
@@ -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;
index d9605a369355f56b3447ed53be68e0524c12e044..3e52167e9d11ce01cf21b1e5565f8d6e7c0de683 100644 (file)
@@ -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;
 
index 60c05bf6d5903fe92a4d7a45357a17812a1f3213..61a01cb36cf225ac99faa9723b1e2b2166683ee5 100644 (file)
@@ -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 (file)
index 0000000..d2c8164
--- /dev/null
@@ -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 (file)
index 23eaac6..0000000
+++ /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 (file)
index 0000000..c960981
--- /dev/null
@@ -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 (file)
index f548b2f..0000000
+++ /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);
-  }
-}
index e0d9f48858a8653ced5fb8cd554ba4a8b71d95c0..e318db2b62592c2f2c2528e84a3c70bce56b2ef0 100644 (file)
@@ -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;
index e5c77a7e50d53cd7c302c349f7c78d37b56241d8..8e5fd6d5e1b5cb7c3f53ff2d311d2e0ed96c009d 100644 (file)
@@ -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