From 2022f77214c6456941f10591e435db8ebead08c0 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 19 Dec 2017 13:42:58 +0100 Subject: SONAR-8216 System info page fails when a setting is defined both in sonar.properties and in DB --- .../server/setting/DatabaseSettingLoader.java | 10 +++--- .../org/sonar/server/setting/NopSettingLoader.java | 7 ++-- .../org/sonar/server/setting/SettingLoader.java | 4 +-- .../sonar/server/setting/ThreadLocalSettings.java | 24 +++++++------- .../server/setting/DatabaseSettingLoaderTest.java | 25 ++++++++------- .../sonar/server/setting/NopSettingLoaderTest.java | 6 +--- .../server/setting/ThreadLocalSettingsTest.java | 37 ++++++++++++---------- 7 files changed, 58 insertions(+), 55 deletions(-) (limited to 'server') diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java b/server/sonar-server/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java index 7e4203adae4..c8be9a21f24 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/DatabaseSettingLoader.java @@ -19,7 +19,8 @@ */ package org.sonar.server.setting; -import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.property.PropertyDto; @@ -44,10 +45,11 @@ public class DatabaseSettingLoader implements SettingLoader { } @Override - public void loadAll(ImmutableMap.Builder appendTo) { + public Map loadAll() { try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.propertiesDao().selectGlobalProperties(dbSession) - .forEach(p -> appendTo.put(p.getKey(), defaultString(p.getValue()))); + return dbClient.propertiesDao().selectGlobalProperties(dbSession) + .stream() + .collect(MoreCollectors.uniqueIndex(PropertyDto::getKey, p -> defaultString(p.getValue()))); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/NopSettingLoader.java b/server/sonar-server/src/main/java/org/sonar/server/setting/NopSettingLoader.java index 4c494e34519..e161d5f090e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/NopSettingLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/NopSettingLoader.java @@ -19,7 +19,8 @@ */ package org.sonar.server.setting; -import com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.Map; public class NopSettingLoader implements SettingLoader { @Override @@ -28,8 +29,8 @@ public class NopSettingLoader implements SettingLoader { } @Override - public void loadAll(ImmutableMap.Builder appendTo) { - // nothing to load + public Map loadAll() { + return Collections.emptyMap(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/SettingLoader.java b/server/sonar-server/src/main/java/org/sonar/server/setting/SettingLoader.java index 9115e7da8c8..49758eac29b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/SettingLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/SettingLoader.java @@ -19,7 +19,7 @@ */ package org.sonar.server.setting; -import com.google.common.collect.ImmutableMap; +import java.util.Map; import javax.annotation.CheckForNull; public interface SettingLoader { @@ -27,6 +27,6 @@ public interface SettingLoader { @CheckForNull String load(String key); - void loadAll(ImmutableMap.Builder appendTo); + Map loadAll(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ThreadLocalSettings.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ThreadLocalSettings.java index a12c4963e02..9a131fb7ed5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ThreadLocalSettings.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ThreadLocalSettings.java @@ -20,7 +20,6 @@ package org.sonar.server.setting; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -36,11 +35,12 @@ import org.sonar.api.config.Settings; import org.sonar.api.server.ServerSide; import static com.google.common.base.Preconditions.checkState; +import static java.util.Collections.unmodifiableMap; import static java.util.Objects.requireNonNull; /** - * Merge of {@link SystemSettings} and the global properties stored in the db table "properties". These - * settings do not contain the settings specific to a project. + * Merge of system settings (including conf/sonar.properties) and the global properties stored + * in the db table "properties". These settings do not contain the settings specific to a project. * *

* System settings have precedence on others. @@ -167,21 +167,19 @@ public class ThreadLocalSettings extends Settings { @Override public Map getProperties() { - ImmutableMap.Builder builder = ImmutableMap.builder(); - loadAll(builder); - systemProps.forEach((key, value) -> builder.put((String) key, (String) value)); - return builder.build(); + Map result = new HashMap<>(); + loadAll(result); + systemProps.forEach((key, value) -> result.put((String) key, (String) value)); + return unmodifiableMap(result); } - private void loadAll(ImmutableMap.Builder builder) { + private void loadAll(Map appendTo) { try { - ImmutableMap.Builder cacheBuilder = ImmutableMap.builder(); - settingLoader.loadAll(cacheBuilder); - Map cache = cacheBuilder.build(); - builder.putAll(cache); + Map cache = settingLoader.loadAll(); + appendTo.putAll(cache); getPropertiesDbFailureCache = cache; } catch (PersistenceException e) { - builder.putAll(getPropertiesDbFailureCache); + appendTo.putAll(getPropertiesDbFailureCache); } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java index 922554bec55..d14c66605ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java @@ -19,7 +19,7 @@ */ package org.sonar.server.setting; -import com.google.common.collect.ImmutableMap; +import java.util.Map; import org.junit.Rule; import org.junit.Test; import org.sonar.api.utils.System2; @@ -49,6 +49,7 @@ public class DatabaseSettingLoaderTest { @Test public void null_value_in_db_is_considered_as_empty_string() { insertPropertyIntoDb(A_KEY, null); + assertThat(underTest.load(A_KEY)).isEqualTo(""); } @@ -60,19 +61,19 @@ public class DatabaseSettingLoaderTest { @Test public void test_loadAll_with_no_properties() { - ImmutableMap.Builder map = ImmutableMap.builder(); - underTest.loadAll(map); - assertThat(map.build().isEmpty()).isTrue(); + Map map = underTest.loadAll(); + assertThat(map).isEmpty(); } - @Test - public void test_loadAll() { - insertPropertyIntoDb("foo", "1"); - insertPropertyIntoDb("bar", "2"); - ImmutableMap.Builder map = ImmutableMap.builder(); - underTest.loadAll(map); - assertThat(map.build()).containsOnly(entry("foo", "1"), entry("bar", "2")); - } + @Test + public void test_loadAll() { + insertPropertyIntoDb("foo", "1"); + insertPropertyIntoDb("bar", "2"); + + Map map = underTest.loadAll(); + + assertThat(map).containsOnly(entry("foo", "1"), entry("bar", "2")); + } private void insertPropertyIntoDb(String key, String value) { dbTester.getDbClient().propertiesDao().saveProperty(new PropertyDto().setKey(key).setValue(value)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/NopSettingLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/NopSettingLoaderTest.java index 329abda074e..798e534f4c8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/NopSettingLoaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/NopSettingLoaderTest.java @@ -19,9 +19,7 @@ */ package org.sonar.server.setting; -import com.google.common.collect.ImmutableMap; import org.junit.Test; -import org.sonar.server.setting.NopSettingLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -33,8 +31,6 @@ public class NopSettingLoaderTest { public void do_nothing() { assertThat(underTest.load("foo")).isNull(); - ImmutableMap.Builder map = ImmutableMap.builder(); - underTest.loadAll(map); - assertThat(map.build()).isEmpty(); + assertThat(underTest.loadAll()).isEmpty(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java index 9dc3e4df4e7..4884c5fa8e7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java @@ -35,11 +35,11 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.config.PropertyDefinitions; +import static java.util.Collections.unmodifiableMap; import static java.util.concurrent.TimeUnit.SECONDS; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.MapEntry.entry; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -109,6 +109,18 @@ public class ThreadLocalSettingsTest { assertThat(underTest.get("foo")).isNotPresent(); } + /** + * SONAR-8216 System info page fails when a setting is defined both in sonar.properties and in DB + */ + @Test + public void getProperties_does_not_fail_on_duplicated_key() { + insertPropertyIntoDb("foo", "from_db"); + underTest = create(ImmutableMap.of("foo", "from_system")); + + assertThat(underTest.get("foo")).hasValue("from_system"); + assertThat(underTest.getProperties().get("foo")).isEqualTo("from_system"); + } + @Test public void load_encryption_secret_key_from_system_properties() throws Exception { File secretKey = temp.newFile(); @@ -259,7 +271,7 @@ public class ThreadLocalSettingsTest { public void getProperties_return_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); - doThrow(toBeThrown).when(settingLoaderMock).loadAll(any(ImmutableMap.Builder.class)); + doThrow(toBeThrown).when(settingLoaderMock).loadAll(); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); assertThat(underTest.getProperties()) @@ -270,7 +282,7 @@ public class ThreadLocalSettingsTest { public void getProperties_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); - doThrow(toBeThrown).when(settingLoaderMock).loadAll(any(ImmutableMap.Builder.class)); + doThrow(toBeThrown).when(settingLoaderMock).loadAll(); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); underTest.load(); @@ -285,18 +297,11 @@ public class ThreadLocalSettingsTest { String value2 = randomAlphanumeric(5); SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); - doAnswer(invocationOnMock -> { - ImmutableMap.Builder builder = (ImmutableMap.Builder) invocationOnMock.getArguments()[0]; - builder.put(key, value1); - return null; - }).doThrow(toBeThrown) - .doAnswer(invocationOnMock -> { - ImmutableMap.Builder builder = (ImmutableMap.Builder) invocationOnMock.getArguments()[0]; - builder.put(key, value2); - return null; - }) + doAnswer(invocationOnMock -> ImmutableMap.of(key, value1)) + .doThrow(toBeThrown) + .doAnswer(invocationOnMock -> ImmutableMap.of(key, value2)) .when(settingLoaderMock) - .loadAll(any(ImmutableMap.Builder.class)); + .loadAll(); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); underTest.load(); @@ -394,8 +399,8 @@ public class ThreadLocalSettingsTest { } @Override - public void loadAll(ImmutableMap.Builder appendTo) { - appendTo.putAll(map); + public Map loadAll() { + return unmodifiableMap(map); } } } -- cgit v1.2.3 From 8d3f85ca3272be3b99826c86d24dd4ca54ae85ed Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 19 Dec 2017 13:48:31 +0100 Subject: SONAR-10210 Fix performance hotspot in DB migration #1267 --- .../db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java | 5 ----- .../db/migration/version/v60/PopulateAnalysisUuidOnMeasuresTest.java | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'server') diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java index c7eca704768..d68fd020771 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java @@ -44,11 +44,6 @@ public class PopulateAnalysisUuidOnMeasures extends DataChange { massUpdate.select("select distinct m.snapshot_id as sId, s.root_snapshot_id as rootSid " + "from project_measures m " + "inner join snapshots s on m.snapshot_id = s.id " + - "where m.analysis_uuid is null " + - "union " + - "select distinct m.snapshot_id as sId, s.root_snapshot_id as rootSid " + - "from project_measures m " + - "inner join snapshots s on m.snapshot_id=s.id " + "where m.analysis_uuid is null" ); massUpdate.update("update project_measures set analysis_uuid=? where snapshot_id = ? and analysis_uuid is null"); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasuresTest.java index 023793635c6..eb274166294 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasuresTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasuresTest.java @@ -81,7 +81,7 @@ public class PopulateAnalysisUuidOnMeasuresTest { assertThat(rows.get("analysisUuid")).isEqualTo(expectedAnalysisUuid); } - private String insertSnapshot(long id, String uuid, String qualifier, @Nullable Long rootSnapshotId) { + private void insertSnapshot(long id, String uuid, String qualifier, @Nullable Long rootSnapshotId) { int depth; switch (qualifier) { case "TRK": @@ -108,7 +108,6 @@ public class PopulateAnalysisUuidOnMeasuresTest { "ROOT_SNAPSHOT_ID", rootSnapshotId != null ? valueOf(rootSnapshotId) : null, "QUALIFIER", qualifier, "DEPTH", valueOf(depth)); - return uuid; } private void insertMeasure(long id, long snapshotId) { -- cgit v1.2.3 From 527a13d12e2457845d2631e2615181f6173c13bc Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 19 Dec 2017 15:52:18 +0100 Subject: SONAR-10214 Deprecated value of "qualityProfile" is "name", not "profileName" --- .../main/java/org/sonar/server/qualityprofile/ws/ExportAction.java | 2 +- .../java/org/sonar/server/qualityprofile/ws/ExportActionTest.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java index 50f907490eb..cea5b11724e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java @@ -89,7 +89,7 @@ public class ExportAction implements QProfileWsAction { action.createParam(PARAM_QUALITY_PROFILE) .setDescription("Quality profile name to export. If left empty, the default profile for the language is exported. If this parameter is set, '%s' must not be set.", PARAM_KEY) - .setDeprecatedKey("profileName", "6.6") + .setDeprecatedKey("name", "6.6") .setExampleValue("My Sonar way"); action.createParam(PARAM_LANGUAGE) diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java index 55f46efe64e..7a08c259b7a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java @@ -48,8 +48,8 @@ import org.sonar.server.ws.WsActionTester; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; public class ExportActionTest { @@ -74,14 +74,19 @@ public class ExportActionTest { assertThat(definition.isPost()).isFalse(); assertThat(definition.isInternal()).isFalse(); assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("key", "language", "qualityProfile", "organization"); + WebService.Param organizationParam = definition.param("organization"); assertThat(organizationParam.since()).isEqualTo("6.4"); assertThat(organizationParam.isInternal()).isTrue(); + WebService.Param key = definition.param("key"); assertThat(key.since()).isEqualTo("6.5"); assertThat(key.deprecatedSince()).isEqualTo("6.6"); + WebService.Param name = definition.param("qualityProfile"); assertThat(name.deprecatedSince()).isNullOrEmpty(); + assertThat(name.deprecatedKey()).isEqualTo("name"); + WebService.Param language = definition.param("language"); assertThat(language.deprecatedSince()).isNullOrEmpty(); } -- cgit v1.2.3 From e6fea33be6dd9333abdd82444317a708804d2f85 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 28 Nov 2017 10:28:32 +0100 Subject: SONAR-10131 purge test files when purging project history --- .../org/sonar/db/component/ComponentTreeQuery.java | 15 ++ .../org/sonar/db/purge/PurgeConfiguration.java | 15 +- .../src/main/java/org/sonar/db/purge/PurgeDao.java | 9 +- .../org/sonar/db/component/ComponentMapper.xml | 6 + .../org/sonar/db/measure/MeasureMapper.xml | 15 +- .../org/sonar/db/component/ComponentDaoTest.java | 25 ++- .../org/sonar/db/purge/PurgeConfigurationTest.java | 27 +-- .../test/java/org/sonar/db/purge/PurgeDaoTest.java | 11 +- ...eHistoricalDataOfDirectoriesAndFiles-result.xml | 216 ++++++++++++++++++--- ...ldDeleteHistoricalDataOfDirectoriesAndFiles.xml | 210 ++++++++++++++++++-- 10 files changed, 469 insertions(+), 80 deletions(-) (limited to 'server') diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentTreeQuery.java index 6119f3cb9ae..a6099250007 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentTreeQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentTreeQuery.java @@ -42,12 +42,15 @@ public class ComponentTreeQuery { // SONAR-7681 a public implementation of List must be used in MyBatis - potential concurrency exceptions otherwise @CheckForNull private final ArrayList qualifiers; + @CheckForNull + private final ArrayList scopes; private final String baseUuid; private final Strategy strategy; private ComponentTreeQuery(Builder builder) { this.nameOrKeyQuery = builder.nameOrKeyQuery; this.qualifiers = builder.qualifiers == null ? null : newArrayList(builder.qualifiers); + this.scopes = builder.scopes == null ? null : newArrayList(builder.scopes); this.baseUuid = builder.baseUuid; this.strategy = requireNonNull(builder.strategy); } @@ -57,6 +60,11 @@ public class ComponentTreeQuery { return qualifiers; } + @CheckForNull + public Collection getScopes() { + return scopes; + } + @CheckForNull public String getNameOrKeyQuery() { return nameOrKeyQuery; @@ -98,6 +106,8 @@ public class ComponentTreeQuery { private String nameOrKeyQuery; @CheckForNull private Collection qualifiers; + @CheckForNull + private Collection scopes; private String baseUuid; private Strategy strategy; @@ -120,6 +130,11 @@ public class ComponentTreeQuery { return this; } + public Builder setScopes(Collection scopes) { + this.scopes = scopes; + return this; + } + public Builder setBaseUuid(String uuid) { this.baseUuid = uuid; return this; 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 c9d903f883f..15fc642e842 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 @@ -30,16 +30,19 @@ import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; import org.sonar.core.config.PurgeConstants; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; + public class PurgeConfiguration { private final IdUuidPair rootProjectIdUuid; - private final String[] scopesWithoutHistoricalData; + private final Collection scopesWithoutHistoricalData; private final int maxAgeInDaysOfClosedIssues; private final Optional maxAgeInDaysOfInactiveShortLivingBranches; private final System2 system2; private final Collection disabledComponentUuids; - public PurgeConfiguration(IdUuidPair rootProjectId, String[] scopesWithoutHistoricalData, int maxAgeInDaysOfClosedIssues, + public PurgeConfiguration(IdUuidPair rootProjectId, Collection scopesWithoutHistoricalData, int maxAgeInDaysOfClosedIssues, Optional maxAgeInDaysOfInactiveShortLivingBranches, System2 system2, Collection disabledComponentUuids) { this.rootProjectIdUuid = rootProjectId; this.scopesWithoutHistoricalData = scopesWithoutHistoricalData; @@ -50,11 +53,11 @@ public class PurgeConfiguration { } public static PurgeConfiguration newDefaultPurgeConfiguration(Configuration config, IdUuidPair idUuidPair, Collection disabledComponentUuids) { - String[] scopes = new String[] {Scopes.FILE}; + Collection scopesWithoutHistoricalData = singletonList(Scopes.FILE); if (config.getBoolean(PurgeConstants.PROPERTY_CLEAN_DIRECTORY).orElse(false)) { - scopes = new String[] {Scopes.DIRECTORY, Scopes.FILE}; + scopesWithoutHistoricalData = asList(Scopes.FILE, Scopes.DIRECTORY); } - return new PurgeConfiguration(idUuidPair, scopes, config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(), + return new PurgeConfiguration(idUuidPair, scopesWithoutHistoricalData, config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(), config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_INACTIVE_SHORT_LIVING_BRANCHES), System2.INSTANCE, disabledComponentUuids); } @@ -62,7 +65,7 @@ public class PurgeConfiguration { return rootProjectIdUuid; } - public String[] scopesWithoutHistoricalData() { + public Collection getScopesWithoutHistoricalData() { return scopesWithoutHistoricalData; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index de29166e268..05cb3aee82b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -21,7 +21,6 @@ package org.sonar.db.purge; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -64,7 +63,7 @@ public class PurgeDao implements Dao { PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); - deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands); + deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.getScopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf, listener); deleteOldClosedIssues(conf, mapper, listener); @@ -119,8 +118,8 @@ public class PurgeDao implements Dao { commands.deleteAnalyses(query); } - private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { - if (scopesWithoutHistoricalData.length == 0) { + private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, Collection scopesWithoutHistoricalData, PurgeCommands purgeCommands) { + if (scopesWithoutHistoricalData.isEmpty()) { return; } @@ -134,7 +133,7 @@ public class PurgeDao implements Dao { dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) - .setQualifiers(Arrays.asList(scopesWithoutHistoricalData)) + .setScopes(scopesWithoutHistoricalData) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 5d7e051032f..b22881f4b64 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -374,6 +374,12 @@ #{qualifier,jdbcType=VARCHAR} + + and p.scope in + + #{scope,jdbcType=VARCHAR} + + and ( p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 860b4e73f47..d29bcf17665 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -121,7 +121,20 @@ and pm.person_id is null - + and p.enabled = ${_true} + + and p.qualifier in + + #{qualifier,jdbcType=VARCHAR} + + + + and ( + p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} + or + upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' + ) +