From: Julien Lancelot Date: Mon, 5 Sep 2016 15:39:58 +0000 (+0200) Subject: SONAR-8055 Declare emails configuration with PropertyDefinition X-Git-Tag: 6.1-RC1~202 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ade78dc77fb8e7e8643d8e106e07deae31e262a8;p=sonarqube.git SONAR-8055 Declare emails configuration with PropertyDefinition --- diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 6bf1b1a3da7..258b34ed9e0 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -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(); diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index 5c173cae78d..982466b9d5c 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -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) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 3960bb7054b..8a45c529669 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -106,6 +106,11 @@ public interface CoreProperties { */ String SUBCATEGORY_COVERAGE_EXCLUSIONS = "coverage"; + /** + * @since 6.1 + */ + String SUBCATEGORY_EMAIL = "email"; + /** * @since 3.7 */ 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 index 9628a3c7cef..1d85fb02ccd 100644 --- 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 @@ -20,11 +20,19 @@ 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 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()); + } } 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 index 2c395c980ca..c9271b72817 100644 --- 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 @@ -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); + } }