]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9478 Replace Settings by Configuration
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 29 Jun 2017 16:13:15 +0000 (18:13 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 4 Jul 2017 21:47:46 +0000 (23:47 +0200)
206 files changed:
server/sonar-ce-api/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
server/sonar-ce-api/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java
server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-db-core/src/test/java/org/sonar/db/CoreTestDb.java
server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java
server/sonar-db-core/src/test/java/org/sonar/db/ResultSetIteratorTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/Filters.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/BatchSessionTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeConfigurationTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDtoTest.java
server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java
server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectSettingsFactory.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java
server/sonar-server/src/main/java/org/sonar/server/authentication/JwtHttpHandler.java
server/sonar-server/src/main/java/org/sonar/server/authentication/JwtSerializer.java
server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java
server/sonar-server/src/main/java/org/sonar/server/authentication/SsoAuthenticator.java
server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java
server/sonar-server/src/main/java/org/sonar/server/authentication/ws/ValidateAction.java
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepository.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepository.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryImpl.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssignee.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilter.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureComputersVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettings.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadQualityGateStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java
server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java
server/sonar-server/src/main/java/org/sonar/server/es/IndexDefinitions.java
server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java
server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/notification/NotificationDaemon.java
server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java
server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerFileSystemImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdLoader.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java
server/sonar-server/src/main/java/org/sonar/server/platform/UrlSettings.java
server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabase.java
server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabaseFactory.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/SettingsAction.java
server/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/util/OkHttpClientProvider.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java
server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java
server/sonar-server/src/test/java/org/sonar/server/authentication/ws/ValidateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TestSettingsRepository.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettingsTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateLoadingStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java
server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java
server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java
server/sonar-server/src/test/java/org/sonar/server/es/IndexerStartupTaskTest.java
server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDaemonTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerLoggingTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/UrlSettingsTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ProjectSettingsFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
sonar-core/src/main/java/org/sonar/core/config/ConfigurationProvider.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java
sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java
sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/config/internal/MapSettings.java
sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java

index 77e6f78be49b108c4b4013445be4c68e26b18301..be00dbc3d088584e988eb8e0c68a36a939e2c7c1 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.ce.configuration;
 
 import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -47,8 +47,8 @@ public class CeConfigurationImpl implements CeConfiguration, Startable {
 
   private final int workerCount;
 
-  public CeConfigurationImpl(Settings settings) {
-    String workerCountAsStr = settings.getString(CE_WORKERS_COUNT_PROPERTY);
+  public CeConfigurationImpl(Configuration config) {
+    String workerCountAsStr = config.get(CE_WORKERS_COUNT_PROPERTY).orElse(null);
     if (workerCountAsStr == null || workerCountAsStr.isEmpty()) {
       this.workerCount = DEFAULT_WORKER_COUNT;
     } else {
@@ -72,8 +72,7 @@ public class CeConfigurationImpl implements CeConfiguration, Startable {
     return MessageException.of(format(
       "value '%s' of property %s is invalid. It must an integer strictly greater than 0.",
       workerCountAsStr,
-      CE_WORKERS_COUNT_PROPERTY)
-      );
+      CE_WORKERS_COUNT_PROPERTY));
   }
 
   @Override
index 11a80512919dc6e338339c64049b1abd8f9981fa..2f501716b2dcb73b300f96f6647b5702a64e43e7 100644 (file)
@@ -23,8 +23,7 @@ import java.util.Random;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.MessageException;
 
 import static java.lang.Math.abs;
@@ -36,32 +35,32 @@ public class CeConfigurationImplTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   @Test
   public void getWorkerCount_returns_1_when_worker_property_is_not_defined() {
-    assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
   }
 
   @Test
   public void getWorkerCount_returns_1_when_worker_property_is_empty() {
     settings.setProperty(CE_WORKERS_COUNT_PROPERTY, "");
 
-    assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
   }
 
   @Test
   public void getWorkerCount_returns_1_when_worker_property_is_space_chars() {
     settings.setProperty(CE_WORKERS_COUNT_PROPERTY, "  \n  ");
 
-    assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
   }
 
   @Test
   public void getWorkerCount_returns_1_when_worker_property_is_1() {
     settings.setProperty(CE_WORKERS_COUNT_PROPERTY, 1);
 
-    assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
   }
 
   @Test
@@ -69,7 +68,7 @@ public class CeConfigurationImplTest {
     int value = abs(new Random().nextInt()) + 2;
     settings.setProperty(CE_WORKERS_COUNT_PROPERTY, value);
 
-    assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(value);
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(value);
   }
 
   @Test
@@ -79,7 +78,7 @@ public class CeConfigurationImplTest {
 
     expectMessageException(value);
 
-    new CeConfigurationImpl(settings);
+    new CeConfigurationImpl(settings.asConfig());
   }
 
   @Test
@@ -89,7 +88,7 @@ public class CeConfigurationImplTest {
 
     expectMessageException(value);
 
-    new CeConfigurationImpl(settings);
+    new CeConfigurationImpl(settings.asConfig());
   }
 
   @Test
@@ -101,7 +100,7 @@ public class CeConfigurationImplTest {
     expectedException.expectMessage("value '" + value + "' of property " + CE_WORKERS_COUNT_PROPERTY + " is invalid. " +
       "It must an integer strictly greater than 0");
 
-    new CeConfigurationImpl(settings);
+    new CeConfigurationImpl(settings.asConfig());
   }
 
   private void expectMessageException(int value) {
@@ -112,13 +111,13 @@ public class CeConfigurationImplTest {
 
   @Test
   public void getCleanCeTasksInitialDelay_returns_1() {
-    assertThat(new CeConfigurationImpl(settings).getCleanCeTasksInitialDelay())
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getCleanCeTasksInitialDelay())
       .isEqualTo(1L);
   }
 
   @Test
   public void getCleanCeTasksDelay_returns_10() {
-    assertThat(new CeConfigurationImpl(settings).getCleanCeTasksDelay())
+    assertThat(new CeConfigurationImpl(settings.asConfig()).getCleanCeTasksDelay())
       .isEqualTo(10L);
   }
 }
index 13c383ba329d221e1b52a7f48a212464800986ce..b913387c84a7a2661ae1c7f6b538d8a466e27bbf 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.locks.Lock;
 import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.process.ProcessProperties;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -46,10 +46,10 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
   @VisibleForTesting
   protected HazelcastInstance hzInstance;
 
-  public HazelcastClientWrapperImpl(Settings settings) {
-    boolean clusterEnabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
-    String clusterName = settings.getString(ProcessProperties.CLUSTER_NAME);
-    String clusterLocalEndPoint = settings.getString(ProcessProperties.CLUSTER_LOCALENDPOINT);
+  public HazelcastClientWrapperImpl(Configuration config) {
+    boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+    String clusterName = config.get(ProcessProperties.CLUSTER_NAME).orElse(null);
+    String clusterLocalEndPoint = config.get(ProcessProperties.CLUSTER_LOCALENDPOINT).orElse(null);
 
     checkState(clusterEnabled, "Cluster is not enabled");
     checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set");
@@ -85,7 +85,7 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
   }
 
   @Override
-  public <K,V> Map<K,V> getReplicatedMap(String name) {
+  public <K, V> Map<K, V> getReplicatedMap(String name) {
     return hzInstance.getReplicatedMap(name);
   }
 
index 992df9f4a30b84e38487568d009b92f50c6238eb..5f50464eb512c5259940c28e93898e04e1051ddf 100644 (file)
@@ -52,10 +52,11 @@ import org.sonar.ce.log.CeProcessLogging;
 import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
 import org.sonar.ce.queue.CeQueueCleaner;
 import org.sonar.ce.queue.PurgeCeActivities;
-import org.sonar.ce.settings.ProjectSettingsFactory;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
 import org.sonar.ce.taskprocessor.CeTaskProcessorModule;
 import org.sonar.ce.user.CeUserSession;
 import org.sonar.core.component.DefaultResourceTypes;
+import org.sonar.core.config.ConfigurationProvider;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.i18n.DefaultI18n;
 import org.sonar.core.i18n.RuleI18nManager;
@@ -181,12 +182,10 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
     if (props.valueAsBoolean("sonar.cluster.enabled")) {
       this.level4.add(
         HazelcastClientWrapperImpl.class,
-        CeDistributedInformationImpl.class
-      );
+        CeDistributedInformationImpl.class);
     } else {
       this.level4.add(
-        StandaloneCeDistributedInformation.class
-      );
+        StandaloneCeDistributedInformation.class);
     }
     configureFromModules(this.level4);
     ServerExtensionInstaller extensionInstaller = this.level4.getComponentByType(ServerExtensionInstaller.class);
@@ -225,6 +224,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
     Version apiVersion = ApiVersion.load(System2.INSTANCE);
     return new Object[] {
       ThreadLocalSettings.class,
+      new ConfigurationProvider(),
       new SonarQubeVersion(apiVersion),
       SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE),
       CeProcessLogging.class,
@@ -406,7 +406,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
       CeTaskProcessorModule.class,
 
       InternalPropertiesImpl.class,
-      ProjectSettingsFactory.class,
+      ProjectConfigurationFactory.class,
 
       // cleaning
       CeCleaningModule.class
index 1267693e9e1de9f3134f2d3493cd6d207732c1a1..3c483a80f3e9ca1e9812e1e2add532e3064f4649 100644 (file)
@@ -36,7 +36,6 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -51,7 +50,6 @@ import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.process.NetworkUtils;
 import org.sonar.process.ProcessProperties;
@@ -74,8 +72,8 @@ public class HazelcastClientWrapperImplTest {
     int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
     hzCluster = HazelcastTestHelper.createHazelcastCluster("cluster_with_client", port);
 
-    Settings settings = createClusterSettings("cluster_with_client", "localhost:" + port);
-    hzClient = new HazelcastClientWrapperImpl(settings);
+    MapSettings settings = createClusterSettings("cluster_with_client", "localhost:" + port);
+    hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @AfterClass
@@ -94,8 +92,8 @@ public class HazelcastClientWrapperImplTest {
 
   @Test
   public void start_throws_ISE_if_LOCALENDPOINT_is_incorrect() {
-    Settings settings = createClusterSettings("sonarqube", "\u4563\u1432\u1564");
-    HazelcastClientWrapperImpl hzClient = new HazelcastClientWrapperImpl(settings);
+    MapSettings settings = createClusterSettings("sonarqube", "\u4563\u1432\u1564");
+    HazelcastClientWrapperImpl hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Unable to connect to any address in the config! The following addresses were tried:");
@@ -105,56 +103,56 @@ public class HazelcastClientWrapperImplTest {
 
   @Test
   public void constructor_throws_ISE_if_LOCALENDPOINT_is_empty() {
-    Settings settings = createClusterSettings("sonarqube", "");
+    MapSettings settings = createClusterSettings("sonarqube", "");
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("LocalEndPoint have not been set");
 
-    new HazelcastClientWrapperImpl(settings);
+    new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @Test
   public void constructor_throws_ISE_if_CLUSTER_ENABLED_is_false() {
-    Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+    MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Cluster is not enabled");
 
-    new HazelcastClientWrapperImpl(settings);
+    new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @Test
   public void constructor_throws_ISE_if_missing_CLUSTER_ENABLED() {
-    Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+    MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
     settings.removeProperty(ProcessProperties.CLUSTER_ENABLED);
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Cluster is not enabled");
 
-    new HazelcastClientWrapperImpl(settings);
+    new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @Test
   public void constructor_throws_ISE_if_missing_CLUSTER_NAME() {
-    Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+    MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
     settings.removeProperty(ProcessProperties.CLUSTER_NAME);
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("sonar.cluster.name is missing");
 
-    new HazelcastClientWrapperImpl(settings);
+    new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @Test
   public void constructor_throws_ISE_if_missing_CLUSTER_LOCALENDPOINT() {
-    Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+    MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
     settings.removeProperty(ProcessProperties.CLUSTER_LOCALENDPOINT);
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("LocalEndPoint have not been set");
 
-    new HazelcastClientWrapperImpl(settings);
+    new HazelcastClientWrapperImpl(settings.asConfig());
   }
 
   @Test
@@ -162,9 +160,9 @@ public class HazelcastClientWrapperImplTest {
     int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
     // Launch a fake Hazelcast instance
     HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster("client_must_connect_to_hazelcast", port);
-    Settings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
+    MapSettings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
 
-    HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings);
+    HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings.asConfig());
     ClientListenerImpl clientListener = new ClientListenerImpl();
     hzInstance.getClientService().addClientListener(clientListener);
     try {
@@ -184,9 +182,8 @@ public class HazelcastClientWrapperImplTest {
 
       Set<String> setTest = new HashSet<>();
       setTest.addAll(
-        Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10))
-      );
-      Map<String, Set<String>> replicatedMap =  hzClient.getReplicatedMap("TEST1");
+        Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10)));
+      Map<String, Set<String>> replicatedMap = hzClient.getReplicatedMap("TEST1");
       replicatedMap.put("KEY1", ImmutableSet.copyOf(setTest));
       assertThat(hzCluster.getReplicatedMap("TEST1"))
         .containsOnlyKeys("KEY1");
@@ -235,8 +232,7 @@ public class HazelcastClientWrapperImplTest {
       mapTest.put("a", Arrays.asList("123", "456"));
       hzCluster.getMap("TEST3").putAll(mapTest);
       assertThat(hzClient.getMap("TEST3")).containsExactly(
-        entry("a", Arrays.asList("123", "456"))
-      );
+        entry("a", Arrays.asList("123", "456")));
     } finally {
       hzClient.stop();
     }
@@ -272,8 +268,7 @@ public class HazelcastClientWrapperImplTest {
     }
     assertThat(memoryAppender.events).isNotEmpty();
     memoryAppender.events.stream().forEach(
-      e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast")
-    );
+      e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast"));
   }
 
   private class ClientListenerImpl implements ClientListener {
@@ -290,12 +285,11 @@ public class HazelcastClientWrapperImplTest {
     }
   }
 
-  private static Settings createClusterSettings(String name, String localEndPoint) {
-    Properties properties = new Properties();
-    properties.setProperty(ProcessProperties.CLUSTER_NAME, name);
-    properties.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint);
-    properties.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
-    return new MapSettings(new PropertyDefinitions()).addProperties(properties);
+  private static MapSettings createClusterSettings(String name, String localEndPoint) {
+    return new MapSettings(new PropertyDefinitions())
+      .setProperty(ProcessProperties.CLUSTER_NAME, name)
+      .setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint)
+      .setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
   }
 
   private class MemoryAppender<E> extends AppenderBase<E> {
index 4fdec8c405818e4f87a316711144137869792aa5..ca5b507a24b4f458b0796cbd8a269cf7aba696f3 100644 (file)
@@ -134,7 +134,7 @@ public class ComputeEngineContainerImplTest {
     );
     assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
       COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
-        + 23 // level 1
+        + 24 // level 1
         + 46 // content of DaoModule
         + 3 // content of EsSearchModule
         + 58 // content of CorePropertyDefinitions
index bc5cd3cb6d43cc70dcf68b7c9270b0a5c2cb227d..307521236070a5d05cace2aa0be00896d50d012c 100644 (file)
@@ -37,7 +37,7 @@ import org.dbunit.IDatabaseTester;
 import org.dbunit.dataset.datatype.IDataTypeFactory;
 import org.junit.AssumptionViolatedException;
 import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.dialect.H2;
index 1ffc411cb44a17f40f10a17940fdc3f5e53bf8f8..5d9d83d5e76d869f3f80032e030ba88382b657f0 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Properties;
 import org.apache.commons.dbcp.BasicDataSource;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.dialect.PostgreSql;
 import org.sonar.process.logging.LogbackHelper;
 
index 19a9e7089aead25d2c7af465c99ec29c3035b6fc..c50d0943a0af42c0e90cb2cf69e2ca046960a4cc 100644 (file)
@@ -26,7 +26,6 @@ import java.sql.SQLException;
 import java.util.NoSuchElementException;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.utils.System2;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
index be316cb26e96320d76280d536c3c9ab07076adeb..a56ebd4883feb9ef0d33a69d7cacf96ed6bf26da 100644 (file)
@@ -44,8 +44,8 @@ import static java.util.Collections.emptyList;
 import static java.util.Objects.requireNonNull;
 import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.sonar.db.DaoDatabaseUtils.buildLikeValue;
-import static org.sonar.db.DaoDatabaseUtils.executeLargeInputs;
-import static org.sonar.db.DaoDatabaseUtils.executeLargeUpdates;
+import static org.sonar.db.DatabaseUtils.executeLargeInputs;
+import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
 import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
 
 public class ComponentDao implements Dao {
index 7f74b5ee284329d20ab5794cabac6befb38c0c5b..2aa056856b969c183af582fa63df61653abab1e7 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
-import org.sonar.db.Pagination;
 import org.sonar.db.component.ComponentMapper;
 
 import static com.google.common.base.Preconditions.checkArgument;
index cc6fb0dbe18ab9e9f8df4ab80a6ddebe8cd7676c..2d30880fc0ad209bbdc32110a384caa121e28004 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Collection;
 import java.util.Date;
 import javax.annotation.CheckForNull;
 import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.utils.System2;
 import org.sonar.core.config.PurgeConstants;
@@ -46,12 +46,12 @@ public class PurgeConfiguration {
     this.disabledComponentUuids = disabledComponentUuids;
   }
 
-  public static PurgeConfiguration newDefaultPurgeConfiguration(Settings settings, IdUuidPair idUuidPair, Collection<String> disabledComponentUuids) {
+  public static PurgeConfiguration newDefaultPurgeConfiguration(Configuration config, IdUuidPair idUuidPair, Collection<String> disabledComponentUuids) {
     String[] scopes = new String[] {Scopes.FILE};
-    if (settings.getBoolean(PurgeConstants.PROPERTY_CLEAN_DIRECTORY)) {
+    if (config.getBoolean(PurgeConstants.PROPERTY_CLEAN_DIRECTORY).orElse(false)) {
       scopes = new String[] {Scopes.DIRECTORY, Scopes.FILE};
     }
-    return new PurgeConfiguration(idUuidPair, scopes, settings.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES), System2.INSTANCE, disabledComponentUuids);
+    return new PurgeConfiguration(idUuidPair, scopes, config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(), System2.INSTANCE, disabledComponentUuids);
   }
 
   public IdUuidPair rootProjectIdUuid() {
index 10dab8e6f454bcef2ca41b1606592484529448e7..cbc3016339e96de202b84eacd63dd12b07d49506 100644 (file)
@@ -23,7 +23,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
 import java.util.ArrayList;
 import java.util.List;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -34,8 +34,6 @@ import org.sonar.db.purge.PurgeDao;
 import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.purge.PurgeableAnalysisDto;
 
-import static org.sonar.core.util.stream.MoreCollectors.toList;
-
 public class DefaultPeriodCleaner {
 
   private static final Logger LOG = Loggers.get(DefaultPeriodCleaner.class);
@@ -47,8 +45,8 @@ public class DefaultPeriodCleaner {
     this.profiler = profiler;
   }
 
-  public void clean(DbSession session, String rootUuid, Settings settings) {
-    doClean(rootUuid, new Filters(settings).all(), session);
+  public void clean(DbSession session, String rootUuid, Configuration config) {
+    doClean(rootUuid, new Filters(config).all(), session);
   }
 
   @VisibleForTesting
index fab44eaa2cccb2b26bfb77b1964be43500c7034a..8ed4a3c7a6bf7a914cf36ec92a8de465a83f4fc5 100644 (file)
@@ -24,17 +24,17 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.core.config.PurgeConstants;
 
 class Filters {
   private final List<Filter> all = Lists.newArrayList();
 
-  Filters(Settings settings) {
-    Date dateToStartKeepingOneSnapshotByDay = getDateFromHours(settings, PurgeConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY);
-    Date dateToStartKeepingOneSnapshotByWeek = getDateFromWeeks(settings, PurgeConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK);
-    Date dateToStartKeepingOneSnapshotByMonth = getDateFromWeeks(settings, PurgeConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
-    Date dateToStartDeletingAllSnapshots = getDateFromWeeks(settings, PurgeConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS);
+  Filters(Configuration config) {
+    Date dateToStartKeepingOneSnapshotByDay = getDateFromHours(config, PurgeConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY);
+    Date dateToStartKeepingOneSnapshotByWeek = getDateFromWeeks(config, PurgeConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK);
+    Date dateToStartKeepingOneSnapshotByMonth = getDateFromWeeks(config, PurgeConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
+    Date dateToStartDeletingAllSnapshots = getDateFromWeeks(config, PurgeConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS);
 
     all.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByDay, Calendar.DAY_OF_YEAR, "day"));
     all.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByMonth, dateToStartKeepingOneSnapshotByWeek, Calendar.WEEK_OF_YEAR, "week"));
@@ -42,13 +42,13 @@ class Filters {
     all.add(new DeleteAllFilter(dateToStartDeletingAllSnapshots));
   }
 
-  static Date getDateFromWeeks(Settings settings, String propertyKey) {
-    int weeks = settings.getInt(propertyKey);
+  static Date getDateFromWeeks(Configuration config, String propertyKey) {
+    int weeks = config.getInt(propertyKey).get();
     return DateUtils.addWeeks(new Date(), -weeks);
   }
 
-  static Date getDateFromHours(Settings settings, String propertyKey) {
-    int hours = settings.getInt(propertyKey);
+  static Date getDateFromHours(Configuration config, String propertyKey) {
+    int hours = config.getInt(propertyKey).get();
     return DateUtils.addHours(new Date(), -hours);
   }
 
index cd5e4275373107e0c279dd05a041b341a3cf89db..e4902888070afa5fcdc77c3b9d577e5f5db3f3e3 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.db.RowNotFoundException;
 import org.sonar.db.organization.OrganizationDto;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.Optional.*;
+import static java.util.Optional.ofNullable;
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
 
 public class RuleDao implements Dao {
index e9156a1c09a3ebe434b26aa285d6ced950f06f82..f722a77d2b6e713949fe90245583107e3348afc4 100644 (file)
@@ -30,8 +30,8 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.session.RowBounds;
 import org.sonar.api.utils.System2;
 import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
 import org.sonar.db.DaoDatabaseUtils;
+import org.sonar.db.DbSession;
 import org.sonar.db.WildcardPosition;
 
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
index 94d53172528b6be238d0af9227d045aa8217dfa6..2d18560a98f85e85ae2e6a483791bf86e222d4f6 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.db;
 
 import org.junit.Test;
 
-import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
index 7e3e3208d01d18e5d50c3fffa2ad4173269158f9..2efdcfc36298969bc4a184889585c698725576c8 100644 (file)
@@ -53,8 +53,8 @@ import static org.assertj.guava.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newSubView;
 import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
index 0c7ba44000c57d34c629153a16f207cc7b032941..9c027764c2f021788f62df55224ba4d1a42392f1 100644 (file)
  */
 package org.sonar.db.duplication;
 
+import java.util.List;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 
-import java.util.List;
-
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 
index 3afa0d3300a70fdd83c1d9c51563c324f4160454..57b89e8843e41be51fb189aadf2f64def44f9bc9 100644 (file)
@@ -22,12 +22,13 @@ package org.sonar.db.purge;
 import java.util.Collections;
 import java.util.Date;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.config.PurgeConstants;
+import org.sonar.core.config.PurgeProperties;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -55,12 +56,12 @@ public class PurgeConfigurationTest {
 
   @Test
   public void do_not_delete_directory_by_default() {
-    Settings settings = new MapSettings();
+    MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all()));
     settings.setProperty(PurgeConstants.PROPERTY_CLEAN_DIRECTORY, false);
     settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
     Date now = new Date();
 
-    PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings, new IdUuidPair(42L, "any-uuid"), Collections.emptyList());
+    PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings.asConfig(), new IdUuidPair(42L, "any-uuid"), Collections.emptyList());
 
     assertThat(underTest.scopesWithoutHistoricalData()).contains(Scopes.FILE)
       .doesNotContain(Scopes.DIRECTORY);
@@ -69,10 +70,10 @@ public class PurgeConfigurationTest {
 
   @Test
   public void delete_directory_if_in_settings() {
-    Settings settings = new MapSettings();
+    MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all()));
     settings.setProperty(PurgeConstants.PROPERTY_CLEAN_DIRECTORY, true);
 
-    PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings, new IdUuidPair(42L, "any-uuid"), Collections.emptyList());
+    PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings.asConfig(), new IdUuidPair(42L, "any-uuid"), Collections.emptyList());
 
     assertThat(underTest.scopesWithoutHistoricalData()).contains(Scopes.DIRECTORY, Scopes.FILE);
   }
index 0e11e3706137d31833d6a33c850414edb8ddccb0..2e8e1d038865a4959f63181e038f7a086132d54d 100644 (file)
@@ -33,8 +33,8 @@ import org.sonar.db.purge.PurgeDao;
 import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.purge.PurgeableAnalysisDto;
 
-import static org.mockito.Mockito.anyListOf;
-import static org.mockito.Mockito.eq;
+import static org.mockito.Matchers.anyListOf;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.when;
index 3a2f026169b80cc71eb5b18ee8f326a1dbdd7d1d..7e62fc60387dca18866bda6b578ef9f046e3fe4d 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 
 import static java.util.Arrays.asList;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
 
 public class QProfileChangeDaoTest {
index 5747d4a07266a043e46233e4f04abfd9da17840e..3676c783462aa61c0981c4542846df796ce218d5 100644 (file)
  */
 package org.sonar.db.user;
 
-import static org.assertj.core.api.Assertions.assertThat;
-
 import java.util.Arrays;
 import java.util.Collections;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 public class UserDtoTest {
 
   @Rule
index 309bf90ad22298fe4bd58e1181a279b8744ebe30..23b1ebb10db25100e17930cefd5f1e41030ff9ce 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Optional;
 import okhttp3.OkHttpClient;
 import okhttp3.RequestBody;
 import org.apache.commons.io.IOUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.process.DefaultProcessCommands;
 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
@@ -45,8 +45,8 @@ public class CeHttpClient {
 
   private final File ipcSharedDir;
 
-  public CeHttpClient(Settings props) {
-    this.ipcSharedDir = new File(props.getString(PROPERTY_SHARED_PATH));
+  public CeHttpClient(Configuration config) {
+    this.ipcSharedDir = new File(config.get(PROPERTY_SHARED_PATH).get());
   }
 
   /**
diff --git a/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java
new file mode 100644 (file)
index 0000000..dbec22e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.ce.settings;
+
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.ConfigurationBridge;
+import org.sonar.db.DbClient;
+
+@ComputeEngineSide
+public class ProjectConfigurationFactory {
+
+  private final Settings globalSettings;
+  private final DbClient dbClient;
+
+  public ProjectConfigurationFactory(Settings globalSettings, DbClient dbClient) {
+    this.globalSettings = globalSettings;
+    this.dbClient = dbClient;
+  }
+
+  public Configuration newProjectConfiguration(String projectKey) {
+    Settings projectSettings = new ProjectSettings(globalSettings);
+    dbClient.propertiesDao()
+      .selectProjectProperties(projectKey)
+      .forEach(property -> projectSettings.setProperty(property.getKey(), property.getValue()));
+    return new ConfigurationBridge(projectSettings);
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectSettingsFactory.java b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectSettingsFactory.java
deleted file mode 100644 (file)
index 351d497..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.ce.settings;
-
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
-import org.sonar.db.DbClient;
-
-@ComputeEngineSide
-public class ProjectSettingsFactory {
-
-  private final Settings globalSettings;
-  private final DbClient dbClient;
-
-  public ProjectSettingsFactory(Settings globalSettings, DbClient dbClient) {
-    this.globalSettings = globalSettings;
-    this.dbClient = dbClient;
-  }
-
-  public Settings newProjectSettings(String projectKey) {
-    Settings projectSettings = new ProjectSettings(globalSettings);
-    dbClient.propertiesDao()
-      .selectProjectProperties(projectKey)
-      .forEach(property -> projectSettings.setProperty(property.getKey(), property.getValue()));
-    return projectSettings;
-  }
-}
index 297345ec9f53639d1e2515eb7451ddd5032a50fa..54e998e9576a2023f07197eb6c2e0dad64110474 100644 (file)
 package org.sonar.server.app;
 
 import java.io.File;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.process.DefaultProcessCommands;
 import org.sonar.process.ProcessCommands;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
 
 public class ProcessCommandWrapperImpl implements ProcessCommandWrapper {
-  private final Settings settings;
+  private final Configuration config;
 
-  public ProcessCommandWrapperImpl(Settings settings) {
-    this.settings = settings;
+  public ProcessCommandWrapperImpl(Configuration config) {
+    this.config = config;
   }
 
   @Override
@@ -87,14 +86,10 @@ public class ProcessCommandWrapperImpl implements ProcessCommandWrapper {
   }
 
   private int nonNullAsInt(String key) {
-    String s = settings.getString(key);
-    checkArgument(s != null, "Property %s is not set", key);
-    return Integer.parseInt(s);
+    return config.getInt(key).orElseThrow(() -> new IllegalArgumentException(String.format("Property %s is not set", key)));
   }
 
   private File nonNullValueAsFile(String key) {
-    String s = settings.getString(key);
-    checkArgument(s != null, "Property %s is not set", key);
-    return new File(s);
+    return new File(config.get(key).orElseThrow(() -> new IllegalArgumentException(String.format("Property %s is not set", key))));
   }
 }
index 905cc015943b1c0d61c22656cef98d26c706714b..461910be4215b23768ea3194c567c3574dce56a4 100644 (file)
@@ -29,7 +29,7 @@ import javax.annotation.Nullable;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -70,11 +70,11 @@ public class JwtHttpHandler {
   private final int sessionTimeoutInSeconds;
   private final JwtCsrfVerifier jwtCsrfVerifier;
 
-  public JwtHttpHandler(System2 system2, DbClient dbClient, Settings settings, JwtSerializer jwtSerializer, JwtCsrfVerifier jwtCsrfVerifier) {
+  public JwtHttpHandler(System2 system2, DbClient dbClient, Configuration config, JwtSerializer jwtSerializer, JwtCsrfVerifier jwtCsrfVerifier) {
     this.jwtSerializer = jwtSerializer;
     this.dbClient = dbClient;
     this.system2 = system2;
-    this.sessionTimeoutInSeconds = getSessionTimeoutInSeconds(settings);
+    this.sessionTimeoutInSeconds = getSessionTimeoutInSeconds(config);
     this.jwtCsrfVerifier = jwtCsrfVerifier;
   }
 
@@ -176,14 +176,9 @@ public class JwtHttpHandler {
     }
   }
 
-  private static int getSessionTimeoutInSeconds(Settings settings) {
-    int minutes;
-    if (settings.hasKey(SESSION_TIMEOUT_IN_MINUTES_PROPERTY)) {
-      minutes = settings.getInt(SESSION_TIMEOUT_IN_MINUTES_PROPERTY);
-      checkArgument(minutes > 0, "Property %s must be strictly positive. Got %s", SESSION_TIMEOUT_IN_MINUTES_PROPERTY, minutes);
-    } else {
-      minutes = SESSION_TIMEOUT_DEFAULT_VALUE_IN_MINUTES;
-    }
+  private static int getSessionTimeoutInSeconds(Configuration config) {
+    int minutes = config.getInt(SESSION_TIMEOUT_IN_MINUTES_PROPERTY).orElse(SESSION_TIMEOUT_DEFAULT_VALUE_IN_MINUTES);
+    checkArgument(minutes > 0, "Property %s must be strictly positive. Got %s", SESSION_TIMEOUT_IN_MINUTES_PROPERTY, minutes);
     checkArgument(minutes <= MAX_SESSION_TIMEOUT_IN_MINUTES, "Property %s must not be greater than 3 months (%s minutes). Got %s minutes",
       SESSION_TIMEOUT_IN_MINUTES_PROPERTY, MAX_SESSION_TIMEOUT_IN_MINUTES, minutes);
     return minutes * 60;
index 8b2a628950817a91922347320760f916ae367ca9..477f4f59e89e4965afbd9fcc756123be176f6fed 100644 (file)
@@ -35,16 +35,16 @@ import javax.annotation.concurrent.Immutable;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
 import org.sonar.api.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.authentication.event.AuthenticationException;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static io.jsonwebtoken.impl.crypto.MacProvider.generateKey;
 import static java.util.Objects.requireNonNull;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 
 /**
  * This class can be used to encode or decode a JWT token
@@ -56,14 +56,14 @@ public class JwtSerializer implements Startable {
 
   private static final SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.HS256;
 
-  private final Settings settings;
+  private final Configuration config;
   private final System2 system2;
   private final UuidFactory uuidFactory;
 
   private SecretKey secretKey;
 
-  public JwtSerializer(Settings settings, System2 system2, UuidFactory uuidFactory) {
-    this.settings = settings;
+  public JwtSerializer(Configuration config, System2 system2, UuidFactory uuidFactory) {
+    this.config = config;
     this.system2 = system2;
     this.uuidFactory = uuidFactory;
   }
@@ -75,11 +75,11 @@ public class JwtSerializer implements Startable {
 
   @Override
   public void start() {
-    String encodedKey = settings.getString(SECRET_KEY_PROPERTY);
-    if (encodedKey == null) {
-      this.secretKey = generateSecretKey();
+    Optional<String> encodedKey = config.get(SECRET_KEY_PROPERTY);
+    if (encodedKey.isPresent()) {
+      this.secretKey = decodeSecretKeyProperty(encodedKey.get());
     } else {
-      this.secretKey = decodeSecretKeyProperty(encodedKey);
+      this.secretKey = generateSecretKey();
     }
   }
 
index ee6c90a02d83a69d9e2daac5ea7cf2e2477ac2c8..a7bf1c56d7af7bb46c0b7cfde5622a48f801108f 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Locale;
 import java.util.Optional;
 import javax.servlet.http.HttpServletRequest;
 import org.sonar.api.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.security.Authenticator;
 import org.sonar.api.security.ExternalGroupsProvider;
 import org.sonar.api.security.ExternalUsersProvider;
@@ -38,20 +38,20 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.authentication.event.AuthenticationException;
 import org.sonar.server.user.SecurityRealmFactory;
 
 import static java.util.Objects.requireNonNull;
 import static org.apache.commons.lang.StringUtils.isEmpty;
 import static org.apache.commons.lang.StringUtils.trimToNull;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY;
 
 public class RealmAuthenticator implements Startable {
 
   private static final Logger LOG = Loggers.get(RealmAuthenticator.class);
 
-  private final Settings settings;
+  private final Configuration config;
   private final SecurityRealmFactory securityRealmFactory;
   private final UserIdentityAuthenticator userIdentityAuthenticator;
   private final AuthenticationEvent authenticationEvent;
@@ -61,9 +61,9 @@ public class RealmAuthenticator implements Startable {
   private ExternalUsersProvider externalUsersProvider;
   private ExternalGroupsProvider externalGroupsProvider;
 
-  public RealmAuthenticator(Settings settings, SecurityRealmFactory securityRealmFactory,
+  public RealmAuthenticator(Configuration config, SecurityRealmFactory securityRealmFactory,
     UserIdentityAuthenticator userIdentityAuthenticator, AuthenticationEvent authenticationEvent) {
-    this.settings = settings;
+    this.config = config;
     this.securityRealmFactory = securityRealmFactory;
     this.userIdentityAuthenticator = userIdentityAuthenticator;
     this.authenticationEvent = authenticationEvent;
@@ -142,7 +142,7 @@ public class RealmAuthenticator implements Startable {
   }
 
   private String getLogin(String userLogin) {
-    if (settings.getBoolean("sonar.authenticator.downcase")) {
+    if (config.getBoolean("sonar.authenticator.downcase").orElse(false)) {
       return userLogin.toLowerCase(Locale.ENGLISH);
     }
     return userLogin;
index 16408ab1823c2fafd9f140d77c47bdc852a4b958..6859112cda68ff75353bb6aca94a81c330360cb7 100644 (file)
@@ -32,7 +32,7 @@ import javax.annotation.CheckForNull;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.sonar.api.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.authentication.Display;
 import org.sonar.api.server.authentication.IdentityProvider;
 import org.sonar.api.server.authentication.UserIdentity;
@@ -41,12 +41,11 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.authentication.event.AuthenticationException;
 import org.sonar.server.exceptions.BadRequestException;
 
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
 import static org.apache.commons.lang.time.DateUtils.addMinutes;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY;
 
 public class SsoAuthenticator implements Startable {
@@ -82,7 +81,7 @@ public class SsoAuthenticator implements Startable {
     REFRESH_INTERVAL_PARAM, REFRESH_INTERVAL_DEFAULT_VALUE);
 
   private final System2 system2;
-  private final Settings settings;
+  private final Configuration config;
   private final UserIdentityAuthenticator userIdentityAuthenticator;
   private final JwtHttpHandler jwtHttpHandler;
   private final AuthenticationEvent authenticationEvent;
@@ -90,10 +89,10 @@ public class SsoAuthenticator implements Startable {
   private boolean enabled = false;
   private Map<String, String> settingsByKey = new HashMap<>();
 
-  public SsoAuthenticator(System2 system2, Settings settings, UserIdentityAuthenticator userIdentityAuthenticator,
+  public SsoAuthenticator(System2 system2, Configuration config, UserIdentityAuthenticator userIdentityAuthenticator,
     JwtHttpHandler jwtHttpHandler, AuthenticationEvent authenticationEvent) {
     this.system2 = system2;
-    this.settings = settings;
+    this.config = config;
     this.userIdentityAuthenticator = userIdentityAuthenticator;
     this.jwtHttpHandler = jwtHttpHandler;
     this.authenticationEvent = authenticationEvent;
@@ -101,11 +100,11 @@ public class SsoAuthenticator implements Startable {
 
   @Override
   public void start() {
-    if (settings.getBoolean(ENABLE_PARAM)) {
+    if (config.getBoolean(ENABLE_PARAM).orElse(false)) {
       LOG.info("SSO Authentication enabled");
       enabled = true;
       DEFAULT_VALUES_BY_SETTING_KEYS.entrySet()
-        .forEach(entry -> settingsByKey.put(entry.getKey(), defaultIfBlank(settings.getString(entry.getKey()), DEFAULT_VALUES_BY_SETTING_KEYS.get(entry.getKey()))));
+        .forEach(entry -> settingsByKey.put(entry.getKey(), config.get(entry.getKey()).orElse(DEFAULT_VALUES_BY_SETTING_KEYS.get(entry.getKey()))));
     }
   }
 
index e86e6c80c65ff65e9aa7b22e1d8d62f2709008a2..4cedd53921903e5b743d82aadb4ae3ab789bef1a 100644 (file)
@@ -24,10 +24,13 @@ import java.util.Optional;
 import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
+import org.sonar.api.web.ServletFilter.UrlPattern;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Method;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.authentication.event.AuthenticationException;
 import org.sonar.server.user.ThreadLocalUserSession;
 import org.sonar.server.user.UserSession;
@@ -35,11 +38,8 @@ import org.sonar.server.user.UserSessionFactory;
 
 import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
 import static org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY;
-import static org.sonar.api.web.ServletFilter.UrlPattern;
 import static org.sonar.api.web.ServletFilter.UrlPattern.Builder.staticResourcePatterns;
 import static org.sonar.server.authentication.AuthenticationError.handleAuthenticationError;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Method;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.authentication.ws.LoginAction.LOGIN_URL;
 import static org.sonar.server.authentication.ws.LogoutAction.LOGOUT_URL;
 import static org.sonar.server.authentication.ws.ValidateAction.VALIDATE_URL;
@@ -70,7 +70,7 @@ public class UserSessionInitializer {
     .excludes(SKIPPED_URLS)
     .build();
 
-  private final Settings settings;
+  private final Configuration config;
   private final JwtHttpHandler jwtHttpHandler;
   private final BasicAuthenticator basicAuthenticator;
   private final SsoAuthenticator ssoAuthenticator;
@@ -78,10 +78,10 @@ public class UserSessionInitializer {
   private final AuthenticationEvent authenticationEvent;
   private final UserSessionFactory userSessionFactory;
 
-  public UserSessionInitializer(Settings settings, JwtHttpHandler jwtHttpHandler, BasicAuthenticator basicAuthenticator,
+  public UserSessionInitializer(Configuration config, JwtHttpHandler jwtHttpHandler, BasicAuthenticator basicAuthenticator,
     SsoAuthenticator ssoAuthenticator, ThreadLocalUserSession threadLocalSession, AuthenticationEvent authenticationEvent,
     UserSessionFactory userSessionFactory) {
-    this.settings = settings;
+    this.config = config;
     this.jwtHttpHandler = jwtHttpHandler;
     this.basicAuthenticator = basicAuthenticator;
     this.ssoAuthenticator = ssoAuthenticator;
@@ -127,7 +127,7 @@ public class UserSessionInitializer {
       threadLocalSession.set(session);
       request.setAttribute(ACCESS_LOG_LOGIN, session.getLogin());
     } else {
-      if (settings.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY)) {
+      if (config.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY).orElse(false)) {
         throw AuthenticationException.newBuilder()
           .setSource(Source.local(Method.BASIC))
           .setMessage("User must be authenticated")
index ec0b424c5dba1f2bfb355c8490814ff013ff83a8..1e273d7351e3faa5c8071ea9c7b56d366fe5183f 100644 (file)
@@ -29,7 +29,7 @@ import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.ServletFilter;
@@ -48,12 +48,12 @@ public class ValidateAction extends ServletFilter implements AuthenticationWsAct
   private static final String VALIDATE_ACTION = "validate";
   public static final String VALIDATE_URL = "/" + AUTHENTICATION_CONTROLLER + "/" + VALIDATE_ACTION;
 
-  private final Settings settings;
+  private final Configuration config;
   private final JwtHttpHandler jwtHttpHandler;
   private final BasicAuthenticator basicAuthenticator;
 
-  public ValidateAction(Settings settings, BasicAuthenticator basicAuthenticator, JwtHttpHandler jwtHttpHandler) {
-    this.settings = settings;
+  public ValidateAction(Configuration config, BasicAuthenticator basicAuthenticator, JwtHttpHandler jwtHttpHandler) {
+    this.config = config;
     this.basicAuthenticator = basicAuthenticator;
     this.jwtHttpHandler = jwtHttpHandler;
   }
@@ -97,7 +97,7 @@ public class ValidateAction extends ServletFilter implements AuthenticationWsAct
       if (user.isPresent()) {
         return true;
       }
-      return !settings.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY);
+      return !config.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY).orElse(false);
     } catch (AuthenticationException e) {
       return false;
     }
index e2d3f0cb3a063f8ebadae46cb94b0ee71094c44d..8226567c96ee74904b52a54d0754c9205cc435d3 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.component.index;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.DefaultIndexSettingsElement;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
@@ -42,17 +42,17 @@ public class ComponentIndexDefinition implements IndexDefinition {
 
   static final DefaultIndexSettingsElement[] NAME_ANALYZERS = {SORTABLE_ANALYZER, SEARCH_PREFIX_ANALYZER, SEARCH_PREFIX_CASE_INSENSITIVE_ANALYZER, SEARCH_GRAMS_ANALYZER};
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public ComponentIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public ComponentIndexDefinition(Configuration config) {
+    this.config = config;
   }
 
   @Override
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX_TYPE_COMPONENT.getIndex());
     index.refreshHandledByIndexer();
-    index.configureShards(settings, DEFAULT_NUMBER_OF_SHARDS);
+    index.configureShards(config, DEFAULT_NUMBER_OF_SHARDS);
 
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_COMPONENT.getType())
       .requireProjectAuthorization();
index 8ce11e2c38c99f60686ef1ea9225a37536f1fcce..d2969f7c8409be81eedb95d6412f163cb349b6cd 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.computation.dbcleaner;
 import java.util.Collection;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.TimeUtils;
 import org.sonar.api.utils.log.Logger;
@@ -54,22 +54,22 @@ public class ProjectCleaner {
     this.purgeListener = purgeListener;
   }
 
-  public ProjectCleaner purge(DbSession session, IdUuidPair idUuidPair, Settings projectSettings, Collection<String> disabledComponentUuids) {
+  public ProjectCleaner purge(DbSession session, IdUuidPair idUuidPair, Configuration projectConfig, Collection<String> disabledComponentUuids) {
     long start = System.currentTimeMillis();
     profiler.reset();
 
-    PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectSettings, idUuidPair, disabledComponentUuids);
+    PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, idUuidPair, disabledComponentUuids);
 
-    cleanHistoricalData(session, configuration.rootProjectIdUuid().getUuid(), projectSettings);
+    cleanHistoricalData(session, configuration.rootProjectIdUuid().getUuid(), projectConfig);
     doPurge(session, configuration);
 
     session.commit();
-    logProfiling(start, projectSettings);
+    logProfiling(start, projectConfig);
     return this;
   }
 
-  private void logProfiling(long start, Settings settings) {
-    if (settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
+  private void logProfiling(long start, Configuration config) {
+    if (config.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY).orElse(false)) {
       long duration = System.currentTimeMillis() - start;
       LOG.info("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n");
       profiler.dump(duration, LOG);
@@ -77,9 +77,9 @@ public class ProjectCleaner {
     }
   }
 
-  private void cleanHistoricalData(DbSession session, String rootUuid, Settings settings) {
+  private void cleanHistoricalData(DbSession session, String rootUuid, Configuration config) {
     try {
-      periodCleaner.clean(session, rootUuid, settings);
+      periodCleaner.clean(session, rootUuid, config);
     } catch (Exception e) {
       // purge errors must no fail the batch
       LOG.error("Fail to clean historical data [uuid=" + rootUuid + "]", e);
index c9ea8198b7c6409ee1ea4cb94324d238f6380006..e2a3371186059d57aa755478e5f2322dddc5ac76 100644 (file)
@@ -32,22 +32,23 @@ import javax.annotation.Nullable;
 import org.sonar.api.ce.measure.Component;
 import org.sonar.api.ce.measure.Issue;
 import org.sonar.api.ce.measure.Measure;
+import org.sonar.api.ce.measure.MeasureComputer.MeasureComputerContext;
+import org.sonar.api.ce.measure.MeasureComputer.MeasureComputerDefinition;
 import org.sonar.api.ce.measure.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.sonar.api.ce.measure.MeasureComputer.MeasureComputerContext;
-import static org.sonar.api.ce.measure.MeasureComputer.MeasureComputerDefinition;
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 
 public class MeasureComputerContextImpl implements MeasureComputerContext {
 
-  private final SettingsRepository settings;
+  private final ConfigurationRepository config;
   private final MeasureRepository measureRepository;
   private final MetricRepository metricRepository;
 
@@ -58,9 +59,9 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
   private MeasureComputerDefinition definition;
   private Set<String> allowedMetrics;
 
-  public MeasureComputerContextImpl(org.sonar.server.computation.task.projectanalysis.component.Component component, SettingsRepository settings,
+  public MeasureComputerContextImpl(org.sonar.server.computation.task.projectanalysis.component.Component component, ConfigurationRepository config,
     MeasureRepository measureRepository, MetricRepository metricRepository, ComponentIssuesRepository componentIssuesRepository) {
-    this.settings = settings;
+    this.config = config;
     this.internalComponent = component;
     this.measureRepository = measureRepository;
     this.metricRepository = metricRepository;
@@ -96,7 +97,7 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
       @Override
       @CheckForNull
       public String getString(String key) {
-        return getComponentSettings().getString(key);
+        return getComponentSettings().get(key).orElse(null);
       }
 
       @Override
@@ -106,8 +107,8 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
     };
   }
 
-  private org.sonar.api.config.Settings getComponentSettings() {
-    return settings.getSettings(internalComponent);
+  private Configuration getComponentSettings() {
+    return config.getConfiguration(internalComponent);
   }
 
   @Override
@@ -187,11 +188,12 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
       component.getKey(),
       Component.Type.valueOf(component.getType().name()),
       component.getType() == org.sonar.server.computation.task.projectanalysis.component.Component.Type.FILE
-        ? new ComponentImpl.FileAttributesImpl(component.getFileAttributes().getLanguageKey(), component.getFileAttributes().isUnitTest()) : null);
+        ? new ComponentImpl.FileAttributesImpl(component.getFileAttributes().getLanguageKey(), component.getFileAttributes().isUnitTest())
+        : null);
   }
 
-  private class ComponentToMeasure implements Function<org.sonar.server.computation.task.projectanalysis.component.Component,
-      Optional<org.sonar.server.computation.task.projectanalysis.measure.Measure>> {
+  private class ComponentToMeasure
+    implements Function<org.sonar.server.computation.task.projectanalysis.component.Component, Optional<org.sonar.server.computation.task.projectanalysis.measure.Measure>> {
 
     private final Metric metric;
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepository.java
new file mode 100644 (file)
index 0000000..1dd33a4
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.component;
+
+import org.sonar.api.config.Configuration;
+
+/**
+ * Repository of component settings.
+ */
+public interface ConfigurationRepository {
+  /**
+   * Returns the configuration for the specified Component.
+   */
+  Configuration getConfiguration(Component component);
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java
new file mode 100644 (file)
index 0000000..80489e4
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.component;
+
+import java.util.Collection;
+import java.util.Map;
+import org.sonar.api.config.Configuration;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
+import org.sonar.server.util.cache.CacheLoader;
+import org.sonar.server.util.cache.MemoryCache;
+
+/**
+ * Repository of component settings implementation based on a memory cache.
+ */
+public class ConfigurationRepositoryImpl implements ConfigurationRepository {
+
+  private final ProjectConfigurationFactory projectConfigurationFactory;
+  private final MemoryCache<String, Configuration> cache = new MemoryCache<>(new CacheLoader<String, Configuration>() {
+    @Override
+    public Configuration load(String key) {
+      return projectConfigurationFactory.newProjectConfiguration(key);
+    }
+
+    @Override
+    public Map<String, Configuration> loadAll(Collection<? extends String> keys) {
+      throw new UnsupportedOperationException("loadAll is not supported");
+    }
+  });
+
+  public ConfigurationRepositoryImpl(ProjectConfigurationFactory projectSettingsFactory) {
+    this.projectConfigurationFactory = projectSettingsFactory;
+  }
+
+  @Override
+  public Configuration getConfiguration(Component component) {
+    return cache.get(component.getKey());
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepository.java
deleted file mode 100644 (file)
index de4b4ca..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.component;
-
-import org.sonar.api.config.Settings;
-
-/**
- * Repository of component settings.
- */
-public interface SettingsRepository {
-  /**
-   * Returns the settings for the specified Component.
-   */
-  Settings getSettings(Component component);
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryImpl.java
deleted file mode 100644 (file)
index f56f4da..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.component;
-
-import java.util.Collection;
-import java.util.Map;
-import org.sonar.api.config.Settings;
-import org.sonar.ce.settings.ProjectSettingsFactory;
-import org.sonar.server.util.cache.CacheLoader;
-import org.sonar.server.util.cache.MemoryCache;
-
-/**
- * Repository of component settings implementation based on a memory cache.
- */
-public class SettingsRepositoryImpl implements SettingsRepository {
-
-  private final ProjectSettingsFactory projectSettingsFactory;
-  private final MemoryCache<String, Settings> cache = new MemoryCache<>(new CacheLoader<String, Settings>() {
-    @Override
-    public Settings load(String key) {
-      return projectSettingsFactory.newProjectSettings(key);
-    }
-
-    @Override
-    public Map<String, Settings> loadAll(Collection<? extends String> keys) {
-      throw new UnsupportedOperationException("loadAll is not supported");
-    }
-  });
-
-  public SettingsRepositoryImpl(ProjectSettingsFactory projectSettingsFactory) {
-    this.projectSettingsFactory = projectSettingsFactory;
-  }
-
-  @Override
-  public Settings getSettings(Component component){
-    return cache.get(component.getKey());
-  }
-
-}
index 2b7096ffad586816fa1183d5c117b30ff97fe618..c6fcc5d22d9c06651e72abf10261d271ed8cde41 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.server.computation.task.projectanalysis.batch.BatchReportDirect
 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderImpl;
 import org.sonar.server.computation.task.projectanalysis.component.DbIdsRepositoryImpl;
 import org.sonar.server.computation.task.projectanalysis.component.DisabledComponentsHolderImpl;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepositoryImpl;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepositoryImpl;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderImpl;
 import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolderImpl;
 import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryImpl;
@@ -166,7 +166,7 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop
       LanguageRepositoryImpl.class,
       MeasureRepositoryImpl.class,
       EventRepositoryImpl.class,
-      SettingsRepositoryImpl.class,
+      ConfigurationRepositoryImpl.class,
       DbIdsRepositoryImpl.class,
       DisabledComponentsHolderImpl.class,
       QualityGateServiceImpl.class,
index 0124c12c947e9bae929479c9aa24e5a8c7f73f7a..dde79aa7c1603caea3fd31b1ee1458f80d237eda 100644 (file)
@@ -27,7 +27,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.duplications.block.Block;
@@ -52,13 +52,13 @@ public class IntegrateCrossProjectDuplications {
   private static final int MAX_CLONE_GROUP_PER_FILE = 100;
   private static final int MAX_CLONE_PART_PER_GROUP = 100;
 
-  private final Settings settings;
+  private final Configuration config;
   private final DuplicationRepository duplicationRepository;
 
   private Map<String, NumberOfUnitsNotLessThan> numberOfUnitsByLanguage = new HashMap<>();
 
-  public IntegrateCrossProjectDuplications(Settings settings, DuplicationRepository duplicationRepository) {
-    this.settings = settings;
+  public IntegrateCrossProjectDuplications(Configuration config, DuplicationRepository duplicationRepository) {
+    this.config = config;
     this.duplicationRepository = duplicationRepository;
   }
 
@@ -96,8 +96,7 @@ public class IntegrateCrossProjectDuplications {
     if (!Iterables.isEmpty(duplicates)) {
       duplicationRepository.add(
         file,
-        new Duplication(new TextBlock(originPart.getStartLine(), originPart.getEndLine()), duplicates)
-        );
+        new Duplication(new TextBlock(originPart.getStartLine(), originPart.getEndLine()), duplicates));
     }
   }
 
@@ -123,11 +122,7 @@ public class IntegrateCrossProjectDuplications {
     if (languageKey.equalsIgnoreCase(JAVA_KEY)) {
       return 0;
     }
-    int minimumTokens = settings.getInt("sonar.cpd." + languageKey + ".minimumTokens");
-    if (minimumTokens == 0) {
-      return 100;
-    }
-    return minimumTokens;
+    return config.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
   }
 
   private static class NumberOfUnitsNotLessThan implements Predicate<CloneGroup> {
index eeebe0c86e8116df492898b3c31eae79d0f18f0b..9fccec304427fe13b01563c88d57014fc4cde942 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 
 import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
@@ -42,16 +42,16 @@ public class DefaultAssignee {
 
   private final DbClient dbClient;
   private final TreeRootHolder treeRootHolder;
-  private final SettingsRepository settingsRepository;
+  private final ConfigurationRepository configRepository;
   private final AnalysisMetadataHolder analysisMetadataHolder;
 
   private boolean loaded = false;
   private String login = null;
 
-  public DefaultAssignee(DbClient dbClient, TreeRootHolder treeRootHolder, SettingsRepository settingsRepository, AnalysisMetadataHolder analysisMetadataHolder) {
+  public DefaultAssignee(DbClient dbClient, TreeRootHolder treeRootHolder, ConfigurationRepository configRepository, AnalysisMetadataHolder analysisMetadataHolder) {
     this.dbClient = dbClient;
     this.treeRootHolder = treeRootHolder;
-    this.settingsRepository = settingsRepository;
+    this.configRepository = configRepository;
     this.analysisMetadataHolder = analysisMetadataHolder;
   }
 
@@ -60,7 +60,7 @@ public class DefaultAssignee {
     if (loaded) {
       return login;
     }
-    String configuredLogin = settingsRepository.getSettings(treeRootHolder.getRoot()).getString(DEFAULT_ISSUE_ASSIGNEE);
+    String configuredLogin = configRepository.getConfiguration(treeRootHolder.getRoot()).get(DEFAULT_ISSUE_ASSIGNEE).orElse(null);
     if (!Strings.isNullOrEmpty(configuredLogin) && isValidLogin(configuredLogin)) {
       this.login = configuredLogin;
     }
index 5b3eb5d2b1a2a0f88edadf89d6df5369964392d9..d45d0338b3befc763c13cabfd0f83c2d8f9d9bb5 100644 (file)
@@ -24,18 +24,17 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static java.lang.String.format;
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
 import static org.sonar.core.config.IssueExclusionProperties.PATTERNS_MULTICRITERIA_EXCLUSION_KEY;
 import static org.sonar.core.config.IssueExclusionProperties.PATTERNS_MULTICRITERIA_INCLUSION_KEY;
 import static org.sonar.core.config.IssueExclusionProperties.RESOURCE_KEY;
@@ -50,10 +49,10 @@ public class IssueFilter {
   private final List<IssuePattern> exclusionPatterns;
   private final List<IssuePattern> inclusionPatterns;
 
-  public IssueFilter(TreeRootHolder treeRootHolder, SettingsRepository settingsRepository) {
-    Settings settings = settingsRepository.getSettings(treeRootHolder.getRoot());
-    this.exclusionPatterns = loadPatterns(PATTERNS_MULTICRITERIA_EXCLUSION_KEY, settings);
-    this.inclusionPatterns = loadPatterns(PATTERNS_MULTICRITERIA_INCLUSION_KEY, settings);
+  public IssueFilter(TreeRootHolder treeRootHolder, ConfigurationRepository configRepository) {
+    Configuration config = configRepository.getConfiguration(treeRootHolder.getRoot());
+    this.exclusionPatterns = loadPatterns(PATTERNS_MULTICRITERIA_EXCLUSION_KEY, config);
+    this.inclusionPatterns = loadPatterns(PATTERNS_MULTICRITERIA_INCLUSION_KEY, config);
   }
 
   public boolean accept(DefaultIssue issue, Component component) {
@@ -108,14 +107,14 @@ public class IssueFilter {
     }
   }
 
-  private static List<IssuePattern> loadPatterns(String propertyKey, Settings settings) {
+  private static List<IssuePattern> loadPatterns(String propertyKey, Configuration settings) {
     List<IssuePattern> patterns = new ArrayList<>();
-    String patternConf = defaultIfBlank(settings.getString(propertyKey), "");
+    String patternConf = settings.get(propertyKey).orElse("");
     for (String id : Splitter.on(",").omitEmptyStrings().split(patternConf)) {
       String propPrefix = propertyKey + "." + id + ".";
-      String componentPathPattern = settings.getString(propPrefix + RESOURCE_KEY);
+      String componentPathPattern = settings.get(propPrefix + RESOURCE_KEY).orElse(null);
       checkArgument(!isNullOrEmpty(componentPathPattern), format("File path pattern cannot be empty. Please check '%s' settings", propertyKey));
-      String ruleKeyPattern = settings.getString(propPrefix + RULE_KEY);
+      String ruleKeyPattern = settings.get(propPrefix + RULE_KEY).orElse(null);
       checkArgument(!isNullOrEmpty(ruleKeyPattern), format("Rule key pattern cannot be empty. Please check '%s' settings", propertyKey));
       patterns.add(new IssuePattern(componentPathPattern, ruleKeyPattern));
     }
index 92a4d820fdb47980e2e0b95198cb6bd75c1d4b61..5b571ee48e7b87cade0aa62bb26f4343971e4222 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.ce.measure.MeasureComputer;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository;
 import org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl;
@@ -40,12 +40,12 @@ public class MeasureComputersVisitor extends TypeAwareVisitorAdapter {
 
   private final MetricRepository metricRepository;
   private final MeasureRepository measureRepository;
-  private final SettingsRepository settings;
+  private final ConfigurationRepository settings;
 
   private final MeasureComputersHolder measureComputersHolder;
   private final ComponentIssuesRepository componentIssuesRepository;
 
-  public MeasureComputersVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, SettingsRepository settings,
+  public MeasureComputersVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, ConfigurationRepository settings,
     MeasureComputersHolder measureComputersHolder, ComponentIssuesRepository componentIssuesRepository) {
     super(CrawlerDepthLimit.reportMaxDepth(FILE).withViewsMaxDepth(SUBVIEW), POST_ORDER);
     this.metricRepository = metricRepository;
index 91f7509166ec9d6e70bd5be18b30dfbadc87e812..cf128cf218877fddcf10854682b2fb419769d5d0 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.MessageException;
 
 import static java.lang.String.format;
@@ -38,32 +38,30 @@ import static org.sonar.api.CoreProperties.RATING_GRID_DEF_VALUES;
 
 public class RatingSettings {
 
-  private final Settings settings;
+  private final Configuration config;
   private final Map<String, LanguageSpecificConfiguration> languageSpecificConfigurationByLanguageKey;
 
-  public RatingSettings(Settings settings) {
-    this.settings = settings;
-    this.languageSpecificConfigurationByLanguageKey = buildLanguageSpecificConfigurationByLanguageKey(settings);
+  public RatingSettings(Configuration config) {
+    this.config = config;
+    this.languageSpecificConfigurationByLanguageKey = buildLanguageSpecificConfigurationByLanguageKey(config);
   }
 
-  private static Map<String, LanguageSpecificConfiguration> buildLanguageSpecificConfigurationByLanguageKey(Settings settings) {
+  private static Map<String, LanguageSpecificConfiguration> buildLanguageSpecificConfigurationByLanguageKey(Configuration config) {
     ImmutableMap.Builder<String, LanguageSpecificConfiguration> builder = ImmutableMap.builder();
-    String[] languageConfigIndexes = settings.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS);
+    String[] languageConfigIndexes = config.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS);
     for (String languageConfigIndex : languageConfigIndexes) {
       String languagePropertyKey = LANGUAGE_SPECIFIC_PARAMETERS + "." + languageConfigIndex + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY;
-      String languageKey = settings.getString(languagePropertyKey);
-      if (languageKey == null) {
-        throw MessageException.of("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " +
-          "Contact your administrator to update this configuration in the global administration section of SonarQube.");
-      }
-      builder.put(languageKey, LanguageSpecificConfiguration.create(settings, languageConfigIndex));
+      String languageKey = config.get(languagePropertyKey)
+        .orElseThrow(() -> MessageException.of("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " +
+          "Contact your administrator to update this configuration in the global administration section of SonarQube."));
+      builder.put(languageKey, LanguageSpecificConfiguration.create(config, languageConfigIndex));
     }
     return builder.build();
   }
 
   public RatingGrid getRatingGrid() {
     try {
-      String[] ratingGrades = settings.getStringArray(RATING_GRID);
+      String[] ratingGrades = config.getStringArray(RATING_GRID);
       double[] grid = new double[4];
       for (int i = 0; i < 4; i++) {
         grid[i] = Double.parseDouble(ratingGrades[i]);
@@ -72,7 +70,7 @@ public class RatingSettings {
     } catch (Exception e) {
       throw new IllegalArgumentException("The rating grid is incorrect. Expected something similar to '"
         + RATING_GRID_DEF_VALUES + "' and got '"
-        + settings.getString(RATING_GRID) + "'", e);
+        + config.get(RATING_GRID).get() + "'", e);
     }
   }
 
@@ -93,10 +91,10 @@ public class RatingSettings {
 
   private long getDefaultDevelopmentCost() {
     try {
-      return Long.parseLong(settings.getString(DEVELOPMENT_COST));
+      return Long.parseLong(config.get(DEVELOPMENT_COST).get());
     } catch (NumberFormatException e) {
       throw new IllegalArgumentException("The value of the development cost property '" + DEVELOPMENT_COST
-        + "' is incorrect. Expected long but got '" + settings.getString(DEVELOPMENT_COST) + "'", e);
+        + "' is incorrect. Expected long but got '" + config.get(DEVELOPMENT_COST).get() + "'", e);
     }
   }
 
@@ -117,13 +115,13 @@ public class RatingSettings {
       this.metricKey = metricKey;
     }
 
-    static LanguageSpecificConfiguration create(Settings settings, String configurationId) {
+    static LanguageSpecificConfiguration create(Configuration config, String configurationId) {
 
       String configurationPrefix = LANGUAGE_SPECIFIC_PARAMETERS + "." + configurationId + ".";
 
-      String language = settings.getString(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY);
-      String manDays = settings.getString(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY);
-      String metric = settings.getString(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY);
+      String language = config.get(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY).orElse(null);
+      String manDays = config.get(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY).orElse(null);
+      String metric = config.get(configurationPrefix + LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY).orElse(null);
 
       return new LanguageSpecificConfiguration(language, manDays, metric);
     }
index 75e40591c3c3f54975738121ee39263f51f996a8..be93f8fd7803d40cb4887d725dda5056c6e19ca5 100644 (file)
@@ -21,14 +21,14 @@ package org.sonar.server.computation.task.projectanalysis.step;
 
 import com.google.common.base.Optional;
 import javax.annotation.CheckForNull;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
@@ -52,15 +52,15 @@ import static org.sonar.server.computation.task.projectanalysis.component.Crawle
 public class LoadPeriodsStep implements ComputationStep {
 
   private final DbClient dbClient;
-  private final SettingsRepository settingsRepository;
+  private final ConfigurationRepository configRepository;
   private final TreeRootHolder treeRootHolder;
   private final AnalysisMetadataHolder analysisMetadataHolder;
   private final PeriodHolderImpl periodsHolder;
 
-  public LoadPeriodsStep(DbClient dbClient, SettingsRepository settingsRepository, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder,
+  public LoadPeriodsStep(DbClient dbClient, ConfigurationRepository settingsRepository, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder,
     PeriodHolderImpl periodsHolder) {
     this.dbClient = dbClient;
-    this.settingsRepository = settingsRepository;
+    this.configRepository = settingsRepository;
     this.treeRootHolder = treeRootHolder;
     this.analysisMetadataHolder = analysisMetadataHolder;
     this.periodsHolder = periodsHolder;
@@ -100,8 +100,8 @@ public class LoadPeriodsStep implements ComputationStep {
     PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(),
       isReportType ? projectOrView.getReportAttributes().getVersion() : null);
 
-    Settings settings = settingsRepository.getSettings(projectOrView);
-    Period period = periodResolver.resolve(settings);
+    Configuration config = configRepository.getConfiguration(projectOrView);
+    Period period = periodResolver.resolve(config);
     // SONAR-4700 Add a past snapshot only if it exists
     if (period != null) {
       return period;
index 1417de24f8bc8d67a5286a5d626afc740e3494cf..ca1d5588d54fca78720860270328d4d307eef539 100644 (file)
@@ -21,13 +21,13 @@ package org.sonar.server.computation.task.projectanalysis.step;
 
 import com.google.common.base.Optional;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
 import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
 import org.sonar.server.computation.task.projectanalysis.qualitygate.MutableQualityGateHolder;
@@ -47,14 +47,14 @@ public class LoadQualityGateStep implements ComputationStep {
   private static final String PROPERTY_QUALITY_GATE = "sonar.qualitygate";
 
   private final TreeRootHolder treeRootHolder;
-  private final SettingsRepository settingsRepository;
+  private final ConfigurationRepository configRepository;
   private final QualityGateService qualityGateService;
   private final MutableQualityGateHolder qualityGateHolder;
 
-  public LoadQualityGateStep(TreeRootHolder treeRootHolder, SettingsRepository settingsRepository,
-                             QualityGateService qualityGateService, MutableQualityGateHolder qualityGateHolder) {
+  public LoadQualityGateStep(TreeRootHolder treeRootHolder, ConfigurationRepository settingsRepository,
+    QualityGateService qualityGateService, MutableQualityGateHolder qualityGateHolder) {
     this.treeRootHolder = treeRootHolder;
-    this.settingsRepository = settingsRepository;
+    this.configRepository = settingsRepository;
     this.qualityGateService = qualityGateService;
     this.qualityGateHolder = qualityGateHolder;
   }
@@ -72,10 +72,10 @@ public class LoadQualityGateStep implements ComputationStep {
 
   private void executeForProject(Component project) {
     String projectKey = project.getKey();
-    Settings settings = settingsRepository.getSettings(project);
-    String qualityGateSetting = settings.getString(PROPERTY_QUALITY_GATE);
+    Configuration config = configRepository.getConfiguration(project);
+    String qualityGateSetting = config.get(PROPERTY_QUALITY_GATE).orElse(null);
 
-    if (qualityGateSetting == null || StringUtils.isBlank(qualityGateSetting)) {
+    if (StringUtils.isBlank(qualityGateSetting)) {
       LOGGER.debug("No quality gate is configured for project " + projectKey);
       qualityGateHolder.setNoQualityGate();
       return;
index 3ea2fe10647017795eeb7fc5a210754338c9a68c..7a21affa5ac9e444b9316e0023ac0487b15de178 100644 (file)
@@ -25,7 +25,7 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -65,8 +65,8 @@ public class PeriodResolver {
   }
 
   @CheckForNull
-  public Period resolve(Settings settings) {
-    String propertyValue = getPropertyValue(settings);
+  public Period resolve(Configuration config) {
+    String propertyValue = getPropertyValue(config);
     if (StringUtils.isBlank(propertyValue)) {
       return null;
     }
@@ -207,7 +207,7 @@ public class PeriodResolver {
     return DateUtils.formatDate(Date.from(new Date(date).toInstant().truncatedTo(ChronoUnit.SECONDS)));
   }
 
-  private static String getPropertyValue(Settings settings) {
-    return settings.getString(LEAK_PERIOD);
+  private static String getPropertyValue(Configuration config) {
+    return config.get(LEAK_PERIOD).get();
   }
 }
index f260563094c713941cd286199526d2bbd3cae6ae..677689f58a462406d1496edd82a9edfe697ec4a7 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.DbIdsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
 import org.sonar.server.computation.task.projectanalysis.component.DisabledComponentsHolder;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
 import org.sonar.server.computation.dbcleaner.ProjectCleaner;
@@ -43,16 +43,16 @@ public class PurgeDatastoresStep implements ComputationStep {
   private final DbClient dbClient;
   private final DbIdsRepository dbIdsRepository;
   private final TreeRootHolder treeRootHolder;
-  private final SettingsRepository settingsRepository;
+  private final ConfigurationRepository configRepository;
   private final DisabledComponentsHolder disabledComponentsHolder;
 
   public PurgeDatastoresStep(DbClient dbClient, ProjectCleaner projectCleaner, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder,
-    SettingsRepository settingsRepository, DisabledComponentsHolder disabledComponentsHolder) {
+    ConfigurationRepository configRepository, DisabledComponentsHolder disabledComponentsHolder) {
     this.projectCleaner = projectCleaner;
     this.dbClient = dbClient;
     this.dbIdsRepository = dbIdsRepository;
     this.treeRootHolder = treeRootHolder;
-    this.settingsRepository = settingsRepository;
+    this.configRepository = configRepository;
     this.disabledComponentsHolder = disabledComponentsHolder;
   }
 
@@ -75,7 +75,7 @@ public class PurgeDatastoresStep implements ComputationStep {
   private void execute(Component root) {
     try (DbSession dbSession = dbClient.openSession(true)) {
       IdUuidPair idUuidPair = new IdUuidPair(dbIdsRepository.getComponentId(root), root.getUuid());
-      projectCleaner.purge(dbSession, idUuidPair, settingsRepository.getSettings(root), disabledComponentsHolder.getUuids());
+      projectCleaner.purge(dbSession, idUuidPair, configRepository.getConfiguration(root), disabledComponentsHolder.getUuids());
       dbSession.commit();
     }
   }
index 6baef99868a5197ef20da5011060661385526f56..c66de9fd3ae68bf8c6f44e1c617cc02e8db930a1 100644 (file)
@@ -24,12 +24,12 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
 import org.sonar.api.ce.posttask.PostProjectAnalysisTask;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.config.WebhookProperties;
 import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 
 import static java.lang.String.format;
@@ -40,15 +40,15 @@ public class WebhookPostTask implements PostProjectAnalysisTask {
   private static final Logger LOGGER = Loggers.get(WebhookPostTask.class);
 
   private final TreeRootHolder rootHolder;
-  private final SettingsRepository settingsRepository;
+  private final ConfigurationRepository configRepository;
   private final WebhookPayloadFactory payloadFactory;
   private final WebhookCaller caller;
   private final WebhookDeliveryStorage deliveryStorage;
 
-  public WebhookPostTask(TreeRootHolder rootHolder, SettingsRepository settingsRepository, WebhookPayloadFactory payloadFactory,
+  public WebhookPostTask(TreeRootHolder rootHolder, ConfigurationRepository settingsRepository, WebhookPayloadFactory payloadFactory,
     WebhookCaller caller, WebhookDeliveryStorage deliveryStorage) {
     this.rootHolder = rootHolder;
-    this.settingsRepository = settingsRepository;
+    this.configRepository = settingsRepository;
     this.payloadFactory = payloadFactory;
     this.caller = caller;
     this.deliveryStorage = deliveryStorage;
@@ -56,30 +56,30 @@ public class WebhookPostTask implements PostProjectAnalysisTask {
 
   @Override
   public void finished(ProjectAnalysis analysis) {
-    Settings settings = settingsRepository.getSettings(rootHolder.getRoot());
+    Configuration config = configRepository.getConfiguration(rootHolder.getRoot());
 
     Iterable<String> webhookProps = Iterables.concat(
-      getWebhookProperties(settings, WebhookProperties.GLOBAL_KEY),
-      getWebhookProperties(settings, WebhookProperties.PROJECT_KEY));
+      getWebhookProperties(config, WebhookProperties.GLOBAL_KEY),
+      getWebhookProperties(config, WebhookProperties.PROJECT_KEY));
     if (!Iterables.isEmpty(webhookProps)) {
-      process(settings, analysis, webhookProps);
+      process(config, analysis, webhookProps);
       deliveryStorage.purge(analysis.getProject().getUuid());
     }
   }
 
-  private static List<String> getWebhookProperties(Settings settings, String propertyKey) {
-    String[] webhookIds = settings.getStringArray(propertyKey);
+  private static List<String> getWebhookProperties(Configuration config, String propertyKey) {
+    String[] webhookIds = config.getStringArray(propertyKey);
     return Arrays.stream(webhookIds)
       .map(webhookId -> format("%s.%s", propertyKey, webhookId))
       .limit(MAX_WEBHOOKS_PER_TYPE)
       .collect(MoreCollectors.toList(webhookIds.length));
   }
 
-  private void process(Settings settings, ProjectAnalysis analysis, Iterable<String> webhookProperties) {
+  private void process(Configuration config, ProjectAnalysis analysis, Iterable<String> webhookProperties) {
     WebhookPayload payload = payloadFactory.create(analysis);
     for (String webhookProp : webhookProperties) {
-      String name = settings.getString(format("%s.%s", webhookProp, WebhookProperties.NAME_FIELD));
-      String url = settings.getString(format("%s.%s", webhookProp, WebhookProperties.URL_FIELD));
+      String name = config.get(format("%s.%s", webhookProp, WebhookProperties.NAME_FIELD)).orElse(null);
+      String url = config.get(format("%s.%s", webhookProp, WebhookProperties.URL_FIELD)).orElse(null);
       // as webhooks are defined as property sets, we can't ensure validity of fields on creation.
       if (name != null && url != null) {
         Webhook webhook = new Webhook(analysis.getProject().getUuid(), analysis.getCeTask().getId(), name, url);
index 2712e89b639f05c16d788eac424893833573b69c..d4259c676598af9ffb34d7c1462306244466ac36 100644 (file)
@@ -29,7 +29,7 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.elasticsearch.common.transport.TransportAddress;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -43,25 +43,25 @@ public class EsClientProvider extends ProviderAdapter {
 
   private EsClient cache;
 
-  public EsClient provide(Settings settings) {
+  public EsClient provide(Configuration config) {
     if (cache == null) {
       TransportClient nativeClient;
       org.elasticsearch.common.settings.Settings.Builder esSettings = org.elasticsearch.common.settings.Settings.builder();
 
       // mandatory property defined by bootstrap process
-      esSettings.put("cluster.name", settings.getString(ProcessProperties.CLUSTER_NAME));
+      esSettings.put("cluster.name", config.get(ProcessProperties.CLUSTER_NAME).get());
 
-      boolean clusterEnabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
-      if (clusterEnabled && settings.getBoolean(ProcessProperties.CLUSTER_SEARCH_DISABLED)) {
+      boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+      if (clusterEnabled && config.getBoolean(ProcessProperties.CLUSTER_SEARCH_DISABLED).orElse(false)) {
         esSettings.put("client.transport.sniff", true);
         nativeClient = TransportClient.builder().settings(esSettings).build();
-        Arrays.stream(settings.getStringArray(ProcessProperties.CLUSTER_SEARCH_HOSTS))
+        Arrays.stream(config.getStringArray(ProcessProperties.CLUSTER_SEARCH_HOSTS))
           .map(HostAndPort::fromString)
           .forEach(h -> addHostToClient(h, nativeClient));
         LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
       } else {
         nativeClient = TransportClient.builder().settings(esSettings).build();
-        HostAndPort host = HostAndPort.fromParts(settings.getString(ProcessProperties.SEARCH_HOST), settings.getInt(ProcessProperties.SEARCH_PORT));
+        HostAndPort host = HostAndPort.fromParts(config.get(ProcessProperties.SEARCH_HOST).get(), config.getInt(ProcessProperties.SEARCH_PORT).get());
         addHostToClient(host, nativeClient);
         LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
       }
index b1490a4338f3021e47742c655ce233c5f521f1b0..2774983adc474d314e45fb13e7e0971db42d517f 100644 (file)
@@ -24,6 +24,7 @@ import com.google.common.collect.Maps;
 import java.util.Map;
 import org.elasticsearch.common.settings.Settings;
 import org.picocontainer.Startable;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 
 /**
@@ -87,11 +88,11 @@ public class IndexDefinitions implements Startable {
 
   private final Map<String, Index> byKey = Maps.newHashMap();
   private final IndexDefinition[] defs;
-  private final org.sonar.api.config.Settings settings;
+  private final Configuration config;
 
-  public IndexDefinitions(IndexDefinition[] defs, org.sonar.api.config.Settings settings) {
+  public IndexDefinitions(IndexDefinition[] defs, Configuration config) {
     this.defs = defs;
-    this.settings = settings;
+    this.config = config;
   }
 
   public Map<String, Index> getIndices() {
@@ -103,7 +104,7 @@ public class IndexDefinitions implements Startable {
     // collect definitions
     IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
 
-    if (!settings.getBoolean("sonar.internal.es.disableIndexes")) {
+    if (!config.getBoolean("sonar.internal.es.disableIndexes").orElse(false)) {
       for (IndexDefinition definition : defs) {
         definition.define(context);
       }
index 07ae9a9914b4c1ffcf497556b24fd67bef38748c..717f290d8be0ce17499cffc636700df506d458e2 100644 (file)
@@ -27,7 +27,7 @@ import org.elasticsearch.action.admin.indices.open.OpenIndexAction;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.settings.Settings.Builder;
 import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
@@ -41,12 +41,12 @@ public class IndexerStartupTask {
   private static final String SETTING_PREFIX_INITIAL_INDEXING_FINISHED = "sonarqube_initial_indexing_finished.";
 
   private final EsClient esClient;
-  private final Settings settings;
+  private final Configuration config;
   private final StartupIndexer[] indexers;
 
-  public IndexerStartupTask(EsClient esClient, Settings settings, StartupIndexer... indexers) {
+  public IndexerStartupTask(EsClient esClient, Configuration config, StartupIndexer... indexers) {
     this.esClient = esClient;
-    this.settings = settings;
+    this.config = config;
     this.indexers = indexers;
   }
 
@@ -58,7 +58,7 @@ public class IndexerStartupTask {
   }
 
   private boolean indexesAreEnabled() {
-    return !settings.getBoolean("sonar.internal.es.disableIndexes");
+    return !config.getBoolean("sonar.internal.es.disableIndexes").orElse(false);
   }
 
   private void indexEmptyTypes(StartupIndexer indexer) {
index bfc65cfbf270d86a0cfeae0350c9465364338b7a..1d85732cc755fb83c16170e678f5652c71f86d2e 100644 (file)
@@ -32,6 +32,7 @@ import javax.annotation.CheckForNull;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.settings.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.permission.index.AuthorizationTypeSupport;
 
@@ -77,17 +78,12 @@ public class NewIndex {
     return types;
   }
 
-  public void configureShards(org.sonar.api.config.Settings settings, int defaultNbOfShards) {
-    boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
-    int shards = settings.getInt(format("sonar.search.%s.shards", indexName));
-    if (shards == 0) {
-      shards = defaultNbOfShards;
-    }
+  public void configureShards(Configuration config, int defaultNbOfShards) {
+    boolean clusterMode = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+    int shards = config.getInt(format("sonar.search.%s.shards", indexName)).orElse(defaultNbOfShards);
+
+    int replicas = config.getInt(ProcessProperties.SEARCH_REPLICAS).orElse(clusterMode ? 1 : 0);
 
-    int replicas = settings.getInt(ProcessProperties.SEARCH_REPLICAS);
-    if (replicas == 0 && settings.getString(ProcessProperties.SEARCH_REPLICAS) == null) {
-      replicas = clusterMode ? 1 : 0;
-    }
     getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards);
     getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas);
   }
index 0a3dd89130257634f49a35162c63e3907c2dd9b1..37c1cf6d8abedd5292e42abaf15cdc11a4f40147 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.issue.index;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
@@ -74,10 +74,10 @@ public class IssueIndexDefinition implements IndexDefinition {
    */
   public static final String FIELD_ISSUE_TECHNICAL_UPDATED_AT = "updatedAt";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public IssueIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public IssueIndexDefinition(Configuration config) {
+    this.config = config;
   }
 
   @Override
@@ -85,7 +85,7 @@ public class IssueIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX_TYPE_ISSUE.getIndex());
 
     index.refreshHandledByIndexer();
-    index.configureShards(settings, 5);
+    index.configureShards(config, 5);
 
     NewIndex.NewIndexType type = index.createType(INDEX_TYPE_ISSUE.getType());
     type.requireProjectAuthorization();
index ea28cf08a2745c6f1406de66716971b25892ea59..76e4394774324bfd94294247d9420d15e7397d9a 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.measure.index;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
@@ -41,17 +41,17 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
   public static final String FIELD_MEASURES_VALUE = "value";
   public static final String FIELD_LANGUAGES = "languages";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public ProjectMeasuresIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public ProjectMeasuresIndexDefinition(Configuration settings) {
+    this.config = settings;
   }
 
   @Override
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX_TYPE_PROJECT_MEASURES.getIndex());
     index.refreshHandledByIndexer();
-    index.configureShards(settings, 5);
+    index.configureShards(config, 5);
 
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
       .requireProjectAuthorization();
index c32c9a4dec650f737c3e6ad3b6803914086dbf84..74f4747b874b56fb2aa428807cd0c5ebd5efa83b 100644 (file)
@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
 import org.picocontainer.Startable;
 import org.sonar.api.Properties;
 import org.sonar.api.Property;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.notifications.Notification;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Logger;
@@ -62,9 +62,9 @@ public class NotificationDaemon implements Startable {
   private ScheduledExecutorService executorService;
   private boolean stopping = false;
 
-  public NotificationDaemon(Settings settings, DefaultNotificationManager manager, NotificationService service) {
-    this.delayInSeconds = settings.getLong(PROPERTY_DELAY);
-    this.delayBeforeReportingStatusInSeconds = settings.getLong(PROPERTY_DELAY_BEFORE_REPORTING_STATUS);
+  public NotificationDaemon(Configuration config, DefaultNotificationManager manager, NotificationService service) {
+    this.delayInSeconds = config.getLong(PROPERTY_DELAY).get();
+    this.delayBeforeReportingStatusInSeconds = config.getLong(PROPERTY_DELAY_BEFORE_REPORTING_STATUS).get();
     this.manager = manager;
     this.service = service;
   }
index 9a9da7eeca0fdb1da9cb64a993f2dcf481026042..25a4939746bc1c57fa6dd892ef82715b428c6066 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.System2;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.util.UuidFactory;
@@ -68,20 +68,20 @@ public class OrganizationCreationImpl implements OrganizationCreation {
   private final System2 system2;
   private final UuidFactory uuidFactory;
   private final OrganizationValidation organizationValidation;
-  private final Settings settings;
+  private final Configuration config;
   private final BuiltInQProfileRepository builtInQProfileRepository;
   private final DefaultGroupCreator defaultGroupCreator;
   private final UserIndexer userIndexer;
 
   public OrganizationCreationImpl(DbClient dbClient, System2 system2, UuidFactory uuidFactory,
-    OrganizationValidation organizationValidation, Settings settings, UserIndexer userIndexer,
+    OrganizationValidation organizationValidation, Configuration config, UserIndexer userIndexer,
     BuiltInQProfileRepository builtInQProfileRepository,
     DefaultGroupCreator defaultGroupCreator) {
     this.dbClient = dbClient;
     this.system2 = system2;
     this.uuidFactory = uuidFactory;
     this.organizationValidation = organizationValidation;
-    this.settings = settings;
+    this.config = config;
     this.userIndexer = userIndexer;
     this.builtInQProfileRepository = builtInQProfileRepository;
     this.defaultGroupCreator = defaultGroupCreator;
@@ -170,7 +170,7 @@ public class OrganizationCreationImpl implements OrganizationCreation {
   }
 
   private boolean isCreatePersonalOrgEnabled() {
-    return settings.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_CREATE_PERSONAL_ORG);
+    return config.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_CREATE_PERSONAL_ORG).orElse(false);
   }
 
   private void validate(NewOrganization newOrganization) {
index f7c02a5edc58239d2fc800b899cec9adfac246f3..c19f0d68799e4a2df2b32b11cb101e959f522d6c 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.organization.ws;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -44,7 +44,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 public class CreateAction implements OrganizationsWsAction {
   private static final String ACTION = "create";
 
-  private final Settings settings;
+  private final Configuration config;
   private final UserSession userSession;
   private final DbClient dbClient;
   private final OrganizationsWsSupport wsSupport;
@@ -52,9 +52,9 @@ public class CreateAction implements OrganizationsWsAction {
   private final OrganizationCreation organizationCreation;
   private final OrganizationFlags organizationFlags;
 
-  public CreateAction(Settings settings, UserSession userSession, DbClient dbClient, OrganizationsWsSupport wsSupport,
+  public CreateAction(Configuration config, UserSession userSession, DbClient dbClient, OrganizationsWsSupport wsSupport,
     OrganizationValidation organizationValidation, OrganizationCreation organizationCreation, OrganizationFlags organizationFlags) {
-    this.settings = settings;
+    this.config = config;
     this.userSession = userSession;
     this.dbClient = dbClient;
     this.wsSupport = wsSupport;
@@ -87,7 +87,7 @@ public class CreateAction implements OrganizationsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    if (settings.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_ANYONE_CAN_CREATE)) {
+    if (config.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_ANYONE_CAN_CREATE).orElse(false)) {
       userSession.checkLoggedIn();
     } else {
       userSession.checkIsSystemAdministrator();
index a1ca634e5d6ea448e4d91c03e2d2529c93872707..295a38e39ec61643a51576e113b65c15de6be8eb 100644 (file)
@@ -21,14 +21,12 @@ package org.sonar.server.platform;
 
 import java.io.File;
 import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.app.TomcatContexts;
 
-import static java.util.Objects.requireNonNull;
-
 public class ServerFileSystemImpl implements ServerFileSystem, org.sonar.api.platform.ServerFileSystem, Startable {
 
   private static final Logger LOGGER = Loggers.get(ServerFileSystemImpl.class);
@@ -38,10 +36,10 @@ public class ServerFileSystemImpl implements ServerFileSystem, org.sonar.api.pla
   private final File dataDir;
   private final File deployDir;
 
-  public ServerFileSystemImpl(Settings settings) {
-    this.homeDir = new File(requireNonNull(settings.getString(ProcessProperties.PATH_HOME)));
-    this.tempDir = new File(requireNonNull(settings.getString(ProcessProperties.PATH_TEMP)));
-    this.dataDir = new File(requireNonNull(settings.getString(ProcessProperties.PATH_DATA)));
+  public ServerFileSystemImpl(Configuration config) {
+    this.homeDir = new File(config.get(ProcessProperties.PATH_HOME).get());
+    this.tempDir = new File(config.get(ProcessProperties.PATH_TEMP).get());
+    this.dataDir = new File(config.get(ProcessProperties.PATH_DATA).get());
     this.deployDir = new File(this.dataDir, TomcatContexts.WEB_DEPLOY_PATH_RELATIVE_TO_DATA_DIR);
   }
 
index 7a85fc3987e8855aedb3ae7b279a3baa0875e7ca..049316a0e47c3cb4c48d7729b0fd0a0bd624e8e5 100644 (file)
  */
 package org.sonar.server.platform;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-
-import static com.google.common.base.Optional.fromNullable;
+import org.sonar.api.config.Configuration;
 
 public class ServerIdLoader {
 
-  private final Settings settings;
+  private final Configuration config;
   private final ServerIdGenerator idGenerator;
 
-  public ServerIdLoader(Settings settings, ServerIdGenerator idGenerator) {
-    this.settings = settings;
+  public ServerIdLoader(Configuration config, ServerIdGenerator idGenerator) {
+    this.config = config;
     this.idGenerator = idGenerator;
   }
 
   public Optional<String> getRaw() {
-    return fromNullable(settings.getString(CoreProperties.PERMANENT_SERVER_ID));
+    return config.get(CoreProperties.PERMANENT_SERVER_ID);
   }
 
   public Optional<ServerId> get() {
-    Optional<String> rawId = getRaw();
-    if (!rawId.isPresent()) {
-      return Optional.absent();
-    }
-
-    String organization = settings.getString(CoreProperties.ORGANISATION);
-    String ipAddress = settings.getString(CoreProperties.SERVER_ID_IP_ADDRESS);
-    boolean validated = organization != null
-      && ipAddress != null
-      && idGenerator.validate(organization, ipAddress, rawId.get());
-
-    return Optional.of(new ServerId(rawId.get(), validated));
+    return getRaw().map(rawId -> {
+      Optional<String> organization = config.get(CoreProperties.ORGANISATION);
+      Optional<String> ipAddress = config.get(CoreProperties.SERVER_ID_IP_ADDRESS);
+      boolean validated = organization.isPresent()
+        && ipAddress.isPresent()
+        && idGenerator.validate(organization.get(), ipAddress.get(), rawId);
+
+      return new ServerId(rawId, validated);
+    });
   }
 }
index d753fee38691294551f91a289ed25b9ebed0616e..100cebba00de2d5749758ba48e8295ee2fd0e626 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Date;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.Server;
 import org.sonar.api.server.ServerSide;
 
@@ -32,14 +32,14 @@ import org.sonar.api.server.ServerSide;
 @ServerSide
 public class ServerImpl extends Server {
 
-  private final Settings settings;
+  private final Configuration config;
   private final StartupMetadata state;
   private final ServerFileSystem fs;
   private final UrlSettings urlSettings;
   private final SonarRuntime runtime;
 
-  public ServerImpl(Settings settings, StartupMetadata state, ServerFileSystem fs, UrlSettings urlSettings, SonarRuntime runtime) {
-    this.settings = settings;
+  public ServerImpl(Configuration config, StartupMetadata state, ServerFileSystem fs, UrlSettings urlSettings, SonarRuntime runtime) {
+    this.config = config;
     this.state = state;
     this.fs = fs;
     this.urlSettings = urlSettings;
@@ -48,12 +48,12 @@ public class ServerImpl extends Server {
 
   @Override
   public String getId() {
-    return settings.getString(CoreProperties.SERVER_ID);
+    return config.get(CoreProperties.SERVER_ID).get();
   }
 
   @Override
   public String getPermanentServerId() {
-    return settings.getString(CoreProperties.PERMANENT_SERVER_ID);
+    return config.get(CoreProperties.PERMANENT_SERVER_ID).orElse(null);
   }
 
   @Override
index 0f5845299502745d7234b7105c3ff6209172680f..a60631aed04e8b452a80581ae908ff76cf1cecd1 100644 (file)
@@ -25,12 +25,12 @@ import com.google.common.annotations.VisibleForTesting;
 import java.io.File;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.logging.LogbackHelper;
 import org.sonar.process.ProcessProperties;
+import org.sonar.process.logging.LogbackHelper;
 import org.sonar.server.app.ServerProcessLogging;
 
 @ServerSide
@@ -38,16 +38,16 @@ import org.sonar.server.app.ServerProcessLogging;
 public class ServerLogging {
 
   private final LogbackHelper helper;
-  private final Settings settings;
+  private final Configuration config;
 
-  public ServerLogging(Settings settings) {
-    this(new LogbackHelper(), settings);
+  public ServerLogging(Configuration config) {
+    this(new LogbackHelper(), config);
   }
 
   @VisibleForTesting
-  ServerLogging(LogbackHelper helper, Settings settings) {
+  ServerLogging(LogbackHelper helper, Configuration config) {
     this.helper = helper;
-    this.settings = settings;
+    this.config = config;
   }
 
   public void changeLevel(ServerProcessLogging serverProcessLogging, LoggerLevel level) {
@@ -64,7 +64,7 @@ public class ServerLogging {
    * The directory that contains log files. May not exist.
    */
   public File getLogsDir() {
-    return new File(settings.getString(ProcessProperties.PATH_LOGS));
+    return new File(config.get(ProcessProperties.PATH_LOGS).get());
   }
 
 }
index 0643ff0bf72e71d3fe00058df4f9d20eeb7cfab8..c56693c59210362505f592436f010c2cd610b7fd 100644 (file)
 package org.sonar.server.platform;
 
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
 import static org.apache.commons.lang.StringUtils.isEmpty;
 import static org.apache.commons.lang.StringUtils.isNotEmpty;
 import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
@@ -37,19 +36,19 @@ public class UrlSettings {
   private static final int DEFAULT_HTTP_PORT = 80;
   private static final String ALL_IPS_HOST = "0.0.0.0";
 
-  private final Settings settings;
+  private final Configuration config;
   // cached, so can't change at runtime
   private final String contextPath;
 
-  public UrlSettings(Settings settings) {
-    this.settings = settings;
-    this.contextPath = defaultIfBlank(settings.getString(PROPERTY_CONTEXT), "")
+  public UrlSettings(Configuration config) {
+    this.config = config;
+    this.contextPath = config.get(PROPERTY_CONTEXT).orElse("")
       // Remove trailing slashes
       .replaceFirst("(\\/+)$", "");
   }
 
   public String getBaseUrl() {
-    String url = settings.getString(SERVER_BASE_URL);
+    String url = config.get(SERVER_BASE_URL).orElse("");
     if (isEmpty(url)) {
       url = computeBaseUrl();
     }
@@ -61,7 +60,7 @@ public class UrlSettings {
   }
 
   public boolean isDev() {
-    return settings.getBoolean("sonar.web.dev");
+    return config.getBoolean("sonar.web.dev").orElse(false);
   }
 
   public boolean isSecured() {
@@ -69,9 +68,9 @@ public class UrlSettings {
   }
 
   private String computeBaseUrl() {
-    String host = settings.getString("sonar.web.host");
-    int port = settings.getInt("sonar.web.port");
-    String context = settings.getString("sonar.web.context");
+    String host = config.get("sonar.web.host").orElse("");
+    int port = config.getInt("sonar.web.port").orElse(0);
+    String context = config.get("sonar.web.context").orElse("");
 
     StringBuilder res = new StringBuilder();
     res.append("http://");
index d987b45f5952d361d86ce80b3b4cbda5a3637fbe..08e93f695ed471c5433cdb592f94f0f7be25682f 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.platform.cluster;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.ProcessProperties;
 
@@ -30,10 +30,10 @@ public class ClusterImpl implements Cluster {
   private final boolean enabled;
   private final boolean startupLeader;
 
-  public ClusterImpl(Settings settings) {
-    this.enabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
+  public ClusterImpl(Configuration config) {
+    this.enabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
     if (this.enabled) {
-      this.startupLeader = settings.getBoolean(CLUSTER_WEB_LEADER);
+      this.startupLeader = config.getBoolean(CLUSTER_WEB_LEADER).orElse(false);
       Loggers.get(ClusterImpl.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower");
     } else {
       this.startupLeader = true;
index 33d1f62d6376620cf452561211a6c9ab96d985ea..b971ee110f5000109277eb1cf1147caafd7260bf 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.commons.lang.StringUtils;
 import org.h2.Driver;
 import org.h2.tools.Server;
 import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -46,12 +46,12 @@ import static org.sonar.process.ProcessProperties.PATH_DATA;
 public class EmbeddedDatabase implements Startable {
   private static final Logger LOG = Loggers.get(EmbeddedDatabase.class);
 
-  private final Settings settings;
+  private final Configuration config;
   private final System2 system2;
   private Server server;
 
-  public EmbeddedDatabase(Settings settings, System2 system2) {
-    this.settings = settings;
+  public EmbeddedDatabase(Configuration config, System2 system2) {
+    this.config = config;
     this.system2 = system2;
   }
 
@@ -101,13 +101,13 @@ public class EmbeddedDatabase implements Startable {
   }
 
   private String getRequiredSetting(String property) {
-    String value = settings.getString(property);
+    String value = config.get(property).orElse("");
     checkArgument(isNotEmpty(value), "Missing property %s", property);
     return value;
   }
 
   private String getSetting(String name, String defaultValue) {
-    return StringUtils.defaultIfBlank(settings.getString(name), defaultValue);
+    return StringUtils.defaultIfBlank(config.get(name).orElse(""), defaultValue);
   }
 
   private static void createDatabase(File dbHome, String user, String password) throws SQLException {
index 91c69ff80fcc758712934881fccf62f90a85dc36..836065d1cf12fc5971f72887ced685f513da63f8 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.platform.db;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.database.DatabaseProperties;
 import org.sonar.api.utils.System2;
 
@@ -31,19 +31,19 @@ public class EmbeddedDatabaseFactory implements Startable {
 
   private static final String URL_PREFIX = "jdbc:h2:tcp:";
 
-  private final Settings settings;
+  private final Configuration config;
   private final System2 system2;
   private EmbeddedDatabase embeddedDatabase;
 
-  public EmbeddedDatabaseFactory(Settings settings, System2 system2) {
-    this.settings = settings;
+  public EmbeddedDatabaseFactory(Configuration config, System2 system2) {
+    this.config = config;
     this.system2 = system2;
   }
 
   @Override
   public void start() {
     if (embeddedDatabase == null) {
-      String jdbcUrl = settings.getString(DatabaseProperties.PROP_URL);
+      String jdbcUrl = config.get(DatabaseProperties.PROP_URL).get();
       if (startsWith(jdbcUrl, URL_PREFIX)) {
         embeddedDatabase = createEmbeddedDatabase();
         embeddedDatabase.start();
@@ -61,6 +61,6 @@ public class EmbeddedDatabaseFactory implements Startable {
 
   @VisibleForTesting
   EmbeddedDatabase createEmbeddedDatabase() {
-    return new EmbeddedDatabase(settings, system2);
+    return new EmbeddedDatabase(config, system2);
   }
 }
index 7a864c6471f06ba6d061c1cbf1cacf1426b13af5..823876d9911b86f95060d0e0c42ddec3cc4573ba 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.platform.monitoring;
 
 import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
 import java.io.File;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -28,14 +27,13 @@ import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.Server;
 import org.sonar.api.security.SecurityRealm;
 import org.sonar.api.server.authentication.IdentityProvider;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.authentication.IdentityProviderRepository;
-import org.sonar.server.platform.ServerId;
 import org.sonar.server.platform.ServerIdLoader;
 import org.sonar.server.platform.ServerLogging;
 import org.sonar.server.user.SecurityRealmFactory;
@@ -46,17 +44,17 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
 
   static final String BRANDING_FILE_PATH = "web/WEB-INF/classes/com/sonarsource/branding";
 
-  private final Settings settings;
+  private final Configuration config;
   private final SecurityRealmFactory securityRealmFactory;
   private final IdentityProviderRepository identityProviderRepository;
   private final Server server;
   private final ServerLogging serverLogging;
   private final ServerIdLoader serverIdLoader;
 
-  public SonarQubeMonitor(Settings settings, SecurityRealmFactory securityRealmFactory,
+  public SonarQubeMonitor(Configuration config, SecurityRealmFactory securityRealmFactory,
     IdentityProviderRepository identityProviderRepository, Server server, ServerLogging serverLogging,
     ServerIdLoader serverIdLoader) {
-    this.settings = settings;
+    this.config = config;
     this.securityRealmFactory = securityRealmFactory;
     this.identityProviderRepository = identityProviderRepository;
     this.server = server;
@@ -66,7 +64,7 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
 
   @Override
   public String getServerId() {
-    return serverIdLoader.getRaw().orNull();
+    return serverIdLoader.getRaw().orElse(null);
   }
 
   @Override
@@ -103,7 +101,7 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
   }
 
   private boolean getForceAuthentication() {
-    return settings.getBoolean(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY);
+    return config.getBoolean(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY).orElse(false);
   }
 
   private boolean isOfficialDistribution() {
@@ -129,20 +127,19 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
     addIfNotEmpty("External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders(), attributes);
     attributes.put("Force authentication", getForceAuthentication());
     attributes.put("Official Distribution", isOfficialDistribution());
-    attributes.put("Home Dir", settings.getString(ProcessProperties.PATH_HOME));
-    attributes.put("Data Dir", settings.getString(ProcessProperties.PATH_DATA));
-    attributes.put("Temp Dir", settings.getString(ProcessProperties.PATH_TEMP));
-    attributes.put("Logs Dir", settings.getString(ProcessProperties.PATH_LOGS));
+    attributes.put("Home Dir", config.get(ProcessProperties.PATH_HOME).orElse(null));
+    attributes.put("Data Dir", config.get(ProcessProperties.PATH_DATA).orElse(null));
+    attributes.put("Temp Dir", config.get(ProcessProperties.PATH_TEMP).orElse(null));
+    attributes.put("Logs Dir", config.get(ProcessProperties.PATH_LOGS).orElse(null));
     attributes.put("Logs Level", getLogLevel());
     return attributes;
   }
 
   private void completeWithServerIdAttributes(Map<String, Object> attributes) {
-    Optional<ServerId> serverId = serverIdLoader.get();
-    if (serverId.isPresent()) {
-      attributes.put("Server ID", serverId.get().getId());
-      attributes.put("Server ID validated", serverId.get().isValid());
-    }
+    serverIdLoader.get().ifPresent(serverId -> {
+      attributes.put("Server ID", serverId.getId());
+      attributes.put("Server ID validated", serverId.isValid());
+    });
   }
 
   private static void addIfNotNull(String key, @Nullable String value, Map<String, Object> attributes) {
index 7a2f30b5bba79ed7a9ec540114708b75043be623..10bffed4ced5388e08efdbc43eb6a1ca326e0a9b 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.Version;
 import org.sonar.api.utils.internal.TempFolderCleaner;
+import org.sonar.core.config.ConfigurationProvider;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.util.UuidFactoryImpl;
 import org.sonar.db.DaoModule;
@@ -76,6 +77,7 @@ public class PlatformLevel1 extends PlatformLevel {
       new SonarQubeVersion(apiVersion),
       SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SERVER),
       ThreadLocalSettings.class,
+      new ConfigurationProvider(),
       LogServerVersion.class,
       ProcessCommandWrapperImpl.class,
       RestartFlagHolderImpl.class,
index 3056d5bdde82e8ff4616ae67cdec2124056ae06a..ac0aa79be268beed9f96679c2312325045b39ed6 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.rules.AnnotationRuleParser;
 import org.sonar.api.rules.XMLRuleParser;
 import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
 import org.sonar.ce.CeModule;
-import org.sonar.ce.settings.ProjectSettingsFactory;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
 import org.sonar.core.component.DefaultResourceTypes;
 import org.sonar.core.timemachine.Periods;
 import org.sonar.server.authentication.AuthenticationModule;
@@ -508,7 +508,7 @@ public class PlatformLevel4 extends PlatformLevel {
       CeWsModule.class,
 
       InternalPropertiesImpl.class,
-      ProjectSettingsFactory.class,
+      ProjectConfigurationFactory.class,
 
       // UI
       NavigationWsModule.class,
index cb9e045d80daebd8eda06ea44b18e9ecee07c459..3a5160d573ac66ccb2782997ccbe567596e386e2 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.platform.ws;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -38,14 +38,14 @@ public class RestartAction implements SystemWsAction {
   private static final Logger LOGGER = Loggers.get(RestartAction.class);
 
   private final UserSession userSession;
-  private final Settings settings;
+  private final Configuration config;
   private final Platform platform;
   private final ProcessCommandWrapper processCommandWrapper;
   private final RestartFlagHolder restartFlagHolder;
 
-  public RestartAction(UserSession userSession, Settings settings, Platform platform, ProcessCommandWrapper processCommandWrapper, RestartFlagHolder restartFlagHolder) {
+  public RestartAction(UserSession userSession, Configuration config, Platform platform, ProcessCommandWrapper processCommandWrapper, RestartFlagHolder restartFlagHolder) {
     this.userSession = userSession;
-    this.settings = settings;
+    this.config = config;
     this.platform = platform;
     this.processCommandWrapper = processCommandWrapper;
     this.restartFlagHolder = restartFlagHolder;
@@ -62,7 +62,7 @@ public class RestartAction implements SystemWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    if (settings.getBoolean("sonar.web.dev")) {
+    if (config.getBoolean("sonar.web.dev").orElse(false)) {
       LOGGER.info("Fast restarting WebServer...");
       restartFlagHolder.set();
       try {
index d5038e7c3afd0f921758a53000c7edda409def5d..d16080a749b195e225616407157964142cc9845f 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.commons.io.IOUtils;
 import org.sonar.api.Properties;
 import org.sonar.api.Property;
 import org.sonar.api.PropertyType;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.UriReader;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.config.WebConstants;
@@ -72,10 +72,10 @@ public class UpdateCenterClient {
   private UpdateCenter pluginCenter = null;
   private long lastRefreshDate = 0;
 
-  public UpdateCenterClient(UriReader uriReader, Settings settings) throws URISyntaxException {
+  public UpdateCenterClient(UriReader uriReader, Configuration config) throws URISyntaxException {
     this.uriReader = uriReader;
-    this.uri = new URI(settings.getString(URL_PROPERTY));
-    this.isActivated = settings.getBoolean(WebConstants.SONAR_UPDATECENTER_ACTIVATE);
+    this.uri = new URI(config.get(URL_PROPERTY).get());
+    this.isActivated = config.getBoolean(WebConstants.SONAR_UPDATECENTER_ACTIVATE).get();
     Loggers.get(getClass()).info("Update center: " + uriReader.description(uri));
   }
 
index b50ef8398b2ee1d7e551f8450f04264090a80912..67e446d4aaf5a2f2ce20f8968aacebe71b80d70d 100644 (file)
@@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSortedMap;
 import java.util.Set;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.DefaultIndexSettings;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
@@ -77,15 +77,15 @@ public class RuleIndexDefinition implements IndexDefinition {
   public static final String FIELD_ACTIVE_RULE_SEVERITY = "severity";
   public static final String FIELD_ACTIVE_RULE_RULE_KEY = "ruleKey";
 
-  private final Settings settings;
+  private final Configuration config;
   private final boolean enableSource;
 
-  public RuleIndexDefinition(Settings settings) {
-    this(settings, false);
+  public RuleIndexDefinition(Configuration config) {
+    this(config, false);
   }
 
-  private RuleIndexDefinition(Settings settings, boolean enableSource) {
-    this.settings = settings;
+  private RuleIndexDefinition(Configuration config, boolean enableSource) {
+    this.config = config;
     this.enableSource = enableSource;
   }
 
@@ -93,8 +93,8 @@ public class RuleIndexDefinition implements IndexDefinition {
    * Keep the document sources in index so that indexer tests can verify content
    * of indexed documents.
    */
-  public static RuleIndexDefinition createForTest(Settings settings) {
-    return new RuleIndexDefinition(settings, true);
+  public static RuleIndexDefinition createForTest(Configuration config) {
+    return new RuleIndexDefinition(config, true);
   }
 
   @Override
@@ -105,7 +105,7 @@ public class RuleIndexDefinition implements IndexDefinition {
     // Default nb of shards should be greater than 1 in order to
     // easily detect routing misconfiguration.
     // See https://jira.sonarsource.com/browse/SONAR-9489
-    index.configureShards(settings, 2);
+    index.configureShards(config, 2);
 
     // Active rule type
     NewIndex.NewIndexType activeRuleMapping = index.createType(INDEX_TYPE_ACTIVE_RULE.getType());
index 5cd24c29399f696182bbc61e928ccc7741fbddcf..7d78f076394281ed4dd76fceb6ad4f85c611e8ff 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.test.index;
 
 import com.google.common.collect.ImmutableMap;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
@@ -41,10 +41,10 @@ public class TestIndexDefinition implements IndexDefinition {
   public static final String FIELD_COVERED_FILE_LINES = "coveredLines";
   public static final String FIELD_UPDATED_AT = "updatedAt";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public TestIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public TestIndexDefinition(Configuration config) {
+    this.config = config;
   }
 
   @Override
@@ -52,7 +52,7 @@ public class TestIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX_TYPE_TEST.getIndex());
 
     index.refreshHandledByIndexer();
-    index.configureShards(settings, 5);
+    index.configureShards(config, 5);
 
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType());
     mapping.setAttribute("_routing", ImmutableMap.of("required", true));
@@ -66,8 +66,7 @@ public class TestIndexDefinition implements IndexDefinition {
     mapping.stringFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
     mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
       FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", "string", "index", "not_analyzed"),
-      FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer")
-      )));
+      FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer"))));
     mapping.createDateTimeField(FIELD_UPDATED_AT);
   }
 }
index ac787e9652837439abf355509f0bb4134b1baf39..05c727707f063510d5e6deccc19169079b920ef9 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.ui.ws;
 
 import com.google.common.collect.ImmutableSet;
 import java.util.Set;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.Server;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
@@ -58,7 +58,7 @@ public class GlobalAction implements NavigationWsAction {
     RATING_GRID);
 
   private final PageRepository pageRepository;
-  private final Settings settings;
+  private final Configuration config;
   private final ResourceTypes resourceTypes;
   private final Server server;
   private final DbClient dbClient;
@@ -66,10 +66,10 @@ public class GlobalAction implements NavigationWsAction {
   private final DefaultOrganizationProvider defaultOrganizationProvider;
   private final UserSession userSession;
 
-  public GlobalAction(PageRepository pageRepository, Settings settings, ResourceTypes resourceTypes, Server server,
-                      DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider, UserSession userSession) {
+  public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
+    DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider, UserSession userSession) {
     this.pageRepository = pageRepository;
-    this.settings = settings;
+    this.config = config;
     this.resourceTypes = resourceTypes;
     this.server = server;
     this.dbClient = dbClient;
@@ -120,14 +120,14 @@ public class GlobalAction implements NavigationWsAction {
   private void writeSettings(JsonWriter json) {
     json.name("settings").beginObject();
     for (String settingKey : SETTING_KEYS) {
-      json.prop(settingKey, settings.getString(settingKey));
+      json.prop(settingKey, config.get(settingKey).orElse(null));
     }
     json.endObject();
   }
 
   private void writeDeprecatedLogoProperties(JsonWriter json) {
-    json.prop("logoUrl", settings.getString(SONAR_LF_LOGO_URL));
-    json.prop("logoWidth", settings.getString(SONAR_LF_LOGO_WIDTH_PX));
+    json.prop("logoUrl", config.get(SONAR_LF_LOGO_URL).orElse(null));
+    json.prop("logoWidth", config.get(SONAR_LF_LOGO_WIDTH_PX).orElse(null));
   }
 
   private void writeQualifiers(JsonWriter json) {
index b104a0d89fba643c5874dcf62f1dfcf64c6b7088..923affa0c3ba142b8a4c6b3d77d07d30b241565e 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.ui.ws;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService.NewController;
@@ -32,12 +32,12 @@ import org.sonar.server.user.UserSession;
 public class SettingsAction implements NavigationWsAction {
 
   private final PageRepository pageRepository;
-  private final Settings settings;
+  private final Configuration config;
   private final UserSession userSession;
 
-  public SettingsAction(PageRepository pageRepository, Settings settings, UserSession userSession) {
+  public SettingsAction(PageRepository pageRepository, Configuration config, UserSession userSession) {
     this.pageRepository = pageRepository;
-    this.settings = settings;
+    this.config = config;
     this.userSession = userSession;
   }
 
@@ -60,7 +60,7 @@ public class SettingsAction implements NavigationWsAction {
     boolean isSysAdmin = userSession.isSystemAdministrator();
 
     JsonWriter json = response.newJsonWriter().beginObject();
-    json.prop("showUpdateCenter", isSysAdmin && settings.getBoolean(WebConstants.SONAR_UPDATECENTER_ACTIVATE));
+    json.prop("showUpdateCenter", isSysAdmin && config.getBoolean(WebConstants.SONAR_UPDATECENTER_ACTIVATE).orElse(false));
 
     json.name("extensions").beginArray();
     if (isSysAdmin) {
index 61d2190f9f062f5e9339a127e434669e263fce81..683147ca2f93dd1ebc471c63ddca25d23d644d9d 100644 (file)
@@ -23,7 +23,7 @@ import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
 import org.picocontainer.Startable;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.security.LoginPasswordAuthenticator;
 import org.sonar.api.security.SecurityRealm;
 import org.sonar.api.server.ServerSide;
@@ -40,10 +40,10 @@ public class SecurityRealmFactory implements Startable {
   private final boolean ignoreStartupFailure;
   private final SecurityRealm realm;
 
-  public SecurityRealmFactory(Settings settings, SecurityRealm[] realms, LoginPasswordAuthenticator[] authenticators) {
-    ignoreStartupFailure = settings.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE);
-    String realmName = settings.getString(CoreProperties.CORE_AUTHENTICATOR_REALM);
-    String className = settings.getString(CoreProperties.CORE_AUTHENTICATOR_CLASS);
+  public SecurityRealmFactory(Configuration config, SecurityRealm[] realms, LoginPasswordAuthenticator[] authenticators) {
+    ignoreStartupFailure = config.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE).orElse(false);
+    String realmName = config.get(CoreProperties.CORE_AUTHENTICATOR_REALM).orElse(null);
+    String className = config.get(CoreProperties.CORE_AUTHENTICATOR_CLASS).orElse(null);
     SecurityRealm selectedRealm = null;
     if (!StringUtils.isEmpty(realmName)) {
       selectedRealm = selectRealm(realms, realmName);
@@ -63,16 +63,16 @@ public class SecurityRealmFactory implements Startable {
     realm = selectedRealm;
   }
 
-  public SecurityRealmFactory(Settings settings, LoginPasswordAuthenticator[] authenticators) {
-    this(settings, new SecurityRealm[0], authenticators);
+  public SecurityRealmFactory(Configuration config, LoginPasswordAuthenticator[] authenticators) {
+    this(config, new SecurityRealm[0], authenticators);
   }
 
-  public SecurityRealmFactory(Settings settings, SecurityRealm[] realms) {
-    this(settings, realms, new LoginPasswordAuthenticator[0]);
+  public SecurityRealmFactory(Configuration config, SecurityRealm[] realms) {
+    this(config, realms, new LoginPasswordAuthenticator[0]);
   }
 
-  public SecurityRealmFactory(Settings settings) {
-    this(settings, new SecurityRealm[0], new LoginPasswordAuthenticator[0]);
+  public SecurityRealmFactory(Configuration config) {
+    this(config, new SecurityRealm[0], new LoginPasswordAuthenticator[0]);
   }
 
   @Override
index d1ac28f0a3a1691b54cebf905e6a1d5255c4bd03..b92fae91e360742535283b70f589535b464b8039 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Objects;
 import java.util.Random;
 import javax.annotation.Nullable;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.NewUserHandler;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
@@ -78,10 +78,10 @@ public class UserUpdater {
   private final DefaultOrganizationProvider defaultOrganizationProvider;
   private final OrganizationCreation organizationCreation;
   private final DefaultGroupFinder defaultGroupFinder;
-  private final Settings settings;
+  private final Configuration config;
 
   public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, System2 system2, OrganizationFlags organizationFlags,
-    DefaultOrganizationProvider defaultOrganizationProvider, OrganizationCreation organizationCreation, DefaultGroupFinder defaultGroupFinder, Settings settings) {
+    DefaultOrganizationProvider defaultOrganizationProvider, OrganizationCreation organizationCreation, DefaultGroupFinder defaultGroupFinder, Configuration config) {
     this.newUserNotifier = newUserNotifier;
     this.dbClient = dbClient;
     this.userIndexer = userIndexer;
@@ -90,7 +90,7 @@ public class UserUpdater {
     this.defaultOrganizationProvider = defaultOrganizationProvider;
     this.organizationCreation = organizationCreation;
     this.defaultGroupFinder = defaultGroupFinder;
-    this.settings = settings;
+    this.config = config;
   }
 
   public UserDto create(DbSession dbSession, NewUser newUser) {
@@ -260,7 +260,7 @@ public class UserUpdater {
   }
 
   private void setOnboarded(UserDto userDto) {
-    boolean showOnboarding = settings.getBoolean(ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS);
+    boolean showOnboarding = config.getBoolean(ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS).orElse(false);
     userDto.setOnboarded(!showOnboarding);
   }
 
index 2270ccff34b49eafa7c31ec0c94e6c89738aef55..d64f2fd81456ed4c92b251d7ee82d62bffc66c37 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.user.index;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
@@ -42,17 +42,17 @@ public class UserIndexDefinition implements IndexDefinition {
   public static final String FIELD_SCM_ACCOUNTS = "scmAccounts";
   public static final String FIELD_ORGANIZATION_UUIDS = "organizationUuids";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public UserIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public UserIndexDefinition(Configuration config) {
+    this.config = config;
   }
 
   @Override
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX_TYPE_USER.getIndex());
 
-    index.configureShards(settings, 1);
+    index.configureShards(config, 1);
 
     // type "user"
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType());
index e9f2e27dbad634d6c60b440a17a2dcc8c9f8844c..7d28b5a26db0d938645ce43652f32edb12d3cfc0 100644 (file)
@@ -23,7 +23,7 @@ import okhttp3.OkHttpClient;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
 import org.sonar.process.ProcessProperties;
 import org.sonarqube.ws.client.OkHttpClientBuilder;
@@ -52,15 +52,15 @@ public class OkHttpClientProvider extends ProviderAdapter {
   /**
    * @return a {@link OkHttpClient} singleton
    */
-  public OkHttpClient provide(Settings settings, SonarRuntime runtime) {
+  public OkHttpClient provide(Configuration config, SonarRuntime runtime) {
     if (okHttpClient == null) {
       OkHttpClientBuilder builder = new OkHttpClientBuilder();
       builder.setConnectTimeoutMs(DEFAULT_CONNECT_TIMEOUT_IN_MS);
       builder.setReadTimeoutMs(DEFAULT_READ_TIMEOUT_IN_MS);
       // no need to define proxy URL as system-wide proxy is used and properly
       // configured by bootstrap process.
-      builder.setProxyLogin(settings.getString(ProcessProperties.HTTP_PROXY_USER));
-      builder.setProxyPassword(settings.getString(ProcessProperties.HTTP_PROXY_PASSWORD));
+      builder.setProxyLogin(config.get(ProcessProperties.HTTP_PROXY_USER).orElse(null));
+      builder.setProxyPassword(config.get(ProcessProperties.HTTP_PROXY_PASSWORD).orElse(null));
       builder.setUserAgent(format("SonarQube/%s", runtime.getApiVersion().toString()));
       okHttpClient = builder.build();
     }
index 602e41edb8795db7e7a4f92412c47239b4b3a5ee..d49ef6df2db31bf563b70e68d3d6779d77628994 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.view.index;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
@@ -33,17 +33,17 @@ public class ViewIndexDefinition implements IndexDefinition {
   public static final String FIELD_UUID = "uuid";
   public static final String FIELD_PROJECTS = "projects";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public ViewIndexDefinition(Settings settings) {
-    this.settings = settings;
+  public ViewIndexDefinition(Configuration config) {
+    this.config = config;
   }
 
   @Override
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX_TYPE_VIEW.getIndex());
 
-    index.configureShards(settings, 5);
+    index.configureShards(config, 5);
 
     // type "view"
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_VIEW.getType());
index e6c8c25247fac59ff3bcf41f3dde653701ceeddd..86d319d9e0ff5a68e58e236e0f2af0d355d951cc 100644 (file)
@@ -30,7 +30,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.process.DefaultProcessCommands;
@@ -56,9 +55,9 @@ public class CeHttpClientTest {
   @Before
   public void setUp() throws Exception {
     ipcSharedDir = temp.newFolder();
-    Settings settings = new MapSettings();
+    MapSettings settings = new MapSettings();
     settings.setProperty(ProcessEntryPoint.PROPERTY_SHARED_PATH, ipcSharedDir.getAbsolutePath());
-    underTest = new CeHttpClient(settings);
+    underTest = new CeHttpClient(settings.asConfig());
   }
 
   @Test
index 223b965fcfff6c59cde780120a504fcaca42cc46..b34daac76eb325b4ffcd104555566b86aaf6b6d4 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.process.DefaultProcessCommands;
 
@@ -41,11 +40,11 @@ public class ProcessCommandWrapperImplTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   @Test
   public void requestSQRestart_throws_IAE_if_process_index_property_not_set() throws Exception {
-    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property process.index is not set");
@@ -56,7 +55,7 @@ public class ProcessCommandWrapperImplTest {
   @Test
   public void requestSQRestart_throws_IAE_if_process_shared_path_property_not_set() throws Exception {
     settings.setProperty(PROPERTY_PROCESS_INDEX, 1);
-    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property process.sharedDir is not set");
@@ -70,7 +69,7 @@ public class ProcessCommandWrapperImplTest {
     settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
     settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);
 
-    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings.asConfig());
     underTest.requestSQRestart();
 
     try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(tmpDir, PROCESS_NUMBER)) {
@@ -81,7 +80,7 @@ public class ProcessCommandWrapperImplTest {
   @Test
   public void requestSQStop_throws_IAE_if_process_shared_path_property_not_set() throws Exception {
     settings.setProperty(PROPERTY_PROCESS_INDEX, 1);
-    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property process.sharedDir is not set");
@@ -95,7 +94,7 @@ public class ProcessCommandWrapperImplTest {
     settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
     settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);
 
-    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings.asConfig());
     underTest.requestStop();
 
     try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(tmpDir, PROCESS_NUMBER)) {
@@ -106,7 +105,7 @@ public class ProcessCommandWrapperImplTest {
   @Test
   public void notifyOperational_throws_IAE_if_process_sharedDir_property_not_set() throws Exception {
     settings.setProperty(PROPERTY_PROCESS_INDEX, 1);
-    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property process.sharedDir is not set");
@@ -116,7 +115,7 @@ public class ProcessCommandWrapperImplTest {
 
   @Test
   public void notifyOperational_throws_IAE_if_process_index_property_not_set() throws Exception {
-    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl processCommandWrapper = new ProcessCommandWrapperImpl(settings.asConfig());
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property process.index is not set");
@@ -130,7 +129,7 @@ public class ProcessCommandWrapperImplTest {
     settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
     settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);
 
-    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings);
+    ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings.asConfig());
     underTest.notifyOperational();
 
     try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(tmpDir, PROCESS_NUMBER)) {
index 6d552b4aa9a2bf7dd76424a132f2bd07957e4062..79762338534c92e904cd0498f744ef4e096b3a3e 100644 (file)
@@ -33,7 +33,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -80,12 +79,12 @@ public class JwtHttpHandlerTest {
   private HttpServletResponse response = mock(HttpServletResponse.class);
   private HttpSession httpSession = mock(HttpSession.class);
   private System2 system2 = spy(System2.INSTANCE);
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private JwtSerializer jwtSerializer = mock(JwtSerializer.class);
   private JwtCsrfVerifier jwtCsrfVerifier = mock(JwtCsrfVerifier.class);
   private UserDto userDto = newUserDto().setLogin(USER_LOGIN);
 
-  private JwtHttpHandler underTest = new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+  private JwtHttpHandler underTest = new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
 
   @Before
   public void setUp() throws Exception {
@@ -125,7 +124,7 @@ public class JwtHttpHandlerTest {
     int sessionTimeoutInMinutes = 10;
     settings.setProperty("sonar.web.sessionTimeoutInMinutes", sessionTimeoutInMinutes);
 
-    underTest = new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+    underTest = new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
     underTest.generateToken(userDto, request, response);
 
     verify(jwtSerializer).encode(jwtArgumentCaptor.capture());
@@ -137,7 +136,7 @@ public class JwtHttpHandlerTest {
     int firstSessionTimeoutInMinutes = 10;
     settings.setProperty("sonar.web.sessionTimeoutInMinutes", firstSessionTimeoutInMinutes);
 
-    underTest = new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+    underTest = new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
     underTest.generateToken(userDto, request, response);
 
     // The property is updated, but it won't be taking into account
@@ -155,7 +154,7 @@ public class JwtHttpHandlerTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property sonar.web.sessionTimeoutInMinutes must be strictly positive. Got 0");
 
-    new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+    new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
   }
 
   @Test
@@ -165,7 +164,7 @@ public class JwtHttpHandlerTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property sonar.web.sessionTimeoutInMinutes must be strictly positive. Got -10");
 
-    new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+    new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
   }
 
   @Test
@@ -175,7 +174,7 @@ public class JwtHttpHandlerTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Property sonar.web.sessionTimeoutInMinutes must not be greater than 3 months (129600 minutes). Got 172800 minutes");
 
-    new JwtHttpHandler(system2, dbClient, settings, jwtSerializer, jwtCsrfVerifier);
+    new JwtHttpHandler(system2, dbClient, settings.asConfig(), jwtSerializer, jwtCsrfVerifier);
   }
 
   @Test
index 0c3a97f8c02c863967fba80b3e332e1a057c4b45..86a260fcfabb9a828c3b01205f3531016a2328b1 100644 (file)
@@ -32,16 +32,15 @@ import javax.crypto.spec.SecretKeySpec;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.core.util.UuidFactoryImpl;
+import org.sonar.server.authentication.JwtSerializer.JwtSession;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.authentication.JwtSerializer.JwtSession;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.authentication.event.AuthenticationExceptionMatcher.authenticationException;
 
 public class JwtSerializerTest {
@@ -52,10 +51,10 @@ public class JwtSerializerTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private System2 system2 = System2.INSTANCE;
   private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
-  private JwtSerializer underTest = new JwtSerializer(settings, system2, uuidFactory);
+  private JwtSerializer underTest = new JwtSerializer(settings.asConfig(), system2, uuidFactory);
 
   @Test
   public void generate_token() throws Exception {
index 45c19a9ace3e216081c316f0e14be7e44db022df..85d34585105038a1eb9811398a98bd6816959b9e 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.security.Authenticator;
 import org.sonar.api.security.ExternalGroupsProvider;
@@ -36,6 +35,7 @@ import org.sonar.api.server.authentication.IdentityProvider;
 import org.sonar.api.server.authentication.UserIdentity;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.user.SecurityRealmFactory;
 
 import static java.util.Arrays.asList;
@@ -49,7 +49,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.authentication.event.AuthenticationEvent.Method.BASIC;
 import static org.sonar.server.authentication.event.AuthenticationEvent.Method.BASIC_TOKEN;
 import static org.sonar.server.authentication.event.AuthenticationExceptionMatcher.authenticationException;
@@ -69,7 +68,7 @@ public class RealmAuthenticatorTest {
   private ArgumentCaptor<IdentityProvider> identityProviderArgumentCaptor = ArgumentCaptor.forClass(IdentityProvider.class);
   private ArgumentCaptor<AuthenticationEvent.Source> sourceCaptor = ArgumentCaptor.forClass(Source.class);
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
   private SecurityRealm realm = mock(SecurityRealm.class);
@@ -82,7 +81,7 @@ public class RealmAuthenticatorTest {
 
   private HttpServletRequest request = mock(HttpServletRequest.class);
 
-  private RealmAuthenticator underTest = new RealmAuthenticator(settings, securityRealmFactory, userIdentityAuthenticator, authenticationEvent);
+  private RealmAuthenticator underTest = new RealmAuthenticator(settings.asConfig(), securityRealmFactory, userIdentityAuthenticator, authenticationEvent);
 
   @Before
   public void setUp() throws Exception {
index 3cd623bd8a2982aeaeb2a18daefd39a723d29a75..5875442d41d341ff54bd562ee515acf7bc452dfd 100644 (file)
@@ -31,7 +31,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
@@ -40,6 +39,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.OrganizationCreation;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -61,7 +61,6 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.authentication.event.AuthenticationExceptionMatcher.authenticationException;
 
 public class SsoAuthenticatorTest {
@@ -94,7 +93,7 @@ public class SsoAuthenticatorTest {
   private GroupDto sonarUsers;
 
   private System2 system2 = mock(System2.class);
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private OrganizationCreation organizationCreation = mock(OrganizationCreation.class);
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
   private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
@@ -102,14 +101,14 @@ public class SsoAuthenticatorTest {
   private UserIdentityAuthenticator userIdentityAuthenticator = new UserIdentityAuthenticator(
     db.getDbClient(),
     new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), mock(UserIndexer.class), System2.INSTANCE, organizationFlags, defaultOrganizationProvider, organizationCreation,
-      new DefaultGroupFinder(db.getDbClient()), settings),
+      new DefaultGroupFinder(db.getDbClient()), settings.asConfig()),
     defaultOrganizationProvider, organizationFlags, new DefaultGroupFinder(db.getDbClient()));
 
   private HttpServletResponse response = mock(HttpServletResponse.class);
   private JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
   private AuthenticationEvent authenticationEvent = mock(AuthenticationEvent.class);
 
-  private SsoAuthenticator underTest = new SsoAuthenticator(system2, settings, userIdentityAuthenticator, jwtHttpHandler, authenticationEvent);
+  private SsoAuthenticator underTest = new SsoAuthenticator(system2, settings.asConfig(), userIdentityAuthenticator, jwtHttpHandler, authenticationEvent);
 
   @Before
   public void setUp() throws Exception {
index 9f84bab5786159b3f15c549cbd1e9571cd71eea7..4063840137584fa731b2031dc8257b6f8b7b419d 100644 (file)
@@ -33,6 +33,8 @@ import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.authentication.event.AuthenticationEvent.Method;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.OrganizationCreation;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -48,8 +50,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.sonar.core.config.CorePropertyDefinitions.ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Method;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.authentication.event.AuthenticationExceptionMatcher.authenticationException;
 
 public class UserIdentityAuthenticatorTest {
@@ -89,7 +89,7 @@ public class UserIdentityAuthenticatorTest {
     defaultOrganizationProvider,
     organizationCreation,
     new DefaultGroupFinder(db.getDbClient()),
-    settings);
+    settings.asConfig());
   private UserIdentityAuthenticator underTest = new UserIdentityAuthenticator(db.getDbClient(), userUpdater, defaultOrganizationProvider, organizationFlags,
     new DefaultGroupFinder(db.getDbClient()));
 
index 4f16213740931777549232d4f0b900a31c3d8e52..b8fcf9fd7ce21b1eda2df1dc6d9cb3dfacd15af4 100644 (file)
@@ -26,7 +26,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.server.authentication.BaseIdentityProvider;
 import org.sonar.api.utils.System2;
@@ -35,6 +34,8 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.authentication.event.AuthenticationEvent;
+import org.sonar.server.authentication.event.AuthenticationEvent.Method;
+import org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import org.sonar.server.authentication.event.AuthenticationException;
 import org.sonar.server.user.ServerUserSession;
 import org.sonar.server.user.TestUserSessionFactory;
@@ -53,8 +54,6 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Method;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 
 public class UserSessionInitializerTest {
 
@@ -75,11 +74,11 @@ public class UserSessionInitializerTest {
   private SsoAuthenticator ssoAuthenticator = mock(SsoAuthenticator.class);
   private AuthenticationEvent authenticationEvent = mock(AuthenticationEvent.class);
   private TestUserSessionFactory userSessionFactory = TestUserSessionFactory.standalone();
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   private UserDto user = newUserDto();
 
-  private UserSessionInitializer underTest = new UserSessionInitializer(settings, jwtHttpHandler, basicAuthenticator,
+  private UserSessionInitializer underTest = new UserSessionInitializer(settings.asConfig(), jwtHttpHandler, basicAuthenticator,
     ssoAuthenticator, userSession, authenticationEvent, userSessionFactory);
 
   @Before
index 414195baff8d1ce07b3278818ec3aac0dedd8672..948bcc40233238e16cceeed197642501dbc69a56 100644 (file)
@@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.server.authentication.BasicAuthenticator;
 import org.sonar.server.authentication.JwtHttpHandler;
@@ -52,9 +51,9 @@ public class ValidateActionTest {
   BasicAuthenticator basicAuthenticator = mock(BasicAuthenticator.class);
   JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
 
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
 
-  ValidateAction underTest = new ValidateAction(settings, basicAuthenticator, jwtHttpHandler);
+  ValidateAction underTest = new ValidateAction(settings.asConfig(), basicAuthenticator, jwtHttpHandler);
 
   @Before
   public void setUp() throws Exception {
index 4fca15eacc432e402acbef42e4399a9b1840ee1a..8d9ace5f123513a13fd5e06ba3a15059c4fd7ffd 100644 (file)
@@ -70,7 +70,7 @@ public class IssuesActionTest {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
index a467d42b4408805f963963b162ff400916abc47b..50f42cbf9821c7dd6147a41182df3920947babda 100644 (file)
@@ -48,7 +48,7 @@ import static org.sonar.api.resources.Qualifiers.PROJECT;
 public abstract class ComponentIndexTest {
 
   @Rule
-  public EsTester es = new EsTester(new ComponentIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ComponentIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
index 7324b52cce2a37c244b930c980e8b0b1f9c35fc4..cf69abaaf33f65920827e3b145b693192bba2691 100644 (file)
@@ -48,7 +48,7 @@ public class ComponentIndexerTest {
   private System2 system2 = System2.INSTANCE;
 
   @Rule
-  public EsTester esTester = new EsTester(new ComponentIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new ComponentIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester dbTester = DbTester.create(system2);
index 6208aa2fa2cffaed967cef358e60ad057c870407..7afbb927c5d636c5257b2a4dcdf1069c45239096 100644 (file)
@@ -111,7 +111,7 @@ public class SearchProjectsActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
-  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
index a1d07572f772a65f7c12c282668cc5c4c279ba5d..4f354df9bd102bb1ecccd5f5c2b2caed404ddc6d 100644 (file)
@@ -53,6 +53,8 @@ import org.sonar.server.ws.WsActionTester;
 import org.sonar.test.JsonAssert;
 import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse;
+import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Category;
+import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Organization;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Project;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Suggestion;
 
@@ -80,8 +82,6 @@ import static org.sonar.server.component.ws.SuggestionsAction.PARAM_MORE;
 import static org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY;
 import static org.sonar.server.component.ws.SuggestionsAction.PARAM_RECENTLY_BROWSED;
 import static org.sonar.server.component.ws.SuggestionsAction.SHORT_INPUT_WARNING;
-import static org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Category;
-import static org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Organization;
 
 public class SuggestionsActionTest {
   private static final String[] SUGGESTION_QUALIFIERS = Stream.of(SuggestionCategory.values())
@@ -91,7 +91,7 @@ public class SuggestionsActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
-  public EsTester es = new EsTester(new ComponentIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ComponentIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   public ResourceTypesRule resourceTypes = new ResourceTypesRule();
index b9c8007ef110c70f9bfeb0047ff70c059b0403ee..611a8d14c5345c66ce4aa0bc0c855bb2fe7d839b 100644 (file)
@@ -22,10 +22,12 @@ package org.sonar.server.computation.dbcleaner;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.core.config.PurgeConstants;
+import org.sonar.core.config.PurgeProperties;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
 import org.sonar.db.purge.PurgeConfiguration;
@@ -35,9 +37,9 @@ import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.purge.period.DefaultPeriodCleaner;
 
 import static java.util.Collections.emptyList;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyLong;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -50,7 +52,7 @@ public class ProjectCleanerTest {
   private PurgeProfiler profiler = mock(PurgeProfiler.class);
   private DefaultPeriodCleaner periodCleaner = mock(DefaultPeriodCleaner.class);
   private PurgeListener purgeListener = mock(PurgeListener.class);
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all()));
 
   @Before
   public void before() {
@@ -61,7 +63,7 @@ public class ProjectCleanerTest {
   public void no_profiling_when_property_is_false() {
     settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
 
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings, emptyList());
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList());
 
     verify(profiler, never()).dump(anyLong(), any(Logger.class));
   }
@@ -70,7 +72,7 @@ public class ProjectCleanerTest {
   public void profiling_when_property_is_true() {
     settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
 
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings, emptyList());
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList());
 
     verify(profiler).dump(anyLong(), any(Logger.class));
   }
@@ -79,9 +81,9 @@ public class ProjectCleanerTest {
   public void call_period_cleaner_index_client_and_purge_dao() {
     settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
 
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings, emptyList());
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList());
 
-    verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class));
+    verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Configuration.class));
     verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
   }
 
@@ -89,17 +91,17 @@ public class ProjectCleanerTest {
   public void if_dao_purge_fails_it_should_not_interrupt_program_execution() {
     doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
 
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings, emptyList());
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList());
 
     verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
   }
 
   @Test
   public void if_profiler_cleaning_fails_it_should_not_interrupt_program_execution() {
-    doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class));
+    doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyString(), any(Configuration.class));
 
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings, emptyList());
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList());
 
-    verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class));
+    verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Configuration.class));
   }
 }
index f7e4c33359a27b64ae29dced26b017678c0542a5..533c19917e855c204e43442af1b78803f604b1b6 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
@@ -95,7 +95,7 @@ public class MeasureComputerContextImplTest {
   @Rule
   public ComponentIssuesRepositoryRule componentIssuesRepository = new ComponentIssuesRepositoryRule(treeRootHolder);
 
-  SettingsRepository settingsRepository = mock(SettingsRepository.class);
+  ConfigurationRepository settingsRepository = mock(ConfigurationRepository.class);
 
   @Test
   public void get_component() throws Exception {
@@ -105,9 +105,9 @@ public class MeasureComputerContextImplTest {
 
   @Test
   public void get_string_settings() throws Exception {
-    org.sonar.api.config.Settings serverSettings = new MapSettings();
+    MapSettings serverSettings = new MapSettings();
     serverSettings.setProperty("prop", "value");
-    when(settingsRepository.getSettings(FILE_1)).thenReturn(serverSettings);
+    when(settingsRepository.getConfiguration(FILE_1)).thenReturn(serverSettings.asConfig());
 
     MeasureComputerContextImpl underTest = newContext(FILE_1_REF);
     assertThat(underTest.getSettings().getString("prop")).isEqualTo("value");
@@ -116,9 +116,9 @@ public class MeasureComputerContextImplTest {
 
   @Test
   public void get_string_array_settings() throws Exception {
-    org.sonar.api.config.Settings serverSettings = new MapSettings();
+    MapSettings serverSettings = new MapSettings();
     serverSettings.setProperty("prop", "1,3.4,8,50");
-    when(settingsRepository.getSettings(FILE_1)).thenReturn(serverSettings);
+    when(settingsRepository.getConfiguration(FILE_1)).thenReturn(serverSettings.asConfig());
 
     MeasureComputerContextImpl underTest = newContext(FILE_1_REF);
     assertThat(underTest.getSettings().getStringArray("prop")).containsExactly("1", "3.4", "8", "50");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java
new file mode 100644 (file)
index 0000000..a2800c3
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.component;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.property.PropertyDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
+
+public class ConfigurationRepositoryTest {
+
+  private static final Component ROOT = ReportComponent.builder(PROJECT, 1).setKey("ROOT").build();
+
+  @Rule
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+  DbClient dbClient = dbTester.getDbClient();
+
+  DbSession session;
+
+  MapSettings globalSettings;
+
+  ConfigurationRepository underTest;
+
+  @Before
+  public void createDao() {
+    globalSettings = new MapSettings();
+    session = dbClient.openSession(false);
+    underTest = new ConfigurationRepositoryImpl(new ProjectConfigurationFactory(globalSettings, dbClient));
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void get_project_settings_from_global_settings() {
+    globalSettings.setProperty("key", "value");
+
+    Configuration config = underTest.getConfiguration(ROOT);
+
+    assertThat(config.get("key")).hasValue("value");
+  }
+
+  @Test
+  public void get_project_settings_from_db() {
+    ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey());
+    dbClient.componentDao().insert(session, project);
+    dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value"));
+    session.commit();
+
+    Configuration config = underTest.getConfiguration(ROOT);
+
+    assertThat(config.get("key")).hasValue("value");
+  }
+
+  @Test
+  public void call_twice_get_project_settings() {
+    globalSettings.setProperty("key", "value");
+
+    Configuration config = underTest.getConfiguration(ROOT);
+    assertThat(config.get("key")).hasValue("value");
+
+    config = underTest.getConfiguration(ROOT);
+    assertThat(config.get("key")).hasValue("value");
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/SettingsRepositoryTest.java
deleted file mode 100644 (file)
index de328c1..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.component;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.api.utils.System2;
-import org.sonar.ce.settings.ProjectSettingsFactory;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.property.PropertyDto;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
-
-
-public class SettingsRepositoryTest {
-
-  private static final Component ROOT = ReportComponent.builder(PROJECT, 1).setKey("ROOT").build();
-
-  @Rule
-  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  DbClient dbClient = dbTester.getDbClient();
-
-  DbSession session;
-
-  MapSettings globalSettings;
-
-  SettingsRepository underTest;
-
-  @Before
-  public void createDao() {
-    globalSettings = new MapSettings();
-    session = dbClient.openSession(false);
-    underTest = new SettingsRepositoryImpl(new ProjectSettingsFactory(globalSettings, dbClient));
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void get_project_settings_from_global_settings() {
-    globalSettings.setProperty("key", "value");
-
-    Settings settings = underTest.getSettings(ROOT);
-
-    assertThat(settings.getString("key")).isEqualTo("value");
-  }
-
-  @Test
-  public void get_project_settings_from_db() {
-    ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey());
-    dbClient.componentDao().insert(session, project);
-    dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value"));
-    session.commit();
-
-    Settings settings = underTest.getSettings(ROOT);
-
-    assertThat(settings.getString("key")).isEqualTo("value");
-  }
-
-  @Test
-  public void call_twice_get_project_settings() {
-    globalSettings.setProperty("key", "value");
-
-    Settings settings = underTest.getSettings(ROOT);
-    assertThat(settings.getString("key")).isEqualTo("value");
-
-    settings = underTest.getSettings(ROOT);
-    assertThat(settings.getString("key")).isEqualTo("value");
-  }
-}
index be233329461c6ea4a4ba2a3363026239ed010575..b436f0d38d251468662f946806d4ca3838c58056 100644 (file)
  */
 package org.sonar.server.computation.task.projectanalysis.component;
 
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 
 /**
- * Implementation of {@link SettingsRepository} that always return the
- * same mutable {@link Settings}, whatever the component.
+ * Implementation of {@link ConfigurationRepository} that always return the
+ * same {@link Configuration}, whatever the component.
  */
-public class TestSettingsRepository implements SettingsRepository {
+public class TestSettingsRepository implements ConfigurationRepository {
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public TestSettingsRepository(Settings settings) {
-    this.settings = settings;
+  public TestSettingsRepository(Configuration config) {
+    this.config = config;
   }
 
   @Override
-  public Settings getSettings(Component component) {
-    return settings;
+  public Configuration getConfiguration(Component component) {
+    return config;
   }
 }
index b75ebdb223e14e19c9ec337c8cd215c7389a9860..11e998b817ade4c0d193ca2ea7aa216628f4b1d7 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Collection;
 import java.util.Collections;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -59,9 +58,9 @@ public class IntegrateCrossProjectDuplicationsTest {
 
   static final String OTHER_FILE_KEY = "OTHER_FILE_KEY";
 
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
 
-  IntegrateCrossProjectDuplications underTest = new IntegrateCrossProjectDuplications(settings, duplicationRepository);
+  IntegrateCrossProjectDuplications underTest = new IntegrateCrossProjectDuplications(settings.asConfig(), duplicationRepository);
 
   @Test
   public void add_duplications_from_two_blocks() {
@@ -81,8 +80,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(1)
         .setLines(32, 45)
         .setUnit(5, 20)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = asList(
       new Block.Builder()
@@ -102,8 +100,7 @@ public class IntegrateCrossProjectDuplicationsTest {
 
     assertThat(duplicationRepository.getDuplications(ORIGIN_FILE))
       .containsExactly(
-        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55))
-      );
+        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
   }
 
   @Test
@@ -118,8 +115,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(30, 45)
         .setUnit(0, 10)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = singletonList(
       new Block.Builder()
@@ -127,15 +123,13 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setBlockHash(new ByteArray("a8998353e96320ec"))
         .setIndexInFile(0)
         .setLines(40, 55)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
 
     assertThat(duplicationRepository.getDuplications(ORIGIN_FILE))
       .containsExactly(
-        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55))
-      );
+        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
   }
 
   @Test
@@ -157,8 +151,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(46, 60)
         .setUnit(0, 10)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = singletonList(
       new Block.Builder()
@@ -166,8 +159,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setBlockHash(new ByteArray("a8998353e96320ed"))
         .setIndexInFile(0)
         .setLines(40, 55)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
 
@@ -186,8 +178,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(30, 45)
         .setUnit(0, 4)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = singletonList(
       new Block.Builder()
@@ -195,8 +186,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setBlockHash(new ByteArray("a8998353e96320ec"))
         .setIndexInFile(0)
         .setLines(40, 55)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
 
@@ -214,8 +204,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(30, 45)
         .setUnit(0, 10)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, Collections.<Block>emptyList());
 
@@ -237,8 +226,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(30, 45)
         .setUnit(0, 0)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = singletonList(
       new Block.Builder()
@@ -246,15 +234,13 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setBlockHash(new ByteArray("a8998353e96320ec"))
         .setIndexInFile(0)
         .setLines(40, 55)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(javaFile, originBlocks, duplicatedBlocks);
 
     assertThat(duplicationRepository.getDuplications(ORIGIN_FILE))
       .containsExactly(
-        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55))
-      );
+        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
   }
 
   @Test
@@ -268,8 +254,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setIndexInFile(0)
         .setLines(30, 45)
         .setUnit(0, 100)
-        .build()
-      );
+        .build());
 
     Collection<Block> duplicatedBlocks = singletonList(
       new Block.Builder()
@@ -277,15 +262,13 @@ public class IntegrateCrossProjectDuplicationsTest {
         .setBlockHash(new ByteArray("a8998353e96320ec"))
         .setIndexInFile(0)
         .setLines(40, 55)
-        .build()
-      );
+        .build());
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
 
     assertThat(duplicationRepository.getDuplications(ORIGIN_FILE))
       .containsExactly(
-        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55))
-      );
+        crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
   }
 
   @Test
@@ -306,8 +289,7 @@ public class IntegrateCrossProjectDuplicationsTest {
       duplicatedBlocks.add(
         blockBuilder
           .setResourceId(randomAlphanumeric(16))
-          .build()
-        );
+          .build());
     }
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
@@ -341,8 +323,7 @@ public class IntegrateCrossProjectDuplicationsTest {
         blockBuilder
           .setResourceId("resource" + i)
           .setBlockHash(new ByteArray(hash))
-          .build()
-        );
+          .build());
     }
 
     underTest.computeCpd(ORIGIN_FILE, originBlocks, duplicatedBlocks);
index 024844859bebebf978791a75f2b694414438e434..b65ecc8a1cbb214592f3e7f4071f045539d7320d 100644 (file)
@@ -23,14 +23,13 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
 import org.sonar.server.computation.task.projectanalysis.analysis.Organization;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TestSettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 
@@ -48,8 +47,8 @@ public class DefaultAssigneeTest {
   @Rule
   public TreeRootHolderRule rootHolder = new TreeRootHolderRule().setRoot(DUMB_PROJECT);
 
-  private Settings settings = new MapSettings();
-  private SettingsRepository settingsRepository = new TestSettingsRepository(settings);
+  private MapSettings settings = new MapSettings();
+  private ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
   private AnalysisMetadataHolderImpl analysisMetadataHolder = new AnalysisMetadataHolderImpl();
   private OrganizationDto organizationDto;
 
index 0afcc53cbee2e5d60f6186c1083a275b00b9dfca..e8a08221bf27e2da58462bc672fc3675a5123273 100644 (file)
@@ -36,7 +36,7 @@ import static org.junit.Assert.fail;
 public class ScmAccountToUserLoaderTest {
 
   @org.junit.Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   @org.junit.Rule
   public LogTester logTester = new LogTester();
index d119b23ee3f9fc9a40164249c71a82959fc03307..0c36fc90d9a1839960ebe21652a66dc848d05f32 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 
 import static java.util.Arrays.asList;
@@ -67,7 +67,7 @@ public class IssueFilterTest {
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
 
-  SettingsRepository settingsRepository = mock(SettingsRepository.class);
+  ConfigurationRepository settingsRepository = mock(ConfigurationRepository.class);
 
   @Test
   public void accept_everything_when_no_filter_properties() throws Exception {
@@ -101,8 +101,7 @@ public class IssueFilterTest {
   public void ignore_many_rules() throws Exception {
     IssueFilter underTest = newIssueFilter(newSettings(
       asList("xoo:x1", "**/xoo/File1*", "xoo:x2", "**/xoo/File1*"),
-      Collections.<String>emptyList())
-    );
+      Collections.<String>emptyList()));
 
     assertThat(underTest.accept(ISSUE_1, COMPONENT_1)).isFalse();
     assertThat(underTest.accept(ISSUE_1, COMPONENT_2)).isTrue();
@@ -147,8 +146,7 @@ public class IssueFilterTest {
   public void include_many_rules() throws Exception {
     IssueFilter underTest = newIssueFilter(newSettings(
       Collections.<String>emptyList(),
-      asList("xoo:x1", "**/xoo/File1*", "xoo:x2", "**/xoo/File1*")
-    ));
+      asList("xoo:x1", "**/xoo/File1*", "xoo:x2", "**/xoo/File1*")));
 
     assertThat(underTest.accept(ISSUE_1, COMPONENT_1)).isTrue();
     assertThat(underTest.accept(ISSUE_1, COMPONENT_2)).isFalse();
@@ -182,13 +180,13 @@ public class IssueFilterTest {
     newIssueFilter(newSettings(Collections.<String>emptyList(), asList("", "**")));
   }
 
-  private IssueFilter newIssueFilter(Settings settings) {
-    when(settingsRepository.getSettings(PROJECT)).thenReturn(settings);
+  private IssueFilter newIssueFilter(MapSettings settings) {
+    when(settingsRepository.getConfiguration(PROJECT)).thenReturn(settings.asConfig());
     return new IssueFilter(treeRootHolder, settingsRepository);
   }
 
-  private static Settings newSettings(List<String> exclusionsProperties, List<String> inclusionsProperties) {
-    Settings settings = new MapSettings();
+  private static MapSettings newSettings(List<String> exclusionsProperties, List<String> inclusionsProperties) {
+    MapSettings settings = new MapSettings();
     if (!exclusionsProperties.isEmpty()) {
       addProperties(exclusionsProperties, "ignore", settings);
     }
index 43bad73e48c66cac9df741f5b3782a8e5839c495..c3653c11ea71960380e2e009dc0e43a68dc608fe 100644 (file)
@@ -24,7 +24,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.MessageException;
@@ -37,7 +36,7 @@ import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS
 
 public class RatingSettingsTest {
 
-  private Settings settings;
+  private MapSettings settings;
 
   @Rule
   public ExpectedException throwable = ExpectedException.none();
@@ -50,7 +49,7 @@ public class RatingSettingsTest {
   @Test
   public void load_rating_grid() {
     settings.setProperty(CoreProperties.RATING_GRID, "1,3.4,8,50");
-    RatingSettings configurationLoader = new RatingSettings(settings);
+    RatingSettings configurationLoader = new RatingSettings(settings.asConfig());
 
     double[] grid = configurationLoader.getRatingGrid().getGridValues();
     assertThat(grid).hasSize(4);
@@ -63,7 +62,7 @@ public class RatingSettingsTest {
   @Test
   public void load_work_units_for_language() {
     settings.setProperty(DEVELOPMENT_COST, "50");
-    RatingSettings configurationLoader = new RatingSettings(settings);
+    RatingSettings configurationLoader = new RatingSettings(settings.asConfig());
 
     assertThat(configurationLoader.getDevCost("defaultLanguage")).isEqualTo(50L);
   }
@@ -82,7 +81,7 @@ public class RatingSettingsTest {
     settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY, "40");
     settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY, CoreMetrics.COMPLEXITY_KEY);
 
-    RatingSettings configurationLoader = new RatingSettings(settings);
+    RatingSettings configurationLoader = new RatingSettings(settings.asConfig());
 
     assertThat(configurationLoader.getDevCost(aLanguage)).isEqualTo(30L);
     assertThat(configurationLoader.getDevCost(anotherLanguage)).isEqualTo(40L);
@@ -90,7 +89,7 @@ public class RatingSettingsTest {
 
   @Test
   public void fail_on_invalid_rating_grid_configuration() {
-    RatingSettings configurationLoader = new RatingSettings(settings);
+    RatingSettings configurationLoader = new RatingSettings(settings.asConfig());
 
     throwable.expect(IllegalArgumentException.class);
     settings.setProperty(CoreProperties.RATING_GRID, "a b c");
@@ -107,7 +106,7 @@ public class RatingSettingsTest {
     settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY, aLanguage);
     settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY, "40");
 
-    RatingSettings configurationLoader = new RatingSettings(settings);
+    RatingSettings configurationLoader = new RatingSettings(settings.asConfig());
 
     assertThat(configurationLoader.getDevCost(aLanguage)).isEqualTo(40L);
   }
@@ -122,6 +121,6 @@ public class RatingSettingsTest {
     throwable.expectMessage("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " +
       "Contact your administrator to update this configuration in the global administration section of SonarQube.");
 
-    new RatingSettings(settings);
+    new RatingSettings(settings.asConfig());
   }
 }
index a150f7857e3a29c39cde658d91c7681921e3dab0..a0bfda79d629c76d90ac6e7a4d6a777b35c5ee95 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
@@ -36,8 +35,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
@@ -72,8 +71,8 @@ public class LoadPeriodsStepTest extends BaseStepTest {
 
   private PeriodHolderImpl periodsHolder = new PeriodHolderImpl();
   private DbClient dbClient = dbTester.getDbClient();
-  private Settings settings = new MapSettings();
-  private SettingsRepository settingsRepository = mock(SettingsRepository.class);
+  private MapSettings settings = new MapSettings();
+  private ConfigurationRepository settingsRepository = mock(ConfigurationRepository.class);
 
   private LoadPeriodsStep underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
 
@@ -89,7 +88,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
 
   private void setupRoot(Component root) {
     treeRootHolder.setRoot(root);
-    when(settingsRepository.getSettings(root)).thenReturn(settings);
+    when(settingsRepository.getConfiguration(root)).thenReturn(settings.asConfig());
   }
 
   @DataProvider
@@ -293,7 +292,8 @@ public class LoadPeriodsStepTest extends BaseStepTest {
 
     underTest.execute();
 
-    assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Leak period is set to deprecated value 'previous_analysis'. This value will be removed in next SonarQube LTS, please use another one instead.");
+    assertThat(logTester.logs(LoggerLevel.WARN))
+      .containsOnly("Leak period is set to deprecated value 'previous_analysis'. This value will be removed in next SonarQube LTS, please use another one instead.");
   }
 
   @Test
index b3f606a450e5ac8c4a3698ae396b103210f4d3f0..6264fc0c3d12cec78aa754515b03f83d0cb99ee6 100644 (file)
@@ -29,17 +29,17 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
 import org.sonar.server.computation.dbcleaner.ProjectCleaner;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.MutableDbIdsRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.component.MutableDisabledComponentsHolder;
 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
 import org.sonar.server.computation.task.step.ComputationStep;
@@ -47,9 +47,9 @@ import org.sonar.server.util.WrapInSingleElementArray;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyList;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -68,10 +68,11 @@ public class PurgeDatastoresStepTest extends BaseStepTest {
   public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.standalone();
 
   private ProjectCleaner projectCleaner = mock(ProjectCleaner.class);
-  private SettingsRepository settingsRepository = mock(SettingsRepository.class);
+  private ConfigurationRepository settingsRepository = mock(ConfigurationRepository.class);
   private MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
 
-  private PurgeDatastoresStep underTest = new PurgeDatastoresStep(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS), projectCleaner, dbIdsRepository, treeRootHolder, settingsRepository, disabledComponentsHolder);
+  private PurgeDatastoresStep underTest = new PurgeDatastoresStep(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS), projectCleaner, dbIdsRepository, treeRootHolder,
+    settingsRepository, disabledComponentsHolder);
 
   @Test
   public void call_purge_method_of_the_purge_task_for_project() {
@@ -133,22 +134,22 @@ public class PurgeDatastoresStepTest extends BaseStepTest {
 
   private void verify_call_purge_method_of_the_purge_task(Component project) {
     treeRootHolder.setRoot(project);
-    when(settingsRepository.getSettings(project)).thenReturn(new MapSettings());
+    when(settingsRepository.getConfiguration(project)).thenReturn(new MapSettings().asConfig());
     dbIdsRepository.setComponentId(project, PROJECT_ID);
 
     underTest.execute();
 
     ArgumentCaptor<IdUuidPair> argumentCaptor = ArgumentCaptor.forClass(IdUuidPair.class);
-    verify(projectCleaner).purge(any(DbSession.class), argumentCaptor.capture(), any(Settings.class), anyList());
+    verify(projectCleaner).purge(any(DbSession.class), argumentCaptor.capture(), any(Configuration.class), anyList());
     assertThat(argumentCaptor.getValue().getId()).isEqualTo(PROJECT_ID);
     assertThat(argumentCaptor.getValue().getUuid()).isEqualTo(PROJECT_UUID);
   }
 
   private static Object[][] dataproviderFromComponentTypeValues(Predicate<Component.Type> predicate) {
     return FluentIterable.from(asList(Component.Type.values()))
-        .filter(predicate)
-        .transform(WrapInSingleElementArray.INSTANCE)
-        .toArray(Object[].class);
+      .filter(predicate)
+      .transform(WrapInSingleElementArray.INSTANCE)
+      .toArray(Object[].class);
   }
 
   @Override
index f33bb6fea8dac70dc95bb01a57d135cd68dbe1d6..7e671ffe00e5f1a53e14469e20cf6cb850452ad4 100644 (file)
@@ -26,8 +26,8 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.VisitException;
 import org.sonar.server.computation.task.projectanalysis.qualitygate.Condition;
@@ -55,7 +55,7 @@ public class QualityGateLoadingStepTest {
   @Rule
   public MutableQualityGateHolderRule mutableQualityGateHolder = new MutableQualityGateHolderRule();
 
-  private SettingsRepository settingsRepository = mock(SettingsRepository.class);
+  private ConfigurationRepository settingsRepository = mock(ConfigurationRepository.class);
   private QualityGateService qualityGateService = mock(QualityGateService.class);
 
   private LoadQualityGateStep underTest = new LoadQualityGateStep(treeRootHolder, settingsRepository, qualityGateService, mutableQualityGateHolder);
@@ -64,14 +64,14 @@ public class QualityGateLoadingStepTest {
   public void execute_sets_default_QualityGate_when_project_has_no_settings() {
     ReportComponent root = ReportComponent.builder(Component.Type.PROJECT, 1).setKey(PROJECT_KEY).addChildren(ReportComponent.builder(Component.Type.FILE, 2).build()).build();
     treeRootHolder.setRoot(root);
-    when(settingsRepository.getSettings(root)).thenReturn(new MapSettings());
+    when(settingsRepository.getConfiguration(root)).thenReturn(new MapSettings().asConfig());
 
     underTest.execute();
 
     verifyNoQualityGate();
 
     // verify only project is processed
-    verify(settingsRepository).getSettings(root);
+    verify(settingsRepository).getConfiguration(root);
     verifyNoMoreInteractions(settingsRepository);
   }
 
@@ -83,7 +83,7 @@ public class QualityGateLoadingStepTest {
         .andMessage(format("Unsupported value (%s) in property sonar.qualitygate", "10 sds")));
 
     treeRootHolder.setRoot(PROJECT_ALONE);
-    when(settingsRepository.getSettings(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", "10 sds"));
+    when(settingsRepository.getConfiguration(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", "10 sds").asConfig());
 
     underTest.execute();
   }
@@ -91,7 +91,7 @@ public class QualityGateLoadingStepTest {
   @Test
   public void execute_sets_default_QualityGate_if_it_can_not_be_found_by_service() {
     treeRootHolder.setRoot(PROJECT_ALONE);
-    when(settingsRepository.getSettings(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10));
+    when(settingsRepository.getConfiguration(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10).asConfig());
     when(qualityGateService.findById(10)).thenReturn(Optional.<QualityGate>absent());
 
     underTest.execute();
@@ -104,7 +104,7 @@ public class QualityGateLoadingStepTest {
     QualityGate qualityGate = new QualityGate(465, "name", Collections.<Condition>emptyList());
 
     treeRootHolder.setRoot(PROJECT_ALONE);
-    when(settingsRepository.getSettings(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10));
+    when(settingsRepository.getConfiguration(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10).asConfig());
     when(qualityGateService.findById(10)).thenReturn(Optional.of(qualityGate));
 
     underTest.execute();
index 5592797964e4ca52fbf3971ccd02201f5eb8753a..5685f9fd0643f3f277ade971fe7540db302a188b 100644 (file)
@@ -172,6 +172,6 @@ public class WebhookCallerImplTest {
 
   private WebhookCaller newSender() {
     SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER);
-    return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings(), runtime));
+    return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), runtime));
   }
 }
index 14d69d2c41b1057450946b1d05ed3a502d651ee5..c630e803d16b10c7e425c09bf965149e06bcbd03 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.ce.posttask.PostProjectAnalysisTaskTester;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
+import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TestSettingsRepository;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 
@@ -130,7 +130,7 @@ public class WebhookPostTaskTest {
   }
 
   private void execute() {
-    SettingsRepository settingsRepository = new TestSettingsRepository(settings);
+    ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
     WebhookPostTask task = new WebhookPostTask(rootHolder, settingsRepository, payloadFactory, caller, deliveryStorage);
 
     PostProjectAnalysisTaskTester.of(task)
index b31e8864491b7ebdb0cf262b0b83193846ede4d8..62f15d002ff1151bcac3d260b32ab036151bb94c 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -44,7 +43,7 @@ public class EsClientProviderTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private EsClientProvider underTest = new EsClientProvider();
   private String localhost;
 
@@ -62,7 +61,7 @@ public class EsClientProviderTest {
     settings.setProperty(ProcessProperties.SEARCH_HOST, localhost);
     settings.setProperty(ProcessProperties.SEARCH_PORT, 8080);
 
-    EsClient client = underTest.provide(settings);
+    EsClient client = underTest.provide(settings.asConfig());
     TransportClient transportClient = (TransportClient) client.nativeClient();
     assertThat(transportClient.transportAddresses()).hasSize(1);
     TransportAddress address = transportClient.transportAddresses().get(0);
@@ -71,7 +70,7 @@ public class EsClientProviderTest {
     assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [" + localhost + ":8080]"), ""));
 
     // keep in cache
-    assertThat(underTest.provide(settings)).isSameAs(client);
+    assertThat(underTest.provide(settings.asConfig())).isSameAs(client);
   }
 
   @Test
@@ -80,7 +79,7 @@ public class EsClientProviderTest {
     settings.setProperty(ProcessProperties.CLUSTER_SEARCH_DISABLED, true);
     settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s:8080,%s:8081", localhost, localhost));
 
-    EsClient client = underTest.provide(settings);
+    EsClient client = underTest.provide(settings.asConfig());
     TransportClient transportClient = (TransportClient) client.nativeClient();
     assertThat(transportClient.transportAddresses()).hasSize(2);
     TransportAddress address = transportClient.transportAddresses().get(0);
@@ -92,7 +91,7 @@ public class EsClientProviderTest {
     assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [" + localhost + ":8080, " + localhost + ":8081]"), ""));
 
     // keep in cache
-    assertThat(underTest.provide(settings)).isSameAs(client);
+    assertThat(underTest.provide(settings.asConfig())).isSameAs(client);
   }
 
   @Test
@@ -104,18 +103,19 @@ public class EsClientProviderTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage(format("Port number out of range: %s:100000", localhost));
 
-    underTest.provide(settings);
+    underTest.provide(settings.asConfig());
   }
 
   @Test
   public void es_client_provider_must_throw_ISE_when_incorrect_port_is_used() throws Exception {
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
+    settings.setProperty(ProcessProperties.SEARCH_HOST, "localhost");
     settings.setProperty(ProcessProperties.SEARCH_PORT, "100000");
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Port out of range: 100000");
 
-    underTest.provide(settings);
+    underTest.provide(settings.asConfig());
   }
 
   @Test
@@ -124,7 +124,7 @@ public class EsClientProviderTest {
     settings.setProperty(ProcessProperties.CLUSTER_SEARCH_DISABLED, true);
     settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s,%s:8081", localhost, localhost));
 
-    EsClient client = underTest.provide(settings);
+    EsClient client = underTest.provide(settings.asConfig());
     TransportClient transportClient = (TransportClient) client.nativeClient();
     assertThat(transportClient.transportAddresses()).hasSize(2);
     TransportAddress address = transportClient.transportAddresses().get(0);
@@ -136,6 +136,6 @@ public class EsClientProviderTest {
     assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [" + localhost + ":9001, " + localhost + ":8081]"), ""));
 
     // keep in cache
-    assertThat(underTest.provide(settings)).isSameAs(client);
+    assertThat(underTest.provide(settings.asConfig())).isSameAs(client);
   }
 }
index 00bb513b2009532269d3f99b3da051b916032ad9..2eb1269121a34e1a05d3896208fa33a7343650e7 100644 (file)
@@ -46,6 +46,7 @@ import org.elasticsearch.node.NodeBuilder;
 import org.elasticsearch.search.SearchHit;
 import org.junit.rules.ExternalResource;
 import org.sonar.api.config.internal.MapSettings;
+import org.sonar.core.config.ConfigurationProvider;
 import org.sonar.core.platform.ComponentContainer;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -69,6 +70,7 @@ public class EsTester extends ExternalResource {
     if (!indexDefinitions.isEmpty()) {
       container = new ComponentContainer();
       container.addSingleton(new MapSettings());
+      container.addSingleton(new ConfigurationProvider());
       container.addSingletons(indexDefinitions);
       container.addSingleton(client);
       container.addSingleton(IndexDefinitions.class);
index 72ba6c74e7a7fed28af61fb83d11f0e78fdd4215..cb4c73c9c5a7a91c7cc4321d830f1bafe52f8da0 100644 (file)
@@ -40,7 +40,7 @@ public class IndexCreatorTest {
   public void create_index() throws Exception {
     assertThat(mappings()).isEmpty();
 
-    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinition()}, new MapSettings());
+    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinition()}, new MapSettings().asConfig());
     registry.start();
     IndexCreator creator = new IndexCreator(es.client(), registry);
     creator.start();
@@ -65,7 +65,7 @@ public class IndexCreatorTest {
     assertThat(mappings()).isEmpty();
 
     // v1
-    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinition()}, new MapSettings());
+    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinition()}, new MapSettings().asConfig());
     registry.start();
     IndexCreator creator = new IndexCreator(es.client(), registry);
     creator.start();
@@ -74,7 +74,7 @@ public class IndexCreatorTest {
     assertThat(hashV1).isNotEmpty();
 
     // v2
-    registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinitionV2()}, new MapSettings());
+    registry = new IndexDefinitions(new IndexDefinition[] {new FakeIndexDefinitionV2()}, new MapSettings().asConfig());
     registry.start();
     creator = new IndexCreator(es.client(), registry);
     creator.start();
index 9b42bc4311417f84ce1effdc84564e555a3e769b..ddce70f478ff7b3b3d0a0621143dd06b2cd04af6 100644 (file)
@@ -87,6 +87,6 @@ public class IndexerStartupTaskTest {
   }
 
   private void emulateStartup(StartupIndexer indexer) {
-    new IndexerStartupTask(es.client(), settings, indexer).execute();
+    new IndexerStartupTask(es.client(), settings.asConfig(), indexer).execute();
   }
 }
index 4f9c787a8ac8cd8958baf95ff3f24f788a081286..f9e119a1b122aea897222464427722fca0cb0100 100644 (file)
@@ -159,7 +159,7 @@ public class NewIndexTest {
   @Test
   public void default_shards_and_replicas() {
     NewIndex index = new NewIndex("issues");
-    index.configureShards(new MapSettings(), 5);
+    index.configureShards(new MapSettings().asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("5");
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
   }
@@ -169,7 +169,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("5");
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("1");
   }
@@ -179,7 +179,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty("sonar.search.issues.shards", "3");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("3");
     // keep default value
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
@@ -189,7 +189,7 @@ public class NewIndexTest {
   public void default_number_of_replicas_on_standalone_instance_must_be_0() {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
   }
 
@@ -198,7 +198,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, "false");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
   }
 
@@ -207,7 +207,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("1");
   }
 
@@ -217,7 +217,7 @@ public class NewIndexTest {
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
     settings.setProperty(ProcessProperties.SEARCH_REPLICAS, "0");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
   }
 
@@ -226,7 +226,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.SEARCH_REPLICAS, "3");
-    index.configureShards(settings, 5);
+    index.configureShards(settings.asConfig(), 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("3");
   }
 
@@ -266,8 +266,8 @@ public class NewIndexTest {
 
     // authorization type
     NewIndex.NewIndexType authorizationType = index.getTypes().get("authorization");
-    assertThat(getAttributeAsMap(authorizationType,"_parent")).isNull();
-    assertThat(getAttributeAsMap(authorizationType,"_routing")).containsExactly(entry("required", true));
+    assertThat(getAttributeAsMap(authorizationType, "_parent")).isNull();
+    assertThat(getAttributeAsMap(authorizationType, "_routing")).containsExactly(entry("required", true));
   }
 
   private static Map<String, Object> getAttributeAsMap(NewIndex.NewIndexType type, String attributeKey) {
index 0769a2c5b8a0e355e4529367cb562f1c4b5f0e27..465d7ac0ca06c9cd55e87335a75c56d38ce8163c 100644 (file)
@@ -70,7 +70,7 @@ public class IssueUpdaterTest {
   public DbTester dbTester = DbTester.create(system2);
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
 
   private DbClient dbClient = dbTester.getDbClient();
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
index 24bc6f65dabb665f2a58be83dff5485743304f65..0376accdf4e8182d30bb3d8d2830a71619550d43 100644 (file)
@@ -59,7 +59,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT
 public class IssueIndexDebtTest {
 
   @Rule
-  public EsTester tester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
+  public EsTester tester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()), new ViewIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
index ed7045f351c345fc802a227d0e465d86f8d45269..6beb40197eb85817f2bcc3f0434dabb9930d2a5a 100644 (file)
@@ -32,7 +32,7 @@ public class IssueIndexDefinitionTest {
 
   @Test
   public void define() {
-    IssueIndexDefinition def = new IssueIndexDefinition(new MapSettings());
+    IssueIndexDefinition def = new IssueIndexDefinition(new MapSettings().asConfig());
     def.define(underTest);
 
     assertThat(underTest.getIndices()).hasSize(1);
index 3a74e53b93ea951e1f53279e30c5d82f8644942b..1e9dcb16efafd3771ae4ca2020a3bea520b5eca4 100644 (file)
@@ -84,9 +84,9 @@ public class IssueIndexTest {
 
   @Rule
   public EsTester tester = new EsTester(
-    new IssueIndexDefinition(new MapSettings()),
-    new ViewIndexDefinition(new MapSettings()),
-    new RuleIndexDefinition(new MapSettings()));
+    new IssueIndexDefinition(new MapSettings().asConfig()),
+    new ViewIndexDefinition(new MapSettings().asConfig()),
+    new RuleIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
index 77c4f20a4a6fea5dbeb80d61b4e963cbf89e6ccc..410aae889c6ab3d7f09db84eb5150d45cb20fd9e 100644 (file)
@@ -55,7 +55,7 @@ public class IssueIndexerTest {
   private System2 system2 = System2.INSTANCE;
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester dbTester = DbTester.create(system2);
   @Rule
index 04f7992bcaa4b91f03bd7c0e1546aa487711c829..544c2304213728bc0141d72be09f6413530e5fd3 100644 (file)
@@ -25,7 +25,6 @@ import org.apache.commons.lang.StringUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.EmailSettings;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.notifications.Notification;
 import org.sonar.db.DbTester;
@@ -40,9 +39,9 @@ public class IssueChangesEmailTemplateTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private Settings settings = new MapSettings().setProperty(SERVER_BASE_URL, "http://nemo.sonarsource.org");
+  private MapSettings settings = new MapSettings().setProperty(SERVER_BASE_URL, "http://nemo.sonarsource.org");
 
-  private IssueChangesEmailTemplate underTest = new IssueChangesEmailTemplate(db.getDbClient(), new EmailSettings(settings));
+  private IssueChangesEmailTemplate underTest = new IssueChangesEmailTemplate(db.getDbClient(), new EmailSettings(settings.asConfig()));
 
   @Test
   public void should_ignore_non_issue_changes() {
index 738bc7d340257c195c82211a7ab6fca7965a2f56..d4b849abaa455f6cb65b1f64d8f0597a10eb5e7d 100644 (file)
@@ -80,7 +80,7 @@ public class AddCommentActionTest {
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
index 0d96c89e57b6d06db214b666f5f62b332e45ab43..ef9e92ab163997b93b257be7a8c2aadc09be04c7 100644 (file)
@@ -75,7 +75,7 @@ public class AssignActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
-  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create(system2);
 
@@ -248,14 +248,14 @@ public class AssignActionTest {
   private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
     SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue();
     assertThat(preloadedSearchResponseData.getIssues())
-        .extracting(IssueDto::getKey)
-        .containsOnly(issue.getKey());
+      .extracting(IssueDto::getKey)
+      .containsOnly(issue.getKey());
     assertThat(preloadedSearchResponseData.getRules())
-        .extracting(RuleDefinitionDto::getKey)
-        .containsOnly(issue.getRuleKey());
+      .extracting(RuleDefinitionDto::getKey)
+      .containsOnly(issue.getRuleKey());
     assertThat(preloadedSearchResponseData.getComponents())
-        .extracting(ComponentDto::uuid)
-        .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
+      .extracting(ComponentDto::uuid)
+      .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
   }
 
   private UserDto insertUser(String login) {
index 0fcd4dc71a3c467d7889c3880e5dc19854796883..64888625f323ff640c35cee860b88265bc1acfbd 100644 (file)
@@ -45,7 +45,7 @@ public class AuthorsActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index 792d7767f7fd1f604d344311c39af4229e833199..c31b901b5f6b68602152201575c5cf6a0aaeee38 100644 (file)
@@ -96,7 +96,7 @@ public class BulkChangeActionTest {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index f58f36c3cf4ed9436fa0871c581c4d048cda4cb9..81d7e0b682c3ecbf32ed6b0db296b07982f7902a 100644 (file)
@@ -86,7 +86,7 @@ public class DoTransitionActionTest {
   public DbTester dbTester = DbTester.create(system2);
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
@@ -201,14 +201,14 @@ public class DoTransitionActionTest {
   private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
     SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue();
     assertThat(preloadedSearchResponseData.getIssues())
-        .extracting(IssueDto::getKey)
-        .containsOnly(issue.getKey());
+      .extracting(IssueDto::getKey)
+      .containsOnly(issue.getKey());
     assertThat(preloadedSearchResponseData.getRules())
-        .extracting(RuleDefinitionDto::getKey)
-        .containsOnly(issue.getRuleKey());
+      .extracting(RuleDefinitionDto::getKey)
+      .containsOnly(issue.getRuleKey());
     assertThat(preloadedSearchResponseData.getComponents())
-        .extracting(ComponentDto::uuid)
-        .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
+      .extracting(ComponentDto::uuid)
+      .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
   }
 
 }
index 545a35bb029cac4b951f5c9baf6ef60f2e72f241..6cc8d39de358b09f07f7b9f0bec12e1257f57c98 100644 (file)
@@ -78,7 +78,7 @@ public class SetSeverityActionTest {
   @Rule
   public DbTester dbTester = DbTester.create();
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index 2016cd557178b1ed28029065daefc819a9c824ed..b30f4b72b6911fe7489bdf9d8c639fce71d0130d 100644 (file)
@@ -77,7 +77,7 @@ public class SetTagsActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index d396dbc6f292a18b9fdb7fe6e33a4f116da310c7..efc09708b1044b25435025576d9db3e3230b096a 100644 (file)
@@ -78,7 +78,7 @@ public class SetTypeActionTest {
   @Rule
   public DbTester dbTester = DbTester.create();
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index 660f40738b7cdab00133bcd00ff68daab529fc2a..f93118a2b02df77b81acbabd05cc1f4a130e3ec4 100644 (file)
@@ -61,7 +61,7 @@ public class TagsActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()), new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()), new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private IssueIndexer issueIndexer = new IssueIndexer(es.client(), new IssueIteratorFactory(db.getDbClient()));
   private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
index d70cdb9ed27654d94829dc550819ec0bdc7bc8d4..7a5991c91b7a7f4aa09fd009b7896e4956fe2785 100644 (file)
@@ -74,7 +74,7 @@ public class CreateActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   DbClient dbClient = db.getDbClient();
   ComponentDto project;
index c0987df1b4fe671a401ca4438461f3c7974aae95..9a393e6a1cc5fc7ba376a98fc1302912938a3536 100644 (file)
@@ -54,7 +54,7 @@ public class MetricsActionTest {
   private static final String DEFAULT_PROJECT_KEY = "project-key";
 
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
index 04f01197b67a3ec8beef3866cee360b4f1790fc0..e451752ceb628e10c798b3caa1b4eee9d1693192 100644 (file)
@@ -66,7 +66,7 @@ public class SearchActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   WsTester ws;
   DbClient dbClient = db.getDbClient();
index 35110f592cca9b2f2afe470acef61eb61da8ef40..d74c286d39465bdc81c8ab37919bc60ed9e97dd4 100644 (file)
@@ -65,7 +65,7 @@ public class UpdateActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   private DbClient dbClient = db.getDbClient();
   private DbSession dbSession = db.getSession();
index c7cc1c68a696886d3ff5e621a2c239a8ca8aefd4..e078cfe193e1c660e3d2c04d11679a9ce1568e97 100644 (file)
@@ -96,7 +96,7 @@ public class ProjectMeasuresIndexTest {
   private static final GroupDto GROUP2 = newGroupDto();
 
   @Rule
-  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
index 44b249c934e077c970ea9761eeb284f9866204b6..a733d4a3887b4aa91a2d48df2e07b5742067aa83 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.Facets;
 import org.sonar.server.es.SearchOptions;
+import org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion;
 import org.sonar.server.permission.index.AuthorizationTypeSupport;
 import org.sonar.server.permission.index.PermissionIndexerDao;
 import org.sonar.server.permission.index.PermissionIndexerTester;
@@ -47,7 +48,6 @@ import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.component.ws.FilterParser.Operator.GT;
 import static org.sonar.server.component.ws.FilterParser.Operator.LT;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES;
-import static org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion;
 
 public class ProjectMeasuresIndexTextSearchTest {
 
@@ -56,7 +56,7 @@ public class ProjectMeasuresIndexTextSearchTest {
   private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto();
 
   @Rule
-  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
index 2612e8b5c5b3904b5b37562d53c2d2b4f4d56c4e..b237231746b8264c2f4f99bea882a31440c964b8 100644 (file)
@@ -54,7 +54,7 @@ public class ProjectMeasuresIndexerTest {
   private System2 system2 = System2.INSTANCE;
 
   @Rule
-  public EsTester esTester = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester dbTester = DbTester.create(system2);
index c03a81c8f31e782165a6e05d845bf2f6216be8a8..95cd0ec15eb5a1d82a93d4a69f9f7f2928e21306 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
+import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.notifications.Notification;
@@ -32,12 +33,12 @@ import org.sonar.db.DbClient;
 import org.sonar.db.property.PropertiesDao;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.same;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
@@ -56,7 +57,7 @@ public class NotificationDaemonTest {
   private NotificationDispatcher commentOnIssueCreatedByMe = mock(NotificationDispatcher.class);
   private NotificationDispatcher qualityGateChange = mock(NotificationDispatcher.class);
   private DbClient dbClient = mock(DbClient.class);
-  private NotificationService service = new NotificationService(dbClient, new NotificationDispatcher[]{commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange});
+  private NotificationService service = new NotificationService(dbClient, new NotificationDispatcher[] {commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange});
   private NotificationDaemon underTest = null;
 
   private void setUpMocks() {
@@ -70,9 +71,9 @@ public class NotificationDaemonTest {
     when(qualityGateChange.getType()).thenReturn("qgate-changes");
     when(manager.getFromQueue()).thenReturn(notification).thenReturn(null);
 
-    Settings settings = new MapSettings().setProperty("sonar.notifications.delay", 1L);
+    MapSettings settings = new MapSettings(new PropertyDefinitions(NotificationDaemon.class)).setProperty("sonar.notifications.delay", 1L);
 
-    underTest = new NotificationDaemon(settings, manager, service);
+    underTest = new NotificationDaemon(settings.asConfig(), manager, service);
   }
 
   /**
@@ -137,7 +138,7 @@ public class NotificationDaemonTest {
   @Test
   public void scenario3() {
     setUpMocks();
-    doAnswer(addUser(ASSIGNEE_SIMON, new NotificationChannel[]{emailChannel, gtalkChannel}))
+    doAnswer(addUser(ASSIGNEE_SIMON, new NotificationChannel[] {emailChannel, gtalkChannel}))
       .when(commentOnIssueAssignedToMe).dispatch(same(notification), any(NotificationDispatcher.Context.class));
 
     underTest.start();
@@ -244,7 +245,7 @@ public class NotificationDaemonTest {
   }
 
   private static Answer<Object> addUser(final String user, final NotificationChannel channel) {
-    return addUser(user, new NotificationChannel[]{channel});
+    return addUser(user, new NotificationChannel[] {channel});
   }
 
   private static Answer<Object> addUser(final String user, final NotificationChannel[] channels) {
index b0d17f73fff8b3cb1e3166a8b3ddb6b70bdd8b4f..44e487ffc9f49f466157b91221ef663cb7010ad2 100644 (file)
@@ -89,7 +89,7 @@ public class OrganizationCreationImplTest {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
@@ -105,7 +105,7 @@ public class OrganizationCreationImplTest {
   private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private UserIndex userIndex = new UserIndex(es.client());
   private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient);
-  private OrganizationCreationImpl underTest = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings, userIndexer,
+  private OrganizationCreationImpl underTest = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings.asConfig(), userIndexer,
     builtInQProfileRepositoryRule, defaultGroupCreator);
 
   private UserDto someUser;
index f55ef8e42bcb0efc077dcdf5c47d1cc53b7f0f25..d5aa40abea1882f1a48f3149b8c41ca080d0c228 100644 (file)
@@ -67,7 +67,7 @@ public class AddMemberActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   private UserIndex userIndex = new UserIndex(es.client());
   @Rule
   public DbTester db = DbTester.create();
index b54c7c0d4c5bd98b21ef6c729bf430ee3255e24b..7d7d33f10d9bd1ef22da5ac643c510ccf5faffb5 100644 (file)
@@ -28,7 +28,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
@@ -56,7 +55,6 @@ import org.sonar.server.organization.OrganizationValidation;
 import org.sonar.server.organization.OrganizationValidationImpl;
 import org.sonar.server.organization.TestOrganizationFlags;
 import org.sonar.server.qualityprofile.BuiltInQProfileRepository;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
@@ -88,25 +86,25 @@ public class CreateActionTest {
   @Rule
   public DbTester dbTester = DbTester.create(system2).setDisableDefaultOrganization(true);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
   private DbClient dbClient = dbTester.getDbClient();
   private DbSession dbSession = dbTester.getSession();
-  private Settings settings = new MapSettings()
+  private MapSettings settings = new MapSettings()
     .setProperty(ORGANIZATIONS_ANYONE_CAN_CREATE, false);
   private UuidFactory uuidFactory = mock(UuidFactory.class);
   private OrganizationValidation organizationValidation = new OrganizationValidationImpl();
   private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
   private UserIndex userIndex = new UserIndex(es.client());
-  private OrganizationCreation organizationCreation = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings, userIndexer,
+  private OrganizationCreation organizationCreation = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings.asConfig(), userIndexer,
     mock(BuiltInQProfileRepository.class), new DefaultGroupCreatorImpl(dbClient));
   private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone().setEnabled(true);
 
   private UserDto user;
 
-  private CreateAction underTest = new CreateAction(settings, userSession, dbClient, new OrganizationsWsSupport(organizationValidation), organizationValidation,
+  private CreateAction underTest = new CreateAction(settings.asConfig(), userSession, dbClient, new OrganizationsWsSupport(organizationValidation), organizationValidation,
     organizationCreation, organizationFlags);
 
   private WsActionTester wsTester = new WsActionTester(underTest);
index e075709858afa149d7691b5474cdc6ff3fb709df..903c7fcd16a438aea0da37ac8976d4e165e3801d 100644 (file)
@@ -71,7 +71,7 @@ public class DeleteActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
index 025c354a88c2cc2255f01fb49c9f7399e6798423..c925621cab5e53854797bda8e0702a9dfc931b5d 100644 (file)
@@ -71,7 +71,7 @@ public class RemoveMemberActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create();
   private DbClient dbClient = db.getDbClient();
index 215c224ce70a1b3b119454c4261b3f42fbdb709a..db4e01c6fbb6cdde22a7e08f4e52b3eb987ef938 100644 (file)
@@ -61,7 +61,7 @@ public class SearchMembersActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester db = DbTester.create();
index d04803cf455111be18c5403d3d92c3d0af705999..9e26c7087ce55540919f7d71f69ceec96be9aac5 100644 (file)
@@ -49,11 +49,11 @@ public class BackendCleanupTest {
 
   @Rule
   public EsTester esTester = new EsTester(
-    new RuleIndexDefinition(new MapSettings()),
-    new IssueIndexDefinition(new MapSettings()),
-    new ViewIndexDefinition(new MapSettings()),
-    new ProjectMeasuresIndexDefinition(new MapSettings()),
-    new ComponentIndexDefinition(new MapSettings()));
+    new RuleIndexDefinition(new MapSettings().asConfig()),
+    new IssueIndexDefinition(new MapSettings().asConfig()),
+    new ViewIndexDefinition(new MapSettings().asConfig()),
+    new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()),
+    new ComponentIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
index 6968ccac511d053ea1fffa0138d94d783a79a526..0289e76b7fe7eda0ab219debd70bbd2e7999d68d 100644 (file)
  */
 package org.sonar.server.platform;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -37,9 +36,9 @@ public class ServerIdLoaderTest {
   private static final String AN_IP = "1.2.3.4";
   public static final String AN_ORGANIZATION = "corp";
 
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
   ServerIdGenerator idGenerator = mock(ServerIdGenerator.class);
-  ServerIdLoader underTest = new ServerIdLoader(settings, idGenerator);
+  ServerIdLoader underTest = new ServerIdLoader(settings.asConfig(), idGenerator);
 
   @Test
   public void get_returns_absent_if_id_property_is_not_set() {
@@ -47,7 +46,7 @@ public class ServerIdLoaderTest {
     settings.setProperty(CoreProperties.SERVER_ID_IP_ADDRESS, AN_IP);
 
     Optional<ServerId> serverIdOpt = underTest.get();
-    assertThat(serverIdOpt.isPresent()).isFalse();
+    assertThat(serverIdOpt).isEmpty();
     verifyZeroInteractions(idGenerator);
   }
 
index 6fea447e18386f17511f47da77c52c27897f3e41..55c66fd3a5334a22deea7619a8f99782ed5fade2 100644 (file)
@@ -26,7 +26,6 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.Version;
 
@@ -36,12 +35,12 @@ import static org.mockito.Mockito.when;
 
 public class ServerImplTest {
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private StartupMetadata state = mock(StartupMetadata.class);
   private ServerFileSystem fs = mock(ServerFileSystem.class);
   private UrlSettings urlSettings = mock(UrlSettings.class);
   private SonarRuntime runtime = mock(SonarRuntime.class);
-  private ServerImpl underTest = new ServerImpl(settings, state, fs, urlSettings, runtime);
+  private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, fs, urlSettings, runtime);
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
index d001c95631eda80f166a351d6f2caf69ffac3db4..92aa85e3fa18caea083840c2e15e5ff21078e0ca 100644 (file)
@@ -30,7 +30,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -54,8 +53,8 @@ public class ServerLoggingTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   private LogbackHelper logbackHelper = spy(new LogbackHelper());
-  private Settings settings = new MapSettings();
-  private ServerLogging underTest = new ServerLogging(logbackHelper, settings);
+  private MapSettings settings = new MapSettings();
+  private ServerLogging underTest = new ServerLogging(logbackHelper, settings.asConfig());
 
   @Rule
   public LogTester logTester = new LogTester();
index cf1e60766ce92b276c89fd468e039be5a9571b5d..4e76ae97040dd2142544f74d102168290d7941f8 100644 (file)
@@ -23,7 +23,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.core.config.CorePropertyDefinitions;
 
@@ -39,7 +38,7 @@ public class UrlSettingsTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Settings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
+  private MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
 
   @Test
   public void use_default_context_path() {
@@ -163,10 +162,10 @@ public class UrlSettingsTest {
   }
 
   @Test
-  public void getBaseUrl_throws_NFE_when_port_not_an_int() {
+  public void getBaseUrl_throws_when_port_not_an_int() {
     settings.setProperty(PORT_PORPERTY, "not a number");
 
-    expectedException.expect(NumberFormatException.class);
+    expectedException.expect(IllegalStateException.class);
     underTest().getBaseUrl();
   }
 
@@ -195,6 +194,6 @@ public class UrlSettingsTest {
   }
 
   private UrlSettings underTest() {
-    return new UrlSettings(settings);
+    return new UrlSettings(settings.asConfig());
   }
 }
index 33b32974b5a53e4cc26af69ff4b031f2d2806df7..554dd8ac3036fb70509c4d5d5769d98aec5c057b 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.platform.cluster;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -32,11 +31,11 @@ public class ClusterImplTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   @Test
   public void cluster_is_disabled_by_default() {
-    ClusterImpl underTest = new ClusterImpl(settings);
+    ClusterImpl underTest = new ClusterImpl(settings.asConfig());
 
     assertThat(underTest.isEnabled()).isFalse();
     assertThat(underTest.isStartupLeader()).isTrue();
@@ -47,7 +46,7 @@ public class ClusterImplTest {
     settings.setProperty("sonar.cluster.enabled", "true");
     settings.setProperty("sonar.cluster.web.startupLeader", "true");
 
-    ClusterImpl underTest = new ClusterImpl(settings);
+    ClusterImpl underTest = new ClusterImpl(settings.asConfig());
 
     assertThat(underTest.isEnabled()).isTrue();
     assertThat(underTest.isStartupLeader()).isTrue();
@@ -57,7 +56,7 @@ public class ClusterImplTest {
   public void node_is_startup_follower_by_default_in_cluster() {
     settings.setProperty("sonar.cluster.enabled", "true");
 
-    ClusterImpl underTest = new ClusterImpl(settings);
+    ClusterImpl underTest = new ClusterImpl(settings.asConfig());
 
     assertThat(underTest.isEnabled()).isTrue();
     assertThat(underTest.isStartupLeader()).isFalse();
@@ -68,7 +67,7 @@ public class ClusterImplTest {
     settings.setProperty("sonar.cluster.enabled", "true");
     settings.setProperty("sonar.cluster.web.startupLeader", "false");
 
-    ClusterImpl underTest = new ClusterImpl(settings);
+    ClusterImpl underTest = new ClusterImpl(settings.asConfig());
 
     assertThat(underTest.isEnabled()).isTrue();
     assertThat(underTest.isStartupLeader()).isFalse();
index d88d4b4467f22d1f15795363980b535cf858d3e0..b147df1439eefac34c5fa7e7fee26a0ad1f789ce 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.platform.db;
 
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.database.DatabaseProperties;
 import org.sonar.api.utils.System2;
@@ -31,7 +30,7 @@ import static org.mockito.Mockito.verify;
 
 public class EmbeddedDatabaseFactoryTest {
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private System2 system2 = mock(System2.class);
 
   @Test
@@ -40,7 +39,7 @@ public class EmbeddedDatabaseFactoryTest {
 
     EmbeddedDatabase embeddedDatabase = mock(EmbeddedDatabase.class);
 
-    EmbeddedDatabaseFactory databaseFactory = new EmbeddedDatabaseFactory(settings, system2) {
+    EmbeddedDatabaseFactory databaseFactory = new EmbeddedDatabaseFactory(settings.asConfig(), system2) {
       @Override
       EmbeddedDatabase createEmbeddedDatabase() {
         return embeddedDatabase;
@@ -59,7 +58,7 @@ public class EmbeddedDatabaseFactoryTest {
 
     EmbeddedDatabase embeddedDatabase = mock(EmbeddedDatabase.class);
 
-    EmbeddedDatabaseFactory databaseFactory = new EmbeddedDatabaseFactory(settings, system2) {
+    EmbeddedDatabaseFactory databaseFactory = new EmbeddedDatabaseFactory(settings.asConfig(), system2) {
       @Override
       EmbeddedDatabase createEmbeddedDatabase() {
         return embeddedDatabase;
index bdbd0f4ae064e0386107738b688de6c547a3b11a..f9190c373e8f58270c8bba1e6c665c035502e1dd 100644 (file)
@@ -62,7 +62,7 @@ public class EmbeddedDatabaseTest {
 
   private MapSettings settings = new MapSettings();
   private System2 system2 = mock(System2.class);
-  private EmbeddedDatabase underTest = new EmbeddedDatabase(settings, system2);
+  private EmbeddedDatabase underTest = new EmbeddedDatabase(settings.asConfig(), system2);
 
   @After
   public void tearDown() throws Exception {
index b2b5da6461c5d2d9b1e3d746c2d03fbf7e8ba7d3..0230612bdefcc979e52286678e1762e06d737fea 100644 (file)
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
 public class EsMonitorTest {
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
 
   private EsMonitor underTest = new EsMonitor(esTester.client());
 
index cd0f60d7d4842e6c6b7ec6cb5ab5a8e9b2d7011a..e967f10d8de41cd57b3dccb92c7e4740ce7c7629 100644 (file)
  */
 package org.sonar.server.platform.monitoring;
 
-import com.google.common.base.Optional;
 import java.io.File;
 import java.util.Map;
+import java.util.Optional;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.platform.Server;
 import org.sonar.api.security.SecurityRealm;
@@ -41,7 +40,6 @@ import org.sonar.server.user.SecurityRealmFactory;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.data.MapEntry.entry;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -56,18 +54,20 @@ public class SonarQubeMonitorTest {
   @Rule
   public IdentityProviderRepositoryRule identityProviderRepository = new IdentityProviderRepositoryRule();
 
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
   Server server = mock(Server.class);
-  ServerIdLoader serverIdLoader = mock(ServerIdLoader.class, RETURNS_DEEP_STUBS);
+  ServerIdLoader serverIdLoader = mock(ServerIdLoader.class);
   ServerLogging serverLogging = mock(ServerLogging.class);
   SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
 
-  SonarQubeMonitor underTest = new SonarQubeMonitor(settings, securityRealmFactory, identityProviderRepository, server,
+  SonarQubeMonitor underTest = new SonarQubeMonitor(settings.asConfig(), securityRealmFactory, identityProviderRepository, server,
     serverLogging, serverIdLoader);
 
   @Before
   public void setUp() throws Exception {
     when(serverLogging.getRootLoggerLevel()).thenReturn(LoggerLevel.DEBUG);
+    when(serverIdLoader.getRaw()).thenReturn(Optional.empty());
+    when(serverIdLoader.get()).thenReturn(Optional.empty());
   }
 
   @Test
@@ -80,7 +80,7 @@ public class SonarQubeMonitorTest {
     when(serverIdLoader.getRaw()).thenReturn(Optional.of("ABC"));
     assertThat(underTest.getServerId()).isEqualTo("ABC");
 
-    when(serverIdLoader.getRaw()).thenReturn(Optional.<String>absent());
+    when(serverIdLoader.getRaw()).thenReturn(Optional.<String>empty());
     assertThat(underTest.getServerId()).isNull();
   }
 
@@ -102,7 +102,7 @@ public class SonarQubeMonitorTest {
 
   @Test
   public void attributes_do_not_contain_information_about_server_id_if_absent() {
-    when(serverIdLoader.get()).thenReturn(Optional.<ServerId>absent());
+    when(serverIdLoader.get()).thenReturn(Optional.<ServerId>empty());
 
     Map<String, Object> attributes = underTest.attributes();
     assertThat(attributes).doesNotContainKeys(SERVER_ID_PROPERTY, SERVER_ID_VALIDATED_PROPERTY);
index 4de4e0684a9d007cf3d276ffb0221fb38ec7fdac..87195c8d5c6e0778cb571c2aad75a71e77e5d23e 100644 (file)
@@ -24,7 +24,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.InOrder;
 import org.mockito.Mockito;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -48,11 +47,11 @@ public class RestartActionTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private Platform platform = mock(Platform.class);
   private ProcessCommandWrapper processCommandWrapper = mock(ProcessCommandWrapper.class);
   private RestartFlagHolder restartFlagHolder = mock(RestartFlagHolder.class);
-  private RestartAction sut = new RestartAction(userSessionRule, settings, platform, processCommandWrapper, restartFlagHolder);
+  private RestartAction sut = new RestartAction(userSessionRule, settings.asConfig(), platform, processCommandWrapper, restartFlagHolder);
   private InOrder inOrder = Mockito.inOrder(platform, restartFlagHolder, processCommandWrapper);
 
   private WsActionTester actionTester = new WsActionTester(sut);
index dbef7febd4823c1270df7bd2f5b9fa4a9d2a7a7c..ab574a72946c57f8554358e94274cfc5e797165f 100644 (file)
 package org.sonar.server.platform.ws;
 
 import org.junit.Test;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.ce.http.CeHttpClient;
 import org.sonar.server.app.ProcessCommandWrapper;
 import org.sonar.server.app.RestartFlagHolder;
 import org.sonar.server.platform.Platform;
-import org.sonar.ce.http.CeHttpClient;
 import org.sonar.server.tester.AnonymousMockUserSession;
 import org.sonar.server.user.UserSession;
 
@@ -38,7 +38,8 @@ public class SystemWsTest {
 
   @Test
   public void define() {
-    RestartAction action1 = new RestartAction(mock(UserSession.class), mock(Settings.class), mock(Platform.class), mock(ProcessCommandWrapper.class), mock(RestartFlagHolder.class));
+    RestartAction action1 = new RestartAction(mock(UserSession.class), mock(Configuration.class), mock(Platform.class), mock(ProcessCommandWrapper.class),
+      mock(RestartFlagHolder.class));
     InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), ceHttpClient);
     SystemWs ws = new SystemWs(action1, action2);
     WebService.Context context = new WebService.Context();
index 8dab6dfd604bffc73713e8398e90576b3db34978..fc85da1e7dffc4ba93d61539b3dbb2a065a1132e 100644 (file)
@@ -24,7 +24,6 @@ import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.UriReader;
@@ -45,7 +44,7 @@ public class UpdateCenterClientTest {
 
   private static final String BASE_URL = "https://update.sonarsource.org";
   private UriReader reader = mock(UriReader.class);
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private UpdateCenterClient underTest;
 
   @Before
@@ -53,7 +52,7 @@ public class UpdateCenterClientTest {
     reader = mock(UriReader.class);
     settings.setProperty(UpdateCenterClient.URL_PROPERTY, BASE_URL);
     settings.setProperty(WebConstants.SONAR_UPDATECENTER_ACTIVATE, true);
-    underTest = new UpdateCenterClient(reader, settings);
+    underTest = new UpdateCenterClient(reader, settings.asConfig());
   }
 
   @Test
index 5b90603bbd41e10810a3e72b4a1788ecc71d87bb..ddf60c516891c6bd132d1c1ddbba8a8562fc8724 100644 (file)
@@ -77,8 +77,8 @@ public class BulkUpdateKeyActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
-  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()),
-    new ComponentIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()),
+    new ComponentIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create(system2);
 
index 3156a4fc7606f69424d9cf27cf9d24fb6bc05921..c4f39080a9d6d1e46124a2419c1bf37f864ff615 100644 (file)
@@ -55,7 +55,7 @@ public class SearchActionTest {
   private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto();
 
   @Rule
-  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
index c199fab75d23e553d6a70f0c36a83cc50ede6817..81efcf72ab663f4728242906e14e82e2bcfa1af4 100644 (file)
@@ -81,7 +81,7 @@ public class RuleActivatorTest {
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings()));
+  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   private RuleIndex ruleIndex = new RuleIndex(es.client());
@@ -113,7 +113,6 @@ public class RuleActivatorTest {
     RuleActivation activation = RuleActivation.create(rule.getKey(), BLOCKER, null);
     List<ActiveRuleChange> changes = activate(profile, activation);
 
-
     assertThatRuleIsActivated(profile, rule, changes, BLOCKER, null, emptyMap());
     assertThatProfileIsUpdatedByUser(profile);
   }
@@ -377,7 +376,6 @@ public class RuleActivatorTest {
     expectFailure("Value 'foo' must be an integer.", () -> activate(profile, activation));
   }
 
-
   @Test
   public void ignore_parameters_when_activating_custom_rule() {
     RuleDefinitionDto templateRule = db.rules().insert(r -> r.setIsTemplate(true));
index fd696cfac52fe15a3264537948a7e645ceb5551d..5c3094ccf5fc3ac0f8214bcf9c79eb4980140297 100644 (file)
@@ -51,7 +51,7 @@ public class ActiveRuleIndexerTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings()));
+  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings().asConfig()));
 
   private ActiveRuleIndexer underTest = new ActiveRuleIndexer(db.getDbClient(), es.client(), new ActiveRuleIteratorFactory(db.getDbClient()));
   private RuleDefinitionDto rule1;
index a67d0db9f6df8764d1a9f8a56d539c01d5078852..4416f3eb8a880f4ca8bfa0f2e89d99acb2e3860b 100644 (file)
@@ -81,7 +81,7 @@ public class ChangeParentActionTest {
   @Rule
   public DbTester dbTester = new DbTester(System2.INSTANCE, null);
   @Rule
-  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
index 480d0deddd006b8927837d3b707d21ef32369b67..8c560ae1b933975f6332b6e973596cfda7a3ceb1 100644 (file)
@@ -85,7 +85,7 @@ public class CreateActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
index 15ecc3c0bcd78d57bba2181a514c18281302fd6c..4e21a465e215d9af94cd6d5cc34a06504e4efc0b 100644 (file)
@@ -70,7 +70,7 @@ public class InheritanceActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
@@ -118,8 +118,7 @@ public class InheritanceActionTest {
     /*
      * sonar way (2) <- companyWide (2) <- buWide (2, 1 overriding) <- (forProject1 (2), forProject2 (2))
      */
-    QProfileDto sonarway = db.qualityProfiles().insert(organization, p ->
-      p.setKee("xoo-sonar-way").setLanguage("xoo").setName("Sonar way").setIsBuiltIn(true));
+    QProfileDto sonarway = db.qualityProfiles().insert(organization, p -> p.setKee("xoo-sonar-way").setLanguage("xoo").setName("Sonar way").setIsBuiltIn(true));
     ActiveRuleDto activeRule1 = createActiveRule(rule1, sonarway);
     ActiveRuleDto activeRule2 = createActiveRule(rule2, sonarway);
 
index abf4932caa45ba193598811454ee4baeb2741a2c..b91ed9fb686b335746bc77b05dded36c927d8b7a 100644 (file)
@@ -81,7 +81,7 @@ public class RegisterRulesTest {
   @org.junit.Rule
   public DbTester dbTester = DbTester.create(system);
   @org.junit.Rule
-  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
   @org.junit.Rule
   public LogTester logTester = new LogTester();
 
index 17ee475d67f0afc742246e6b04cf6f42dad7cfb6..b85b1fea380496ab79002b0e806564470c9bc885 100644 (file)
@@ -66,7 +66,7 @@ public class RuleCreatorTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private RuleIndex ruleIndex = new RuleIndex(es.client());
   private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
index cca9a5543243f851f45bcd2be08871074f03f8de..ed78fbc9f5ffe79f4f07b0e375cbaced802102e2 100644 (file)
@@ -77,7 +77,7 @@ public class RuleUpdaterTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private RuleIndex ruleIndex = new RuleIndex(es.client());
   private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
index 2583bf06acdd856c5e3faa4f98346d1896da266a..433d9c2f341cdd6476b7a69b120603c90a8adb55 100644 (file)
@@ -25,7 +25,6 @@ import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.EsTester;
@@ -40,8 +39,8 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.INDEX_TYPE_RULE;;
 
 public class RuleIndexDefinitionTest {
 
-  private Settings settings = new MapSettings();
-  private RuleIndexDefinition underTest = new RuleIndexDefinition(settings);
+  private MapSettings settings = new MapSettings();
+  private RuleIndexDefinition underTest = new RuleIndexDefinition(settings.asConfig());
 
   @Rule
   public EsTester tester = new EsTester(underTest);
index 228fc6658dd68d201d3f247f5bc0a18cd7d2501a..465ab5f8e68b9f57da2123e46968d5dbbc9bcf71 100644 (file)
@@ -91,7 +91,7 @@ public class RuleIndexTest {
   private System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
-  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings()));
+  public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings().asConfig()));
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
index 2bb330d9d5988818d67643b7eb3436fc4031b7a8..93e8ccba2257aa88684ff78801b714d286522135 100644 (file)
@@ -42,7 +42,7 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 public class RuleIndexerTest {
 
   @Rule
-  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester dbTester = DbTester.create();
index a0e5e607eea775b4233d07aedd641ddb1b5e189b..366d1cbdb4c9f338bd26c2aff761a187c62f3e37 100644 (file)
@@ -70,7 +70,7 @@ public class CreateActionTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
 
index 5428e4189f654a571e603eb2f0ed962e4177c128..3ab344e19f45a834d5189913fa86ab54ac4cd4cf 100644 (file)
@@ -101,7 +101,7 @@ public class SearchActionTest {
   @org.junit.Rule
   public DbTester db = DbTester.create(system2);
   @org.junit.Rule
-  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
   private RuleIndex ruleIndex = new RuleIndex(es.client());
index a932f239ed3ce5b8d1e35565b484affcbad618fa..ce6cdb53d0e0bb7a02ef22115e03af13bd6a859d 100644 (file)
@@ -72,7 +72,7 @@ public class ShowActionTest {
   public DbTester dbTester = DbTester.create();
   @org.junit.Rule
   public EsTester esTester = new EsTester(
-    new RuleIndexDefinition(new MapSettings()));
+    new RuleIndexDefinition(new MapSettings().asConfig()));
   @org.junit.Rule
   public ExpectedException thrown = ExpectedException.none();
 
index a79430649cf5959b7ccb950069b1538f1e6a7a49..c32e97894ad8decd087d3ecaee076ee92834cf45 100644 (file)
@@ -50,7 +50,7 @@ public class TagsActionTest {
   @Rule
   public DbTester dbTester = DbTester.create();
   @Rule
-  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   private DbClient dbClient = dbTester.getDbClient();
   private EsClient esClient = esTester.client();
index d602ab95a440f11da6788ec1fa33ed6b839f477c..4e1f82b9d0a0b8577a25391914c6387bb50561d0 100644 (file)
@@ -85,7 +85,7 @@ public class UpdateActionTest {
   public DbTester db = DbTester.create();
 
   @Rule
-  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
index 3e1a393142c38915c27a7f183a800e9608a6addb..64ac88e09729dd444a4969b5b7c7b087cd3adf86 100644 (file)
@@ -21,9 +21,10 @@ package org.sonar.server.setting;
 
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
-import org.sonar.ce.settings.ProjectSettingsFactory;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.property.PropertyDto;
 
@@ -36,18 +37,17 @@ public class ProjectSettingsFactoryTest {
 
   static final String PROJECT_KEY = "PROJECT_KEY";
 
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
   DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS);
 
-  ProjectSettingsFactory underTest = new ProjectSettingsFactory(settings, dbClient);
+  ProjectConfigurationFactory underTest = new ProjectConfigurationFactory(settings, dbClient);
 
   @Test
   public void return_global_settings() {
     settings.setProperty("key", "value");
-    Settings projectSettings = underTest.newProjectSettings(PROJECT_KEY);
+    Configuration config = underTest.newProjectConfiguration(PROJECT_KEY);
 
-    assertThat(projectSettings.getProperties()).hasSize(1);
-    assertThat(projectSettings.getString("key")).isEqualTo("value");
+    assertThat(config.get("key")).hasValue("value");
   }
 
   @Test
@@ -55,24 +55,22 @@ public class ProjectSettingsFactoryTest {
     when(dbClient.propertiesDao().selectProjectProperties(PROJECT_KEY)).thenReturn(newArrayList(
       new PropertyDto().setKey("1").setValue("val1"),
       new PropertyDto().setKey("2").setValue("val2"),
-      new PropertyDto().setKey("3").setValue("val3"))
-      );
+      new PropertyDto().setKey("3").setValue("val3")));
 
-    Settings projectSettings = underTest.newProjectSettings(PROJECT_KEY);
+    Configuration config = underTest.newProjectConfiguration(PROJECT_KEY);
 
-    assertThat(projectSettings.getString("1")).isEqualTo("val1");
-    assertThat(projectSettings.getString("2")).isEqualTo("val2");
-    assertThat(projectSettings.getString("3")).isEqualTo("val3");
+    assertThat(config.get("1")).hasValue("val1");
+    assertThat(config.get("2")).hasValue("val2");
+    assertThat(config.get("3")).hasValue("val3");
   }
 
   @Test
   public void project_settings_override_global_settings() {
     settings.setProperty("key", "value");
     when(dbClient.propertiesDao().selectProjectProperties(PROJECT_KEY)).thenReturn(newArrayList(
-        new PropertyDto().setKey("key").setValue("value2"))
-    );
+      new PropertyDto().setKey("key").setValue("value2")));
 
-    Settings projectSettings = underTest.newProjectSettings(PROJECT_KEY);
-    assertThat(projectSettings.getString("key")).isEqualTo("value2");
+    Configuration projectConfig = underTest.newProjectConfiguration(PROJECT_KEY);
+    assertThat(projectConfig.get("key")).hasValue("value2");
   }
 }
index fbfd3fe0308ab7ff3c54cf5445b9ea9661276c43..243b1ab06f87940ef60cf7f84e65d21ff3bf2813 100644 (file)
@@ -46,7 +46,7 @@ public class CheckSecretKeyActionTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private Encryption encryption = settings.getEncryption();
   private CheckSecretKeyAction underTest = new CheckSecretKeyAction(settings, userSession);
   private WsActionTester ws = new WsActionTester(underTest);
index 35373212e3b66b9bab1584c674e3086e33236297..24f2c6b82879964b0336fcbe28b43ed671869bc7 100644 (file)
@@ -50,7 +50,7 @@ public class EncryptActionTest {
   @Rule
   public TemporaryFolder folder = new TemporaryFolder();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private Encryption encryption = settings.getEncryption();
   private EncryptAction underTest = new EncryptAction(userSession, settings);
   private WsActionTester ws = new WsActionTester(underTest);
index 22e501e92681d2bed398013efdf6a037cf9e8c22..37ad552f690eaa2fa8170ae7dfbe7be427112196 100644 (file)
@@ -46,7 +46,7 @@ public class GenerateSecretKeyActionTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private Encryption encryption = settings.getEncryption();
   private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(settings, userSession);
   private WsActionTester ws = new WsActionTester(underTest);
index 013b64d1db03a47bdfe27db98385ba4d24725c8e..c478ab3ab572b70e7de994d59d9509248a43bdc6 100644 (file)
@@ -34,7 +34,7 @@ import static org.sonar.server.test.index.TestIndexDefinition.INDEX_TYPE_TEST;
 
 public class TestIndexTest {
   @Rule
-  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings().asConfig()));
 
   TestIndex underTest = new TestIndex(es.client());
 
index 37e3ff543eca2a9bcc63985ed6b53a6adee21d04..1922c16d74567473d2dd58f638d970a1159f044e 100644 (file)
@@ -62,7 +62,7 @@ public class TestIndexerTest {
   private System2 system2 = System2.INSTANCE;
 
   @Rule
-  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester db = DbTester.create(system2);
index 1e2c493c2d4ae69e1c4845a10cc7e280b1f0aeea..729b7afcbc7d9b1b1b5a57ae3cde9fa4603296bb 100644 (file)
@@ -63,7 +63,7 @@ public class ListActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
index a6c5c628538449c9ec077b8156f2d79c21480487..edf14a5253ded68190bd74ec653d7ab2b5b5d268 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.ui.ws;
 
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.platform.Server;
 import org.sonar.api.resources.ResourceType;
@@ -52,7 +51,7 @@ public class GlobalActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   private Server server = mock(Server.class);
   private DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
@@ -212,7 +211,7 @@ public class GlobalActionTest {
       }
     }});
     pageRepository.start();
-    ws = new WsActionTester(new GlobalAction(pageRepository, settings, new ResourceTypes(resourceTypeTrees), server,
+    ws = new WsActionTester(new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
       dbClient, organizationFlags, defaultOrganizationProvider, userSession));
   }
 
index 4ee023e0c65c604f2b7251bbcaa5bc544288fcf1..673cb640d95ddd76073951a32cead22b9024841d 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.ui.ws;
 
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.web.page.Page;
 import org.sonar.api.web.page.PageDefinition;
@@ -41,7 +40,7 @@ public class SettingsActionTest {
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   private WsActionTester ws;
 
@@ -87,7 +86,7 @@ public class SettingsActionTest {
         context.addPage(page);
       }
     }});
-    ws = new WsActionTester(new SettingsAction(pageRepository, settings, userSessionRule));
+    ws = new WsActionTester(new SettingsAction(pageRepository, settings.asConfig(), userSessionRule));
     pageRepository.start();
   }
 
index 4878432140c55b4450d2eb4dbb21caa8664ad3ef..44bed60feb41da4c9551ccd1888a8f2c99ba8585 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.user;
 
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.security.LoginPasswordAuthenticator;
 import org.sonar.api.security.SecurityRealm;
@@ -34,7 +33,7 @@ import static org.mockito.Mockito.verify;
 
 public class SecurityRealmFactoryTest {
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
 
   /**
    * Typical usage.
@@ -44,7 +43,7 @@ public class SecurityRealmFactoryTest {
     SecurityRealm realm = spy(new FakeRealm());
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] {realm});
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings.asConfig(), new SecurityRealm[] {realm});
     factory.start();
     assertThat(factory.getRealm()).isSameAs(realm);
     assertThat(factory.hasExternalAuthentication()).isTrue();
@@ -55,7 +54,7 @@ public class SecurityRealmFactoryTest {
 
   @Test
   public void do_not_fail_if_no_realms() {
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings);
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings.asConfig());
     factory.start();
     assertThat(factory.getRealm()).isNull();
     assertThat(factory.hasExternalAuthentication()).isFalse();
@@ -66,7 +65,7 @@ public class SecurityRealmFactoryTest {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, "Fake");
 
     try {
-      new SecurityRealmFactory(settings);
+      new SecurityRealmFactory(settings.asConfig());
       fail();
     } catch (SonarException e) {
       assertThat(e.getMessage()).contains("Realm 'Fake' not found.");
@@ -78,7 +77,7 @@ public class SecurityRealmFactoryTest {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
     LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[] {authenticator});
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings.asConfig(), new LoginPasswordAuthenticator[] {authenticator});
     SecurityRealm realm = factory.getRealm();
     assertThat(realm).isInstanceOf(CompatibilityRealm.class);
   }
@@ -90,7 +89,7 @@ public class SecurityRealmFactoryTest {
     LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] {realm},
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings.asConfig(), new SecurityRealm[] {realm},
       new LoginPasswordAuthenticator[] {authenticator});
     assertThat(factory.getRealm()).isSameAs(realm);
   }
@@ -100,7 +99,7 @@ public class SecurityRealmFactoryTest {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, "Fake");
 
     try {
-      new SecurityRealmFactory(settings);
+      new SecurityRealmFactory(settings.asConfig());
       fail();
     } catch (SonarException e) {
       assertThat(e.getMessage()).contains("Authenticator 'Fake' not found.");
@@ -113,7 +112,7 @@ public class SecurityRealmFactoryTest {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
 
-    new SecurityRealmFactory(settings, new SecurityRealm[] {realm}).start();
+    new SecurityRealmFactory(settings.asConfig(), new SecurityRealm[] {realm}).start();
     verify(realm).init();
   }
 
@@ -123,7 +122,7 @@ public class SecurityRealmFactoryTest {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
 
     try {
-      new SecurityRealmFactory(settings, new SecurityRealm[] {realm}).start();
+      new SecurityRealmFactory(settings.asConfig(), new SecurityRealm[] {realm}).start();
       fail();
     } catch (SonarException e) {
       assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
index d7c4f1c5983abb00b00d5486e23f088592a68a4c..0a3f827f0a99def5d91e3d24e325e1c5bd80dd46 100644 (file)
@@ -77,7 +77,7 @@ public class UserUpdaterTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public DbTester db = DbTester.create(system2);
@@ -92,7 +92,7 @@ public class UserUpdaterTest {
   private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
   private MapSettings settings = new MapSettings();
   private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, system2, organizationFlags, defaultOrganizationProvider, organizationCreation,
-    new DefaultGroupFinder(dbClient), settings);
+    new DefaultGroupFinder(dbClient), settings.asConfig());
 
   @Test
   public void create_user() {
index 5f2dc268a055b57207f1bb13cfa16befae8d866f..5492c1baafac1f19b96adc0fbca66df874d5233e 100644 (file)
@@ -32,7 +32,7 @@ public class UserIndexDefinitionTest {
 
   @Test
   public void define() {
-    UserIndexDefinition def = new UserIndexDefinition(new MapSettings());
+    UserIndexDefinition def = new UserIndexDefinition(new MapSettings().asConfig());
     def.define(underTest);
 
     assertThat(underTest.getIndices()).hasSize(1);
index c0543add15a73a582118eb7f9bb6dfd747bbc23c..66ba400145a5e66a1daf80edd24ab90da31647d7 100644 (file)
@@ -43,7 +43,7 @@ public class UserIndexTest {
   private static final long DATE_2 = 1_500_000_000_001L;
 
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   private UserIndex underTest;
 
index 02b87851c3230e1742b68b8349eee5c79c060805..66fb5c2ceae3272927a8c4447e2ca4a21e6da793 100644 (file)
@@ -39,7 +39,7 @@ public class UserIndexerTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   private UserIndexer underTest = new UserIndexer(db.getDbClient(), es.client());
 
index d3f69cd7664aa4a880f61fd0ebbb1ac2e90523eb..6a09f91f7e824cb82741abeb2ab08c2a4cfa2677 100644 (file)
@@ -53,7 +53,7 @@ public class ChangePasswordActionTest {
   @Rule
   public DbTester db = DbTester.create();
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn();
 
@@ -65,7 +65,7 @@ public class ChangePasswordActionTest {
     TestDefaultOrganizationProvider.from(db),
     mock(OrganizationCreation.class),
     new DefaultGroupFinder(db.getDbClient()),
-    new MapSettings());
+    new MapSettings().asConfig());
 
   private WsTester tester = new WsTester(new UsersWs(new ChangePasswordAction(db.getDbClient(), userUpdater, userSessionRule)));
 
index 3115195f30a77aef5d860478c22b0e613670e5ea..d95b91cc0b2c50dac347eda12af812079d082fac 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
@@ -65,13 +64,13 @@ import static org.sonar.db.user.UserTesting.newUserDto;
 public class CreateActionTest {
 
   private static final String DEFAULT_GROUP_NAME = "sonar-users";
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
   public DbTester db = DbTester.create(system2);
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings.asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
@@ -87,7 +86,7 @@ public class CreateActionTest {
   private WsActionTester tester = new WsActionTester(new CreateAction(
     db.getDbClient(),
     new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, system2, organizationFlags, defaultOrganizationProvider,
-      organizationCreation, new DefaultGroupFinder(db.getDbClient()), settings),
+      organizationCreation, new DefaultGroupFinder(db.getDbClient()), settings.asConfig()),
     userSessionRule));
 
   @Before
index 34538b90c4cda2dd517198d569ca6204f60986c2..a0c8afd33502fb57a9b78b8ad2b012da84a9d074 100644 (file)
@@ -76,7 +76,7 @@ public class DeactivateActionTest {
   public DbTester db = DbTester.create(system2);
 
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
index a6f01a4acf1f5cd91a779486ab324cc85b1e1453..6c44ded965ae67fa7438e764cff24aa900955126 100644 (file)
@@ -56,7 +56,7 @@ public class SearchActionTest {
   private System2 system2 = System2.INSTANCE;
 
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
index 05af1353c6703c1b95c2a7936639a2469b840861..4747ce234a9c03d4f701014695f12e8f5c8d1c03 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.user.ws;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -53,14 +52,14 @@ public class UpdateActionTest {
 
   private static final OrganizationCreation ORGANIZATION_CREATION_NOT_USED_FOR_UPDATE = null;
 
-  private final Settings settings = new MapSettings();
+  private final MapSettings settings = new MapSettings();
 
   private System2 system2 = new System2();
 
   @Rule
   public DbTester dbTester = DbTester.create(system2);
   @Rule
-  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings.asConfig()));
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn().setSystemAdministrator();
 
@@ -77,7 +76,7 @@ public class UpdateActionTest {
     userIndexer = new UserIndexer(dbClient, esTester.client());
     tester = new WsTester(new UsersWs(new UpdateAction(
       new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, system2, organizationFlags, defaultOrganizationProvider, ORGANIZATION_CREATION_NOT_USED_FOR_UPDATE,
-        new DefaultGroupFinder(dbTester.getDbClient()), settings),
+        new DefaultGroupFinder(dbTester.getDbClient()), settings.asConfig()),
       userSessionRule,
       new UserJsonWriter(userSessionRule), dbClient)));
   }
index ff096b38b830093533673f4886ea83f60452de4e..c5135d2417945ddb317f2760f8bde5dfa9a3e830 100644 (file)
@@ -32,7 +32,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.SonarQubeSide;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.utils.Version;
@@ -41,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class OkHttpClientProviderTest {
 
-  private Settings settings = new MapSettings();
+  private MapSettings settings = new MapSettings();
   private SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER);
   private final OkHttpClientProvider underTest = new OkHttpClientProvider();
 
@@ -50,7 +49,7 @@ public class OkHttpClientProviderTest {
 
   @Test
   public void get_returns_a_OkHttpClient_with_default_configuration() throws Exception {
-    OkHttpClient client = underTest.provide(settings, runtime);
+    OkHttpClient client = underTest.provide(settings.asConfig(), runtime);
 
     assertThat(client.connectTimeoutMillis()).isEqualTo(10_000);
     assertThat(client.readTimeoutMillis()).isEqualTo(10_000);
@@ -66,7 +65,7 @@ public class OkHttpClientProviderTest {
     settings.setProperty("http.proxyUser", "the-login");
     settings.setProperty("http.proxyPassword", "the-password");
 
-    OkHttpClient client = underTest.provide(settings, runtime);
+    OkHttpClient client = underTest.provide(settings.asConfig(), runtime);
     Response response = new Response.Builder().protocol(Protocol.HTTP_1_1).request(new Request.Builder().url("http://foo").build()).code(407).build();
     Request request = client.proxyAuthenticator().authenticate(null, response);
 
@@ -75,8 +74,8 @@ public class OkHttpClientProviderTest {
 
   @Test
   public void get_returns_a_singleton() {
-    OkHttpClient client1 = underTest.provide(settings, runtime);
-    OkHttpClient client2 = underTest.provide(settings, runtime);
+    OkHttpClient client1 = underTest.provide(settings.asConfig(), runtime);
+    OkHttpClient client2 = underTest.provide(settings.asConfig(), runtime);
     assertThat(client2).isNotNull().isSameAs(client1);
   }
 
index ea9b451535fbc5377640eb4945d46a709b077f47..a29ef9144592a54e2351f204cab1f413ee7558b6 100644 (file)
@@ -32,7 +32,7 @@ public class ViewIndexDefinitionTest {
 
   @Test
   public void define() {
-    ViewIndexDefinition def = new ViewIndexDefinition(new MapSettings());
+    ViewIndexDefinition def = new ViewIndexDefinition(new MapSettings().asConfig());
     def.define(underTest);
 
     assertThat(underTest.getIndices()).hasSize(1);
index 2e3dc5ceaf4381811e4897ad8ebf6bf3129fea7c..dbe796ee666b03a827ad97dac5353c860972945a 100644 (file)
@@ -33,7 +33,7 @@ import static org.sonar.server.view.index.ViewIndexDefinition.INDEX_TYPE_VIEW;
 public class ViewIndexTest {
 
   @Rule
-  public EsTester esTester = new EsTester(new ViewIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new ViewIndexDefinition(new MapSettings().asConfig()));
 
   ViewIndex index = new ViewIndex(esTester.client());
 
index 426b9d5094537d07cf738134678070222d190d92..922ab565ef0ce41a7f49530514bbea9f95fcab38 100644 (file)
@@ -61,7 +61,7 @@ public class ViewIndexerTest {
   public DbTester dbTester = DbTester.create(system2);
 
   @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()), new ViewIndexDefinition(new MapSettings().asConfig()));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -124,8 +124,7 @@ public class ViewIndexerTest {
 
   @Test
   public void clear_views_lookup_cache_on_index_view_uuid() {
-    IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule)
-    );
+    IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
     IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
 
     String viewUuid = "ABCD";
diff --git a/sonar-core/src/main/java/org/sonar/core/config/ConfigurationProvider.java b/sonar-core/src/main/java/org/sonar/core/config/ConfigurationProvider.java
new file mode 100644 (file)
index 0000000..c68c496
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.core.config;
+
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.ConfigurationBridge;
+
+public class ConfigurationProvider extends ProviderAdapter {
+
+  private Configuration configuration;
+
+  public Configuration provide(Settings settings) {
+    if (configuration == null) {
+      configuration = new ConfigurationBridge(settings);
+    }
+    return configuration;
+  }
+
+}
index ccd69ff2bb69cffb9e01926b5be7f77b0927c6db..7aaecf3a41fdc8bfdb6cfda5d18325fa026c4349 100644 (file)
@@ -24,7 +24,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.i18n.I18n;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -39,11 +39,11 @@ import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VER
 
 public class Periods {
 
-  private final Settings settings;
+  private final Configuration config;
   private final I18n i18n;
 
-  public Periods(Settings settings, I18n i18n) {
-    this.settings = settings;
+  public Periods(Configuration config, I18n i18n) {
+    this.config = config;
     this.i18n = i18n;
   }
 
@@ -58,14 +58,14 @@ public class Periods {
 
   @CheckForNull
   public String label(int periodIndex) {
-    String periodProperty = settings.getString(LEAK_PERIOD + periodIndex);
+    String periodProperty = config.get(LEAK_PERIOD + periodIndex).orElse(null);
     PeriodParameters periodParameters = new PeriodParameters(periodProperty);
     return label(periodParameters.getMode(), periodParameters.getParam(), periodParameters.getDate());
   }
 
   @CheckForNull
   public String abbreviation(int periodIndex) {
-    String periodProperty = settings.getString(LEAK_PERIOD + periodIndex);
+    String periodProperty = config.get(LEAK_PERIOD + periodIndex).orElse(null);
     PeriodParameters periodParameters = new PeriodParameters(periodProperty);
     return abbreviation(periodParameters.getMode(), periodParameters.getParam(), periodParameters.getDate());
   }
index 305d83ec6c1bc73ca7d638b91df6b9e05d19bdc1..7c307f066dbb1eccc6ac504c7fe3b47a8f447115 100644 (file)
@@ -24,14 +24,13 @@ import java.util.Locale;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.i18n.I18n;
 
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.isNull;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.sonar.api.utils.DateUtils.parseDate;
@@ -51,9 +50,9 @@ public class PeriodsTest {
   static int PERIOD_INDEX = 1;
   @Rule
   public ExpectedException thrown = ExpectedException.none();
-  Settings settings = new MapSettings();
+  MapSettings settings = new MapSettings();
   I18n i18n = mock(I18n.class);
-  Periods periods = new Periods(settings, i18n);
+  Periods periods = new Periods(settings.asConfig(), i18n);
 
   @Test
   public void return_over_x_days_label_when_no_date() {
index dae2594593acc05640685523b84fefb1f25b998f..f079a49dc6715996f7aa0228e1bffd9430946e54 100644 (file)
@@ -53,10 +53,10 @@ public class EmailSettings {
   public static final String PREFIX = "email.prefix";
   public static final String PREFIX_DEFAULT = "[SONARQUBE]";
 
-  private final Settings settings;
+  private final Configuration config;
 
-  public EmailSettings(Settings settings) {
-    this.settings = settings;
+  public EmailSettings(Configuration config) {
+    this.config = config;
   }
 
   public String getSmtpHost() {
@@ -92,8 +92,7 @@ public class EmailSettings {
   }
 
   private String get(String key, String defaultValue) {
-    String value = settings.getString(key);
-    return value != null ? value : defaultValue;
+    return config.get(key).orElse(defaultValue);
   }
 
   /**
index 13c407d000b0f5284ea0dfded19c2be5383e212b..d15b7c1a65b98e1d85bf5db7fe381ae39630560d 100644 (file)
@@ -57,7 +57,7 @@ import static org.sonar.api.PropertyType.REGULAR_EXPRESSION;
 import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
 
 /**
- * Declare a plugin property. Values are available at runtime through the components {@link Settings} or {@link org.sonar.api.Configuration.SettingsReader}.
+ * Declare a plugin property. Values are available at runtime through the component {@link Configuration}.
  * <br>
  * It's the programmatic alternative to the annotation {@link org.sonar.api.Property}. It is more
  * testable and adds new features like sub-categories and ordering.
index 6d45e12ddb6acee535ac3bdbee51da0fd6325122..9a58e9eb6a06850fb1092ceb138a2678756f7181 100644 (file)
@@ -79,6 +79,26 @@ public class MapSettings extends Settings {
     return this;
   }
 
+  @Override
+  public MapSettings setProperty(String key, String value) {
+    return (MapSettings) super.setProperty(key, value);
+  }
+
+  @Override
+  public MapSettings setProperty(String key, Integer value) {
+    return (MapSettings) super.setProperty(key, value);
+  }
+
+  @Override
+  public MapSettings setProperty(String key, Boolean value) {
+    return (MapSettings) super.setProperty(key, value);
+  }
+
+  @Override
+  public MapSettings setProperty(String key, Long value) {
+    return (MapSettings) super.setProperty(key, value);
+  }
+
   /**
    * @return a {@link Configuration} proxy on top of this existing {@link Settings} implementation. Changes are reflected in the {@link Configuration} object.
    * @since 6.5
index 507ab123b085d9642c0f17e97a6c761c306f3f8c..0ce63c675632b14381a5083892de7a4e1e2027de 100644 (file)
@@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class EmailSettingsTest {
 
-  private EmailSettings underTest = new EmailSettings(new MapSettings());
+  private EmailSettings underTest = new EmailSettings(new MapSettings().asConfig());
 
   @Test
   public void should_return_default_values() {