From e05aea1ebbba8d94c78afdbfac7230563d6df01f Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Thu, 29 Nov 2018 15:37:02 +0100 Subject: [PATCH] SONAR-11525 analysis warning on module-lvl props Analysis now produces a warning when the property that aggregates all previous module-level properties is not cleared. --- .../db/migration/version/v75/DbVersion75.java | 3 +-- .../db/migration/version/v76/DbVersion76.java | 4 ++-- .../{v75 => v76}/MigrateModuleProperties.java | 4 ++-- .../version/v75/DbVersion75Test.java | 2 +- .../version/v76/DbVersion76Test.java | 2 +- .../MigrateModulePropertiesTest.java | 19 ++++++++++--------- .../MigrateModulePropertiesTest/schema.sql | 0 .../java/org/sonar/api/CoreProperties.java | 8 ++++++-- .../scan/ProjectServerSettingsProvider.java | 18 ++++++++++++++++-- 9 files changed, 39 insertions(+), 21 deletions(-) rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/{v75 => v76}/MigrateModuleProperties.java (96%) rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/{v75 => v76}/MigrateModulePropertiesTest.java (89%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/{v75 => v76}/MigrateModulePropertiesTest/schema.sql (100%) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java index fd5f6716470..05176b69a7b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java @@ -31,7 +31,6 @@ public class DbVersion75 implements DbVersion { .add(2401, "Create ORGANIZATION_ALM_BINDINGS table", CreateOrganizationsAlmBindingsTable.class) .add(2402, "Add column USER_EXTERNAL_ID in ALM_APP_INSTALLS", AddUserExternalIdColumnInAlmAppInstall.class) .add(2403, "Set IS_OWNER_USER not nullable in ALM_APP_INSTALLS", SetIsOwnerUserNotNullableInAlmAppInstalls.class) - .add(2404, "Add table EVENT_COMPONENT_CHANGES", AddEventComponentChanges.class) - .add(2405, "Move module and directory properties to a project level property", MigrateModuleProperties.class); + .add(2404, "Add table EVENT_COMPONENT_CHANGES", AddEventComponentChanges.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76.java index 235b8af2800..0cdfeaf5f99 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76.java @@ -29,8 +29,8 @@ public class DbVersion76 implements DbVersion { registry .add(2500, "Create table USER_PROPERTIES", CreateUserPropertiesTable.class) .add(2501, "Add index in table USER_PROPERTIES", AddUniqueIndexInUserPropertiesTable.class) + .add(2502, "Move module and directory properties to a project level property", MigrateModuleProperties.class) .add(2505, "Fix the direction values of certain metrics (prepare for migration of conditions)", FixDirectionOfMetrics.class) - .add(2506, "Migrate quality gate conditions using warning, period and no more supported operations", MigrateNoMoreUsedQualityGateConditions.class) - ; + .add(2506, "Migrate quality gate conditions using warning, period and no more supported operations", MigrateNoMoreUsedQualityGateConditions.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/MigrateModuleProperties.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/MigrateModuleProperties.java similarity index 96% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/MigrateModuleProperties.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/MigrateModuleProperties.java index 5a7d66c3877..fbdf1e5b556 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/MigrateModuleProperties.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/MigrateModuleProperties.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v75; +package org.sonar.server.platform.db.migration.version.v76; import java.sql.SQLException; import java.util.concurrent.atomic.AtomicReference; @@ -31,7 +31,7 @@ import org.sonar.server.platform.db.migration.step.Upsert; @SupportsBlueGreen public class MigrateModuleProperties extends DataChange { - private static final String NEW_PROPERTY_NAME = "sonar.subprojects.settings.removed"; + protected static final String NEW_PROPERTY_NAME = "sonar.modules.archivedSettings"; private final System2 system2; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java index 1d8a5afbba6..6a0eee289e2 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java @@ -35,6 +35,6 @@ public class DbVersion75Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 6); + verifyMigrationCount(underTest, 5); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76Test.java index bec86f8565a..595ce34382e 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/DbVersion76Test.java @@ -35,7 +35,7 @@ public class DbVersion76Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 4); + verifyMigrationCount(underTest, 5); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/MigrateModulePropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/MigrateModulePropertiesTest.java similarity index 89% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/MigrateModulePropertiesTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/MigrateModulePropertiesTest.java index 52330c71e0c..4692e49ef14 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/MigrateModulePropertiesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v76/MigrateModulePropertiesTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v75; +package org.sonar.server.platform.db.migration.version.v76; import java.sql.SQLException; import java.util.List; @@ -35,9 +35,10 @@ import org.sonar.db.CoreDbTester; import static java.lang.String.valueOf; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.version.v76.MigrateModuleProperties.NEW_PROPERTY_NAME; public class MigrateModulePropertiesTest { - private final static long NOW = 50_000_000_000L; + private static final long NOW = 50_000_000_000L; @Rule public CoreDbTester db = CoreDbTester.createForSchema(MigrateModulePropertiesTest.class, "schema.sql"); @@ -75,9 +76,9 @@ public class MigrateModulePropertiesTest { underTest.execute(); - List> properties = db.select("select ID, TEXT_VALUE, CLOB_VALUE " + + List> properties = db.select(String.format("select ID, TEXT_VALUE, CLOB_VALUE " + "from properties " + - "where PROP_KEY='sonar.subprojects.settings.removed' and RESOURCE_ID = 5"); + "where PROP_KEY='%s' and RESOURCE_ID = 5", NEW_PROPERTY_NAME)); assertThat(properties).hasSize(0); List> remainingProperties = db.select("select ID from properties"); assertThat(remainingProperties).hasSize(2); @@ -148,9 +149,9 @@ public class MigrateModulePropertiesTest { "sonar.coverage.exclusions=Module2A.java\n" + "sonar.cpd.exclusions=Module2B.java\n"; - List> properties = db.select("select ID, TEXT_VALUE, CLOB_VALUE " + - "from properties " + - "where PROP_KEY='sonar.subprojects.settings.removed' and RESOURCE_ID = 1"); + List> properties = db + .select(String.format("select ID, TEXT_VALUE, CLOB_VALUE from properties where PROP_KEY='%s' and RESOURCE_ID = 1", + NEW_PROPERTY_NAME)); assertThat(properties).hasSize(1); Map project1Property = properties.get(0); @@ -171,9 +172,9 @@ public class MigrateModulePropertiesTest { final String expectedResult = "# previous settings for sub-project Another multi-module project::Module X\n" + "sonar.coverage.exclusions=InModule.java\n"; - List> properties = db.select("select ID, TEXT_VALUE, CLOB_VALUE " + + List> properties = db.select(String.format("select ID, TEXT_VALUE, CLOB_VALUE " + "from properties " + - "where PROP_KEY='sonar.subprojects.settings.removed' and RESOURCE_ID = 6"); + "where PROP_KEY='%s' and RESOURCE_ID = 6", NEW_PROPERTY_NAME)); assertThat(properties).hasSize(1); Map project2Property = properties.get(0); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/MigrateModulePropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v76/MigrateModulePropertiesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/MigrateModulePropertiesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v76/MigrateModulePropertiesTest/schema.sql diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 5bbb4974373..e8066776c78 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -79,7 +79,6 @@ public interface CoreProperties { */ String CATEGORY_EXTERNAL_ISSUES = "externalIssues"; - /** * @since 2.11 */ @@ -366,7 +365,7 @@ public interface CoreProperties { /** * @since 3.6 */ - //TODO remove? + // TODO remove? String PROFILING_LOG_PROPERTY = "sonar.showProfiling"; /** @@ -527,4 +526,9 @@ public interface CoreProperties { * @since 5.1 */ String DEFAULT_ISSUE_ASSIGNEE = "sonar.issues.defaultAssigneeLogin"; + + /** + * @since 7.6 + */ + String MODULE_LEVEL_ARCHIVED_SETTINGS = "sonar.modules.archivedSettings"; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettingsProvider.java index 2a85f416445..88f20ae9772 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettingsProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettingsProvider.java @@ -20,17 +20,31 @@ package org.sonar.scanner.scan; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.CoreProperties; +import org.sonar.api.notifications.AnalysisWarnings; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.bootstrap.ScannerProperties; import org.sonar.scanner.repository.settings.SettingsLoader; public class ProjectServerSettingsProvider extends ProviderAdapter { - private ProjectServerSettings singleton; + private static final Logger LOG = Loggers.get(ProjectConfigurationProvider.class); - public ProjectServerSettings provide(SettingsLoader loader, ScannerProperties scannerProperties) { + private static final String MODULE_LEVEL_ARCHIVED_SETTINGS_WARNING = "Please migrate all the properties listed in " + + "`sonar.module.removedProperties` setting to appriopriate project level setting."; + + private ProjectServerSettings singleton = null; + + public ProjectServerSettings provide(SettingsLoader loader, ScannerProperties scannerProperties, AnalysisWarnings analysisWarnings) { if (singleton == null) { Map serverSideSettings = loader.load(scannerProperties.getKeyWithBranch()); + if (StringUtils.isNotBlank(serverSideSettings.get(CoreProperties.MODULE_LEVEL_ARCHIVED_SETTINGS))) { + LOG.warn(MODULE_LEVEL_ARCHIVED_SETTINGS_WARNING); + analysisWarnings.addUnique(MODULE_LEVEL_ARCHIVED_SETTINGS_WARNING); + } singleton = new ProjectServerSettings(serverSideSettings); } return singleton; -- 2.39.5