]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8055 Declare emails configuration with PropertyDefinition 1212/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 5 Sep 2016 15:39:58 +0000 (17:39 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 6 Sep 2016 09:23:54 +0000 (11:23 +0200)
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java
sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java

index 6bf1b1a3da7d23a3c2380967f98a6d87f7ca477f..258b34ed9e09d75e8dfaf277882c3f23ea1f15c9 100644 (file)
@@ -108,7 +108,7 @@ public class ComputeEngineContainerImplTest {
         + 24 // level 1
         + 49 // content of DaoModule
         + 2 // content of EsSearchModule
-        + 54 // content of CorePropertyDefinitions
+        + 61 // content of CorePropertyDefinitions
         + 1 // content of CePropertyDefinitions
     );
     assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
index 5c173cae78d11f3a840ebcc75472a9c569b5cf23..982466b9d5c2f64ef6276145c4a6f4b9d6e233e5 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.util.List;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.PropertyType;
+import org.sonar.api.config.EmailSettings;
 import org.sonar.api.config.PropertyDefinition;
 import org.sonar.api.resources.Qualifiers;
 
@@ -57,6 +58,7 @@ public class CorePropertyDefinitions {
     defs.addAll(SecurityProperties.all());
     defs.addAll(DebtProperties.all());
     defs.addAll(PurgeProperties.all());
+    defs.addAll(EmailSettings.definitions());
 
     defs.addAll(ImmutableList.of(
       PropertyDefinition.builder(PROP_PASSWORD)
index 3960bb7054b250dc74021534fd542bf577ac658b..8a45c529669c54e58ff95c1dade6b1fc22d8e280 100644 (file)
@@ -106,6 +106,11 @@ public interface CoreProperties {
    */
   String SUBCATEGORY_COVERAGE_EXCLUSIONS = "coverage";
 
+  /**
+   * @since 6.1
+   */
+  String SUBCATEGORY_EMAIL = "email";
+
   /**
    * @since 3.7
    */
index 9628a3c7cef562bebe26964af3ca024bda6b9dce..1d85fb02ccda4d271951b352f773a15ee04c5cdc 100644 (file)
 package org.sonar.api.config;
 
 import com.google.common.base.MoreObjects;
-import org.sonar.api.CoreProperties;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 
+import static org.sonar.api.CoreProperties.CATEGORY_GENERAL;
+import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
+import static org.sonar.api.CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE;
+import static org.sonar.api.CoreProperties.SUBCATEGORY_EMAIL;
+import static org.sonar.api.PropertyType.INTEGER;
+import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
+
 /**
  * If batch extensions use this component, then batch must be executed with administrator rights (see properties sonar.login and sonar.password)
  *
@@ -84,10 +92,69 @@ public class EmailSettings {
   }
 
   public String getServerBaseURL() {
-    return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
+    return get(SERVER_BASE_URL, SERVER_BASE_URL_DEFAULT_VALUE);
   }
 
   private String get(String key, String defaultValue) {
     return MoreObjects.firstNonNull(settings.getString(key), defaultValue);
   }
+
+  /**
+   * @since 6.1
+   */
+  public static List<PropertyDefinition> definitions() {
+    return ImmutableList.of(
+      PropertyDefinition.builder(SMTP_HOST)
+        .name("SMTP host")
+        .description("For example \"smtp.gmail.com\". Leave blank to disable email sending.")
+        .defaultValue(SMTP_HOST_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .build(),
+      PropertyDefinition.builder(SMTP_PORT)
+        .name("SMTP port")
+        .description("Port number to connect with SMTP server.")
+        .defaultValue(SMTP_PORT_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .type(INTEGER)
+        .build(),
+      PropertyDefinition.builder(SMTP_SECURE_CONNECTION)
+        .name("Use secure connection")
+        .description("Whether to use secure connection and its type.")
+        .defaultValue(SMTP_SECURE_CONNECTION_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .type(SINGLE_SELECT_LIST)
+        .options("ssl", "starttls")
+        .build(),
+      PropertyDefinition.builder(SMTP_USERNAME)
+        .name("SMTP username")
+        .description("Username to use with authenticated SMTP.")
+        .defaultValue(SMTP_USERNAME_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .build(),
+      PropertyDefinition.builder(SMTP_PASSWORD)
+        .name("SMTP password")
+        .description("Password to use with authenticated SMTP.")
+        .defaultValue(SMTP_PASSWORD_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .build(),
+      PropertyDefinition.builder(FROM)
+        .name("From address")
+        .description("Emails will come from this address. For example - \"noreply@sonarsource.com\". Note that server may ignore this setting.")
+        .defaultValue(FROM_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .build(),
+      PropertyDefinition.builder(PREFIX)
+        .name("Email prefix")
+        .description("Prefix will be prepended to all outgoing email subjects.")
+        .defaultValue(PREFIX_DEFAULT)
+        .category(CATEGORY_GENERAL)
+        .subCategory(SUBCATEGORY_EMAIL)
+        .build());
+  }
 }
index 2c395c980ca562f008a3862fa2aa31fdc74acab2..c9271b728173fab0390d13567578b3666fce967a 100644 (file)
@@ -39,4 +39,9 @@ public class EmailSettingsTest {
     assertThat(underTest.getPrefix()).isEqualTo("[SONARQUBE]");
     assertThat(underTest.getServerBaseURL()).isEqualTo(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
   }
+
+  @Test
+  public void return_definitions() {
+    assertThat(EmailSettings.definitions()).hasSize(7);
+  }
 }