diff options
202 files changed, 900 insertions, 932 deletions
diff --git a/server/sonar-ce-api/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java b/server/sonar-ce-api/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java index 77e6f78be49..be00dbc3d08 100644 --- a/server/sonar-ce-api/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java +++ b/server/sonar-ce-api/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java @@ -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 diff --git a/server/sonar-ce-api/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java b/server/sonar-ce-api/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java index 11a80512919..2f501716b2d 100644 --- a/server/sonar-ce-api/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java +++ b/server/sonar-ce-api/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java @@ -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); } } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java index 13c383ba329..b913387c84a 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java @@ -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); } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 992df9f4a30..5f50464eb51 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -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 diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java index 1267693e9e1..3c483a80f3e 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java @@ -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> { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 4fdec8c4058..ca5b507a24b 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -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 diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/CoreTestDb.java b/server/sonar-db-core/src/test/java/org/sonar/db/CoreTestDb.java index bc5cd3cb6d4..30752123607 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/CoreTestDb.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/CoreTestDb.java @@ -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; diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java index 1ffc411cb44..5d9d83d5e76 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java @@ -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; diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/ResultSetIteratorTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/ResultSetIteratorTest.java index 19a9e7089ae..c50d0943a0a 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/ResultSetIteratorTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/ResultSetIteratorTest.java @@ -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; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index be316cb26e9..a56ebd4883f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -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 { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java index 7f74b5ee284..2aa056856b9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java @@ -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; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java index cc6fb0dbe18..2d30880fc0a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java @@ -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() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java index 10dab8e6f45..cbc3016339e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java @@ -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 diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/Filters.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/Filters.java index fab44eaa2cc..8ed4a3c7a6b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/Filters.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/Filters.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index cd5e4275373..e4902888070 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -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 { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java index e9156a1c09a..f722a77d2b6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java @@ -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; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/BatchSessionTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/BatchSessionTest.java index 94d53172528..2d18560a98f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/BatchSessionTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/BatchSessionTest.java @@ -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; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 7e3e3208d01..2efdcfc3629 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -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; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java index 0c7ba44000c..9c027764c2f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java @@ -19,14 +19,13 @@ */ 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; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeConfigurationTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeConfigurationTest.java index 3afa0d3300a..57b89e8843e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeConfigurationTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeConfigurationTest.java @@ -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); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java index 0e11e370613..2e8e1d03886 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java @@ -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; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java index 3a2f026169b..7e62fc60387 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java @@ -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 { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDtoTest.java index 5747d4a0726..3676c783462 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDtoTest.java @@ -19,14 +19,14 @@ */ 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 diff --git a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java b/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java index 309bf90ad22..23b1ebb10db 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java @@ -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/ProjectSettingsFactory.java b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java index 351d49742a7..dbec22e2141 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectSettingsFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java @@ -20,25 +20,27 @@ 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 ProjectSettingsFactory { +public class ProjectConfigurationFactory { private final Settings globalSettings; private final DbClient dbClient; - public ProjectSettingsFactory(Settings globalSettings, DbClient dbClient) { + public ProjectConfigurationFactory(Settings globalSettings, DbClient dbClient) { this.globalSettings = globalSettings; this.dbClient = dbClient; } - public Settings newProjectSettings(String projectKey) { + public Configuration newProjectConfiguration(String projectKey) { Settings projectSettings = new ProjectSettings(globalSettings); dbClient.propertiesDao() .selectProjectProperties(projectKey) .forEach(property -> projectSettings.setProperty(property.getKey(), property.getValue())); - return projectSettings; + return new ConfigurationBridge(projectSettings); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java b/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java index 297345ec9f5..54e998e9576 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java @@ -20,19 +20,18 @@ 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)))); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtHttpHandler.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtHttpHandler.java index 905cc015943..461910be421 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtHttpHandler.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtHttpHandler.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtSerializer.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtSerializer.java index 8b2a6289508..477f4f59e89 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtSerializer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/JwtSerializer.java @@ -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(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java index ee6c90a02d8..a7bf1c56d7a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/SsoAuthenticator.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/SsoAuthenticator.java index 16408ab1823..6859112cda6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/SsoAuthenticator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/SsoAuthenticator.java @@ -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())))); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java index e86e6c80c65..4cedd539219 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java @@ -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") diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/ws/ValidateAction.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/ws/ValidateAction.java index ec0b424c5db..1e273d7351e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/authentication/ws/ValidateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/ws/ValidateAction.java @@ -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; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java index e2d3f0cb3a0..8226567c96e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java @@ -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(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java index 8ce11e2c38c..d2969f7c840 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java index c9ea8198b7c..e2a33711860 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java @@ -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/SettingsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepository.java index de4b4ca0fef..1dd33a4f4e3 100644 --- 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/ConfigurationRepository.java @@ -19,14 +19,14 @@ */ package org.sonar.server.computation.task.projectanalysis.component; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; /** * Repository of component settings. */ -public interface SettingsRepository { +public interface ConfigurationRepository { /** - * Returns the settings for the specified Component. + * Returns the configuration for the specified Component. */ - Settings getSettings(Component component); + Configuration getConfiguration(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/ConfigurationRepositoryImpl.java index f56f4da7d32..80489e4730a 100644 --- 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/ConfigurationRepositoryImpl.java @@ -21,35 +21,35 @@ 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.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 SettingsRepositoryImpl implements SettingsRepository { +public class ConfigurationRepositoryImpl implements ConfigurationRepository { - private final ProjectSettingsFactory projectSettingsFactory; - private final MemoryCache<String, Settings> cache = new MemoryCache<>(new CacheLoader<String, Settings>() { + private final ProjectConfigurationFactory projectConfigurationFactory; + private final MemoryCache<String, Configuration> cache = new MemoryCache<>(new CacheLoader<String, Configuration>() { @Override - public Settings load(String key) { - return projectSettingsFactory.newProjectSettings(key); + public Configuration load(String key) { + return projectConfigurationFactory.newProjectConfiguration(key); } @Override - public Map<String, Settings> loadAll(Collection<? extends String> keys) { + public Map<String, Configuration> loadAll(Collection<? extends String> keys) { throw new UnsupportedOperationException("loadAll is not supported"); } }); - public SettingsRepositoryImpl(ProjectSettingsFactory projectSettingsFactory) { - this.projectSettingsFactory = projectSettingsFactory; + public ConfigurationRepositoryImpl(ProjectConfigurationFactory projectSettingsFactory) { + this.projectConfigurationFactory = projectSettingsFactory; } @Override - public Settings getSettings(Component component){ + 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/container/ProjectAnalysisTaskContainerPopulator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java index 2b7096ffad5..c6fcc5d22d9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java @@ -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, diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java index 0124c12c947..dde79aa7c16 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java @@ -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> { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssignee.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssignee.java index eeebe0c86e8..9fccec30442 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssignee.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssignee.java @@ -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; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilter.java index 5b3eb5d2b1a..d45d0338b3b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilter.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureComputersVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureComputersVisitor.java index 92a4d820fdb..5b571ee48e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureComputersVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureComputersVisitor.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettings.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettings.java index 91f7509166e..cf128cf2188 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettings.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettings.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStep.java index 75e40591c3c..be93f8fd780 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStep.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadQualityGateStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadQualityGateStep.java index 1417de24f8b..ca1d5588d54 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadQualityGateStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadQualityGateStep.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java index 3ea2fe10647..7a21affa5ac 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java @@ -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(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStep.java index f260563094c..677689f58a4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStep.java @@ -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(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java index 6baef99868a..c66de9fd3ae 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java index 2712e89b639..d4259c67659 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/IndexDefinitions.java b/server/sonar-server/src/main/java/org/sonar/server/es/IndexDefinitions.java index b1490a4338f..2774983adc4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/IndexDefinitions.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/IndexDefinitions.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java b/server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java index 07ae9a9914b..717f290d8be 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java @@ -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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java index bfc65cfbf27..1d85732cc75 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java index 0a3dd891302..37c1cf6d8ab 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java @@ -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(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java index ea28cf08a27..76e43947743 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java @@ -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(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationDaemon.java b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationDaemon.java index c32c9a4dec6..74f4747b874 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationDaemon.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationDaemon.java @@ -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; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java index 9a9da7eeca0..25a4939746b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java @@ -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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java index f7c02a5edc5..c19f0d68799 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java @@ -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(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerFileSystemImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerFileSystemImpl.java index a1ca634e5d6..295a38e39ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerFileSystemImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerFileSystemImpl.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdLoader.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdLoader.java index 7a85fc3987e..049316a0e47 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdLoader.java @@ -19,38 +19,33 @@ */ 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); + }); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java index d753fee3869..100cebba00d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java index 0f584529950..a60631aed04 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java @@ -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()); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/UrlSettings.java b/server/sonar-server/src/main/java/org/sonar/server/platform/UrlSettings.java index 0643ff0bf72..c56693c5921 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/UrlSettings.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/UrlSettings.java @@ -20,10 +20,9 @@ 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://"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java index d987b45f595..08e93f695ed 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabase.java b/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabase.java index 33d1f62d637..b971ee110f5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabase.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabase.java @@ -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 { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabaseFactory.java b/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabaseFactory.java index 91c69ff80fc..836065d1cf1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabaseFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/db/EmbeddedDatabaseFactory.java @@ -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); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java index 7a864c6471f..823876d9911 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java @@ -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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 7a2f30b5bba..10bffed4ced 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -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, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 3056d5bdde8..ac0aa79be26 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -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, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java index cb9e045d80d..3a5160d573a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java @@ -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 { diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java index d5038e7c3af..d16080a749b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java index b50ef8398b2..67e446d4aaf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java @@ -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()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java index 5cd24c29399..7d78f076394 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java @@ -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); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java index ac787e96528..05c727707f0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java @@ -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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/SettingsAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/SettingsAction.java index b104a0d89fb..923affa0c3b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/SettingsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/SettingsAction.java @@ -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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java b/server/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java index 61d2190f9f0..683147ca2f9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java index d1ac28f0a3a..b92fae91e36 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java index 2270ccff34b..d64f2fd8145 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java @@ -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()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/OkHttpClientProvider.java b/server/sonar-server/src/main/java/org/sonar/server/util/OkHttpClientProvider.java index e9f2e27dbad..7d28b5a26db 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/OkHttpClientProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/OkHttpClientProvider.java @@ -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(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java index 602e41edb87..d49ef6df2db 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java b/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java index e6c8c25247f..86d319d9e0f 100644 --- a/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java +++ b/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java index 223b965fcff..b34daac76eb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java @@ -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)) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java index 6d552b4aa9a..79762338534 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java index 0c3a97f8c02..86a260fcfab 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java index 45c19a9ace3..85d34585105 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java index 3cd623bd8a2..5875442d41d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java index 9f84bab5786..40638401375 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java @@ -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())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java index 4f162137409..b8fcf9fd7ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserSessionInitializerTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/ws/ValidateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/ws/ValidateActionTest.java index 414195baff8..948bcc40233 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/ws/ValidateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/ws/ValidateActionTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java index 4fca15eacc4..8d9ace5f123 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java index a467d42b440..50f42cbf982 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java index 7324b52cce2..cf69abaaf33 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 6208aa2fa2c..7afbb927c5d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index a1d07572f77..4f354df9bd1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java index b9c8007ef11..611a8d14c53 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java @@ -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)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java index f7e4c33359a..533c19917e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java @@ -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/SettingsRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java index de328c1d514..a2800c3272c 100644 --- 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/ConfigurationRepositoryTest.java @@ -23,10 +23,10 @@ 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.Configuration; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.System2; -import org.sonar.ce.settings.ProjectSettingsFactory; +import org.sonar.ce.settings.ProjectConfigurationFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -37,8 +37,7 @@ 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 { +public class ConfigurationRepositoryTest { private static final Component ROOT = ReportComponent.builder(PROJECT, 1).setKey("ROOT").build(); @@ -51,13 +50,13 @@ public class SettingsRepositoryTest { MapSettings globalSettings; - SettingsRepository underTest; + ConfigurationRepository underTest; @Before public void createDao() { globalSettings = new MapSettings(); session = dbClient.openSession(false); - underTest = new SettingsRepositoryImpl(new ProjectSettingsFactory(globalSettings, dbClient)); + underTest = new ConfigurationRepositoryImpl(new ProjectConfigurationFactory(globalSettings, dbClient)); } @After @@ -69,9 +68,9 @@ public class SettingsRepositoryTest { public void get_project_settings_from_global_settings() { globalSettings.setProperty("key", "value"); - Settings settings = underTest.getSettings(ROOT); + Configuration config = underTest.getConfiguration(ROOT); - assertThat(settings.getString("key")).isEqualTo("value"); + assertThat(config.get("key")).hasValue("value"); } @Test @@ -81,19 +80,19 @@ public class SettingsRepositoryTest { dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value")); session.commit(); - Settings settings = underTest.getSettings(ROOT); + Configuration config = underTest.getConfiguration(ROOT); - assertThat(settings.getString("key")).isEqualTo("value"); + assertThat(config.get("key")).hasValue("value"); } @Test public void call_twice_get_project_settings() { globalSettings.setProperty("key", "value"); - Settings settings = underTest.getSettings(ROOT); - assertThat(settings.getString("key")).isEqualTo("value"); + Configuration config = underTest.getConfiguration(ROOT); + assertThat(config.get("key")).hasValue("value"); - settings = underTest.getSettings(ROOT); - assertThat(settings.getString("key")).isEqualTo("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/TestSettingsRepository.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TestSettingsRepository.java index be233329461..b436f0d38d2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TestSettingsRepository.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TestSettingsRepository.java @@ -19,22 +19,22 @@ */ 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; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java index b75ebdb223e..11e998b817a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java index 024844859be..b65ecc8a1cb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java index 0afcc53cbee..e8a08221bf2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilterTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilterTest.java index d119b23ee3f..0c36fc90d9a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/filter/IssueFilterTest.java @@ -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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettingsTest.java index 43bad73e48c..c3653c11ea7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettingsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/RatingSettingsTest.java @@ -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()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java index a150f7857e3..a0bfda79d62 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStepTest.java index b3f606a450e..6264fc0c3d1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PurgeDatastoresStepTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateLoadingStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateLoadingStepTest.java index f33bb6fea8d..7e671ffe00e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateLoadingStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateLoadingStepTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java index 5592797964e..5685f9fd064 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookCallerImplTest.java @@ -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)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java index 14d69d2c41b..c630e803d16 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java @@ -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) diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java index b31e8864491..62f15d002ff 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java @@ -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); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java index 00bb513b200..2eb1269121a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java index 72ba6c74e7a..cb4c73c9c5a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/IndexerStartupTaskTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/IndexerStartupTaskTest.java index 9b42bc43114..ddce70f478f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/IndexerStartupTaskTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/IndexerStartupTaskTest.java @@ -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(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java index 4f9c787a8ac..f9e119a1b12 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java @@ -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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java index 0769a2c5b8a..465d7ac0ca0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java index 24bc6f65dab..0376accdf4e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java index ed7045f351c..6beb40197eb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index 3a74e53b93e..1e9dcb16efa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java index 77c4f20a4a6..410aae889c6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java index 04f7992bcaa..544c2304213 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java index 738bc7d3402..d4b849abaa4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java index 0d96c89e57b..ef9e92ab163 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java @@ -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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java index 0fcd4dc71a3..64888625f32 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java index 792d7767f7f..c31b901b5f6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java index f58f36c3cf4..81d7e0b682c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java @@ -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()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java index 545a35bb029..6cc8d39de35 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java index 2016cd55717..b30f4b72b69 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java index d396dbc6f29..efc09708b10 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java index 660f40738b7..f93118a2b02 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java index d70cdb9ed27..7a5991c91b7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java index c0987df1b4f..9a393e6a1cc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java index 04f01197b67..e451752ceb6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java index 35110f592cc..d74c286d394 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java index c7cc1c68a69..e078cfe193e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java index 44b249c934e..a733d4a3887 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java index 2612e8b5c5b..b237231746b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDaemonTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDaemonTest.java index c03a81c8f31..95cd0ec15eb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDaemonTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDaemonTest.java @@ -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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java index b0d17f73fff..44e487ffc9f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java index f55ef8e42bc..d5aa40abea1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java index b54c7c0d4c5..7d7d33f10d9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java index e075709858a..903c7fcd16a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java index 025c354a88c..c925621cab5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java index 215c224ce70..db4e01c6fbb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java index d04803cf455..9e26c7087ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdLoaderTest.java index 6968ccac511..0289e76b7fe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdLoaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdLoaderTest.java @@ -19,10 +19,9 @@ */ 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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java index 6fea447e183..55c66fd3a53 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerLoggingTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerLoggingTest.java index d001c95631e..92aa85e3fa1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerLoggingTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerLoggingTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/UrlSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/UrlSettingsTest.java index cf1e60766ce..4e76ae97040 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/UrlSettingsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/UrlSettingsTest.java @@ -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()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java index 33b32974b5a..554dd8ac303 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseFactoryTest.java index d88d4b4467f..b147df1439e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseFactoryTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java index bdbd0f4ae06..f9190c373e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java index b2b5da6461c..0230612bdef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java index cd0f60d7d48..e967f10d8de 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java @@ -19,15 +19,14 @@ */ 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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java index 4de4e0684a9..87195c8d5c6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java index dbef7febd48..ab574a72946 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java @@ -20,12 +20,12 @@ 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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java index 8dab6dfd604..fc85da1e7df 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java index 5b90603bbd4..ddf60c51689 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java index 3156a4fc760..c4f39080a9d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorTest.java index c199fab75d2..81efcf72ab6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorTest.java @@ -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)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index fd696cfac52..5c3094ccf5f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java index a67d0db9f6d..4416f3eb8a8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java index 480d0deddd0..8c560ae1b93 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java index 15ecc3c0bcd..4e21a465e21 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index abf4932caa4..b91ed9fb686 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorTest.java index 17ee475d67f..b85b1fea380 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java index cca9a554324..ed78fbc9f5f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java index 2583bf06acd..433d9c2f341 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java index 228fc6658dd..465ab5f8e68 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java index 2bb330d9d59..93e8ccba225 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java index a0e5e607eea..366d1cbdb4c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java index 5428e4189f6..3ab344e19f4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java index a932f239ed3..ce6cdb53d0e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java index a79430649cf..c32e97894ad 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java index d602ab95a44..4e1f82b9d0a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ProjectSettingsFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ProjectSettingsFactoryTest.java index 3e1a393142c..64ac88e0972 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ProjectSettingsFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ProjectSettingsFactoryTest.java @@ -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"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java index fbfd3fe0308..243b1ab06f8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java index 35373212e3b..24f2c6b8287 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java index 22e501e9268..37ad552f690 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java index 013b64d1db0..c478ab3ab57 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java index 37e3ff543ec..1922c16d745 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java index 1e2c493c2d4..729b7afcbc7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index a6c5c628538..edf14a5253d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -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)); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java index 4ee023e0c65..673cb640d95 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java @@ -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(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java index 4878432140c..44bed60feb4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java index d7c4f1c5983..0a3f827f0a9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java index 5f2dc268a05..5492c1baafa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java index c0543add15a..66ba400145a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java index 02b87851c32..66fb5c2ceae 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java index d3f69cd7664..6a09f91f7e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java @@ -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))); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index 3115195f30a..d95b91cc0b2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 34538b90c4c..a0c8afd3350 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index a6f01a4acf1..6c44ded965a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index 05af1353c67..4747ce234a9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -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))); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java index ff096b38b83..c5135d24179 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java @@ -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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java index ea9b451535f..a29ef914459 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java index 2e3dc5ceaf4..dbe796ee666 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index 426b9d50945..922ab565ef0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -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 index 00000000000..c68c496f472 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/config/ConfigurationProvider.java @@ -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; + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index ccd69ff2bb6..7aaecf3a41f 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -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()); } diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index 305d83ec6c1..7c307f066db 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -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() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java index dae2594593a..f079a49dc67 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java @@ -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); } /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 13c407d000b..d15b7c1a65b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -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. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/MapSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/MapSettings.java index 6d45e12ddb6..9a58e9eb6a0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/MapSettings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/MapSettings.java @@ -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 diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java index 507ab123b08..0ce63c67563 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java @@ -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() { |