From 3e835d99cd4e16a1308399ef2aab28b58d7cc63a Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Tue, 16 Nov 2021 10:53:24 +0100 Subject: [PATCH] SONAR-15614 Drop the 'sonar.lf.aboutText' property --- .../db/migration/version/v92/DbVersion92.java | 1 + .../DropSonarLfAboutTextPropertyValue.java | 42 ++++++++++++ .../v92/DropSonarLfAboutTextPropertyTest.java | 68 +++++++++++++++++++ .../schema.sql | 10 +++ .../core/config/CorePropertyDefinitions.java | 7 -- .../org/sonar/core/config/WebConstants.java | 1 - .../config/CorePropertyDefinitionsTest.java | 2 +- 7 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyValue.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest/schema.sql diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java index 3f1e6bf6ccc..8d274007179 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java @@ -39,6 +39,7 @@ public class DbVersion92 implements DbVersion { .add(6111, "Change size of column 'kee' in 'components'", AlterKeeInComponentsTable.class) .add(6112, "Create 'project_badge_token' Table", CreateProjectBadgeTokenTable.class) .add(6113, "Deprecate quality profile 'Sonar way Recommended' for js and ts", DeprecateSWRecommendedQProfile.class) + .add(6114, "Drop the 'sonar.lf.aboutText' property value", DropSonarLfAboutTextPropertyValue.class) ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyValue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyValue.java new file mode 100644 index 00000000000..d9481a50d6c --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyValue.java @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v92; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; + +public class DropSonarLfAboutTextPropertyValue extends DataChange { + + public static final String PROPERTY_TO_DELETE_KEY = "sonar.lf.aboutText"; + + public DropSonarLfAboutTextPropertyValue(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context + .prepareUpsert("delete from properties where prop_key = ?") + .setString(1, PROPERTY_TO_DELETE_KEY) + .execute() + .commit(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest.java new file mode 100644 index 00000000000..9a900d647da --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest.java @@ -0,0 +1,68 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v92; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.SequenceUuidFactory; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +public class DropSonarLfAboutTextPropertyTest { + + private final UuidFactory uuidFactory = new SequenceUuidFactory(); + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropSonarLfAboutTextPropertyTest.class, "schema.sql"); + + private final DataChange underTest = new DropSonarLfAboutTextPropertyValue(db.database()); + + @Test + public void do_not_fail_if_no_rows_to_delete() { + assertThatCode(underTest::execute) + .doesNotThrowAnyException(); + } + + @Test + public void deletes_lf_about_text_property_when_they_exist_in_database() throws SQLException { + insertProperty(DropSonarLfAboutTextPropertyValue.PROPERTY_TO_DELETE_KEY, "This is an about text test sample"); + + underTest.execute(); + + assertThat(db.countSql( + String.format("select count(*) from properties where prop_key = '%s'", + DropSonarLfAboutTextPropertyValue.PROPERTY_TO_DELETE_KEY + ))).isZero(); + } + + private void insertProperty(String key, String value) { + db.executeInsert("properties", + "PROP_KEY", key, + "TEXT_VALUE", value, + "IS_EMPTY", String.valueOf(false), + "CREATED_AT", 2, + "UUID", uuidFactory.create()); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest/schema.sql new file mode 100644 index 00000000000..a4f7dac82b6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/DropSonarLfAboutTextPropertyTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PROPERTIES"( + "PROP_KEY" VARCHAR(512) NOT NULL, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000) NULL, + "CLOB_VALUE" VARCHAR(4000) NULL, + "CREATED_AT" INTEGER NOT NULL, + "COMPONENT_UUID" VARCHAR(40) NULL, + "UUID" VARCHAR(40) NOT NULL, + "USER_UUID" VARCHAR(255) NULL +); diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index 8200a483905..79923fd241b 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -136,13 +136,6 @@ public class CorePropertyDefinitions { .category(CoreProperties.CATEGORY_GENERAL) .subCategory(CoreProperties.SUBCATEGORY_LOOKNFEEL) .build(), - PropertyDefinition.builder(WebConstants.SONAR_LF_ABOUT_TEXT) - .name("About page text") - .description("Optional text that is displayed on the About page. Supports html.") - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_LOOKNFEEL) - .type(PropertyType.TEXT) - .build(), // ISSUES PropertyDefinition.builder(CoreProperties.DEVELOPER_AGGREGATED_INFO_DISABLED) diff --git a/sonar-core/src/main/java/org/sonar/core/config/WebConstants.java b/sonar-core/src/main/java/org/sonar/core/config/WebConstants.java index fe2d549320e..709e5fb5064 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/WebConstants.java +++ b/sonar-core/src/main/java/org/sonar/core/config/WebConstants.java @@ -28,7 +28,6 @@ public final class WebConstants { public static final String SONAR_LF_GRAVATAR_SERVER_URL = "sonar.lf.gravatarServerUrl"; public static final String SONAR_LF_LOGO_URL = "sonar.lf.logoUrl"; public static final String SONAR_LF_LOGO_WIDTH_PX = "sonar.lf.logoWidthPx"; - public static final String SONAR_LF_ABOUT_TEXT = "sonar.lf.aboutText"; private WebConstants() { } diff --git a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java index b0b7cb1307e..1fcaec844ef 100644 --- a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java @@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest { @Test public void all() { List defs = CorePropertyDefinitions.all(); - assertThat(defs).hasSize(53); + assertThat(defs).hasSize(52); } @Test -- 2.39.5