Browse Source

SONAR-8055 Declare emails configuration with PropertyDefinition

tags/6.1-RC1
Julien Lancelot 7 years ago
parent
commit
ade78dc77f

+ 1
- 1
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java View 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();

+ 2
- 0
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java View 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)

+ 5
- 0
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java View File

@@ -106,6 +106,11 @@ public interface CoreProperties {
*/
String SUBCATEGORY_COVERAGE_EXCLUSIONS = "coverage";

/**
* @since 6.1
*/
String SUBCATEGORY_EMAIL = "email";

/**
* @since 3.7
*/

+ 69
- 2
sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java View File

@@ -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<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());
}
}

+ 5
- 0
sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java View 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);
}
}

Loading…
Cancel
Save