From 5cea1b86e42b9b71bd289ee35d4b376cb62e51c4 Mon Sep 17 00:00:00 2001
From: Aurelien
<100427063+aurelien-poscia-sonarsource@users.noreply.github.com>
Date: Thu, 28 Apr 2022 15:10:35 +0200
Subject: [PATCH] SONAR-16302 Renamed RULE_DESC_SECTIONS.DESCRIPTION to
RULE_DESC_SECTIONS.CONTENT and corresponding java objects
---
.../main/java/org/sonar/db/rule/RuleDao.java | 2 +-
.../db/rule/RuleDescriptionSectionDto.java | 26 +++----
.../QualityProfileExportMapper.xml | 4 +-
.../org/sonar/db/rule/RuleMapper.xml | 10 +--
server/sonar-db-dao/src/schema/schema-sq.ddl | 2 +-
.../QualityProfileExportDaoTest.java | 8 +--
.../java/org/sonar/db/rule/RuleDaoTest.java | 26 ++++---
.../rule/RuleDescriptionSectionDtoTest.java | 48 +++++++++++++
.../java/org/sonar/db/rule/RuleTesting.java | 8 ++-
.../v95/CreateRuleDescSectionsTable.java | 2 +-
.../db/migration/version/v95/DbVersion95.java | 2 +-
...rtRuleDescriptionIntoRuleDescSections.java | 4 +-
.../CreateIndexForRuleDescSectionsTest.java | 2 +-
...leDescriptionIntoRuleDescSectionsTest.java | 4 +-
.../schema.sql | 2 +-
.../schema.sql | 2 +-
.../server/rule/RuleDescriptionFormatter.java | 4 +-
.../rule/RuleDescriptionFormatterTest.java | 8 +--
.../server/rule/CachingRuleFinderTest.java | 2 +-
.../org/sonar/server/rule/RegisterRules.java | 38 +++++-----
.../sonar/server/rule/RegisterRulesTest.java | 72 +++++++++++++------
.../qualityprofile/QProfileBackuperImpl.java | 2 +-
.../server/qualityprofile/QProfileParser.java | 8 +--
.../rule/NewRuleDescriptionSection.java | 10 +--
.../org/sonar/server/rule/RuleCreator.java | 4 +-
.../org/sonar/server/rule/ws/ListAction.java | 2 +-
.../org/sonar/server/rule/ws/RuleMapper.java | 2 +-
.../QProfileBackuperImplTest.java | 4 +-
.../qualityprofile/QProfileParserTest.java | 4 +-
.../sonar/server/rule/RuleCreatorTest.java | 6 +-
.../sonar/server/rule/RuleUpdaterTest.java | 2 +-
31 files changed, 207 insertions(+), 113 deletions(-)
create mode 100644 server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
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 0837c3e2821..e5709520abe 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
@@ -159,7 +159,7 @@ public class RuleDao implements Dao {
insertRuleDescriptionSectionDtos(ruleDefinitionDto, mapper);
}
- private void insertRuleDescriptionSectionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) {
+ private static void insertRuleDescriptionSectionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) {
ruleDefinitionDto.getRuleDescriptionSectionDtos()
.forEach(section -> mapper.insertRuleDescriptionSection(ruleDefinitionDto.getUuid(), section));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java
index 208987e3f75..ae91fe2bbe7 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java
@@ -29,12 +29,12 @@ public class RuleDescriptionSectionDto {
private final String uuid;
private final String key;
- private final String description;
+ private final String content;
- private RuleDescriptionSectionDto(String uuid, String key, String description) {
+ private RuleDescriptionSectionDto(String uuid, String key, String content) {
this.uuid = uuid;
this.key = key;
- this.description = description;
+ this.content = content;
}
public String getUuid() {
@@ -45,15 +45,15 @@ public class RuleDescriptionSectionDto {
return key;
}
- public String getDescription() {
- return description;
+ public String getContent() {
+ return content;
}
public static RuleDescriptionSectionDto createDefaultRuleDescriptionSection(String uuid, String description) {
return RuleDescriptionSectionDto.builder()
.setDefault()
.uuid(uuid)
- .description(description)
+ .content(description)
.build();
}
@@ -70,7 +70,7 @@ public class RuleDescriptionSectionDto {
return new StringJoiner(", ", RuleDescriptionSectionDto.class.getSimpleName() + "[", "]")
.add("uuid='" + uuid + "'")
.add("key='" + key + "'")
- .add("description='" + description + "'")
+ .add("content='" + content + "'")
.toString();
}
@@ -83,18 +83,18 @@ public class RuleDescriptionSectionDto {
return false;
}
RuleDescriptionSectionDto that = (RuleDescriptionSectionDto) o;
- return Objects.equals(uuid, that.uuid) && Objects.equals(key, that.key) && Objects.equals(description, that.description);
+ return Objects.equals(uuid, that.uuid) && Objects.equals(key, that.key) && Objects.equals(content, that.content);
}
@Override
public int hashCode() {
- return Objects.hash(uuid, key, description);
+ return Objects.hash(uuid, key, content);
}
public static final class RuleDescriptionSectionDtoBuilder {
private String uuid;
private String key = null;
- private String description;
+ private String content;
private RuleDescriptionSectionDtoBuilder() {
}
@@ -116,13 +116,13 @@ public class RuleDescriptionSectionDto {
return this;
}
- public RuleDescriptionSectionDtoBuilder description(String description) {
- this.description = description;
+ public RuleDescriptionSectionDtoBuilder content(String content) {
+ this.content = content;
return this;
}
public RuleDescriptionSectionDto build() {
- return new RuleDescriptionSectionDto(uuid, key, description);
+ return new RuleDescriptionSectionDto(uuid, key, content);
}
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
index 4cea9e1e39b..ed94cc4598a 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
@@ -6,7 +6,7 @@
rds.uuid as "rds_uuid",
rds.kee as "rds_kee",
- rds.description as "rds_description",
+ rds.content as "rds_content",
@@ -50,7 +50,7 @@
-
+
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
index 685b9be1a72..ad74a26fab4 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
@@ -6,7 +6,7 @@
rds.uuid as "rds_uuid",
rds.kee as "rds_kee",
- rds.description as "rds_description",
+ rds.content as "rds_content",
@@ -127,7 +127,7 @@
-
+
@@ -160,7 +160,7 @@
-
+
@@ -403,13 +403,13 @@
uuid,
rule_uuid,
kee,
- description
+ content
)
values (
#{dto.uuid,jdbcType=VARCHAR},
#{ruleUuid,jdbcType=VARCHAR},
#{dto.key,jdbcType=VARCHAR},
- #{dto.description,jdbcType=VARCHAR}
+ #{dto.content,jdbcType=VARCHAR}
)
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index f04aa9a8c4d..b6fdecd4f33 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -811,7 +811,7 @@ CREATE TABLE "RULE_DESC_SECTIONS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"RULE_UUID" CHARACTER VARYING(40) NOT NULL,
"KEE" CHARACTER VARYING(50) NOT NULL,
- "DESCRIPTION" CHARACTER LARGE OBJECT NOT NULL
+ "CONTENT" CHARACTER LARGE OBJECT NOT NULL
);
ALTER TABLE "RULE_DESC_SECTIONS" ADD CONSTRAINT "PK_RULE_DESC_SECTIONS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_RULE_DESC_SECTIONS_KEE" ON "RULE_DESC_SECTIONS"("RULE_UUID" NULLS FIRST, "KEE" NULLS FIRST);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
index 5e4912e4e64..3806c062f8f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
@@ -73,14 +73,14 @@ public class QualityProfileExportDaoTest {
String language = "java";
RuleDefinitionDto ruleTemplate = createRule(language);
RuleDefinitionDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getUuid());
- var customRuleDescription = customRule.getDefaultRuleDescriptionSectionDto().getDescription();
+ var customRuleContent = customRule.getDefaultRuleDescriptionSectionDto().getContent();
RuleMetadataDto customRuleMetadata = createRuleMetadata(new RuleMetadataDto()
.setRuleUuid(customRule.getUuid())
.setNoteData("Extended description")
.setTags(Sets.newHashSet("tag1", "tag2", "tag3")));
RuleDefinitionDto rule = createRule(language, RuleStatus.READY, null);
- var ruleDescription = rule.getDefaultRuleDescriptionSectionDto().getDescription();
+ var ruleContent = rule.getDefaultRuleDescriptionSectionDto().getContent();
RuleMetadataDto ruleMetadata = createRuleMetadata(new RuleMetadataDto()
.setRuleUuid(rule.getUuid()));
QProfileDto profile = createProfile(language);
@@ -96,7 +96,7 @@ public class QualityProfileExportDaoTest {
assertThat(exportCustomRuleDto).isNotNull();
assertThat(exportCustomRuleDto.isCustomRule()).isTrue();
assertThat(exportCustomRuleDto.getParams()).isEmpty();
- assertThat(exportCustomRuleDto.getRuleDescriptionSections().iterator().next().getDescription()).isEqualTo(customRuleDescription);
+ assertThat(exportCustomRuleDto.getRuleDescriptionSections().iterator().next().getContent()).isEqualTo(customRuleContent);
assertThat(exportCustomRuleDto.getExtendedDescription()).isEqualTo(customRuleMetadata.getNoteData());
assertThat(exportCustomRuleDto.getName()).isEqualTo(customRule.getName());
assertThat(exportCustomRuleDto.getRuleKey()).isEqualTo(customRule.getKey());
@@ -112,7 +112,7 @@ public class QualityProfileExportDaoTest {
assertThat(exportRuleDto).isNotNull();
assertThat(exportRuleDto.isCustomRule()).isFalse();
assertThat(exportRuleDto.getParams()).isEmpty();
- assertThat(exportRuleDto.getRuleDescriptionSections().iterator().next().getDescription()).isEqualTo(ruleDescription);
+ assertThat(exportRuleDto.getRuleDescriptionSections().iterator().next().getContent()).isEqualTo(ruleContent);
assertThat(exportRuleDto.getExtendedDescription()).isEqualTo(ruleMetadata.getNoteData());
assertThat(exportRuleDto.getName()).isEqualTo(rule.getName());
assertThat(exportRuleDto.getRuleKey()).isEqualTo(rule.getKey());
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
index 4654954af46..849392b92d7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
@@ -31,6 +31,7 @@ import java.util.Set;
import java.util.function.Consumer;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.ibatis.exceptions.PersistenceException;
+import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
@@ -547,7 +548,7 @@ public class RuleDaoTest {
RuleDescriptionSectionDto newSection = RuleDescriptionSectionDto.builder()
.uuid(randomAlphanumeric(20))
.key("new_key")
- .description(randomAlphanumeric(1000))
+ .content(randomAlphanumeric(1000))
.build();
rule.addRuleDescriptionSectionDto(newSection);
@@ -569,7 +570,7 @@ public class RuleDaoTest {
RuleDescriptionSectionDto replacingSection = RuleDescriptionSectionDto.builder()
.uuid(randomAlphanumeric(20))
.key(existingSection.getKey())
- .description(randomAlphanumeric(1000))
+ .content(randomAlphanumeric(1000))
.build();
rule.addOrReplaceRuleDescriptionSectionDto(replacingSection);
@@ -837,7 +838,7 @@ public class RuleDaoTest {
RuleDescriptionSectionDto ruleDescriptionSectionDto = RuleDescriptionSectionDto.builder()
.key("DESC")
.uuid("uuid")
- .description("my description")
+ .content("my description")
.build();
RuleDefinitionDto r1 = db.rules().insert(r -> {
r.addRuleDescriptionSectionDto(ruleDescriptionSectionDto);
@@ -846,11 +847,14 @@ public class RuleDaoTest {
underTest.selectIndexingRules(db.getSession(), accumulator);
- assertThat(accumulator.list)
+ RuleForIndexingDto firstRule = findRuleForIndexingWithUuid(accumulator, r1.getUuid());
+ RuleForIndexingDto secondRule = findRuleForIndexingWithUuid(accumulator, r2.getUuid());
+
+ assertThat(Arrays.asList(firstRule, secondRule))
.extracting(RuleForIndexingDto::getUuid, RuleForIndexingDto::getRuleKey)
.containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()), tuple(r2.getUuid(), r2.getKey()));
Iterator it = accumulator.list.iterator();
- RuleForIndexingDto firstRule = it.next();
+
assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey());
assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey());
@@ -874,7 +878,6 @@ public class RuleDaoTest {
assertThat(firstRule.getCreatedAt()).isEqualTo(r1.getCreatedAt());
assertThat(firstRule.getUpdatedAt()).isEqualTo(r1.getUpdatedAt());
- RuleForIndexingDto secondRule = it.next();
assertThat(secondRule.isExternal()).isTrue();
}
@@ -888,8 +891,8 @@ public class RuleDaoTest {
underTest.selectIndexingRules(db.getSession(), accumulator);
assertThat(accumulator.list).hasSize(2);
- RuleForIndexingDto firstRule = accumulator.list.get(0);
- RuleForIndexingDto secondRule = accumulator.list.get(1);
+ RuleForIndexingDto firstRule = findRuleForIndexingWithUuid(accumulator, r1.getUuid());
+ RuleForIndexingDto secondRule = findRuleForIndexingWithUuid(accumulator, r2.getUuid());
assertRuleDefinitionFieldsAreEquals(r1, firstRule);
assertRuleMetadataFieldsAreEquals(r1Metadatas, firstRule);
@@ -900,6 +903,13 @@ public class RuleDaoTest {
assertThat(secondRule.getTemplateRepository()).isEqualTo(r1.getRepositoryKey());
}
+ @NotNull
+ private static RuleForIndexingDto findRuleForIndexingWithUuid(Accumulator accumulator, String uuid) {
+ return accumulator.list.stream()
+ .filter(rule -> rule.getUuid().equals(uuid))
+ .findFirst().orElseThrow();
+ }
+
@Test
public void scrollIndexingRulesByKeys() {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
new file mode 100644
index 00000000000..229a1860930
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.db.rule;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class RuleDescriptionSectionDtoTest {
+ private static final RuleDescriptionSectionDto SECTION = RuleDescriptionSectionDto.builder()
+ .key("key")
+ .uuid("uuid")
+ .content("desc").build();
+
+ @Test
+ public void testEquals() {
+
+ Assertions.assertThat(RuleDescriptionSectionDto.builder()
+ .key("key")
+ .uuid("uuid")
+ .content("desc")
+ .build())
+ .isEqualTo(SECTION);
+
+ Assertions.assertThat(SECTION).isEqualTo(SECTION);
+ }
+
+ @Test
+ public void testToString() {
+ Assertions.assertThat(SECTION).hasToString("RuleDescriptionSectionDto[uuid='uuid', key='key', content='desc']");
+ }
+}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
index 833f932a8b2..d2c72d2ef46 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
@@ -75,6 +75,7 @@ public class RuleTesting {
}
public static RuleDefinitionDto newRuleWithoutDescriptionSection(RuleKey ruleKey) {
+ long currentTimeMillis = System.currentTimeMillis();
return new RuleDefinitionDto()
.setRepositoryKey(ruleKey.repository())
.setRuleKey(ruleKey.rule())
@@ -92,10 +93,11 @@ public class RuleTesting {
.setLanguage("lang_" + randomAlphanumeric(3))
.setGapDescription("gapDescription_" + randomAlphanumeric(5))
.setDefRemediationBaseEffort(nextInt(10) + "h")
- .setDefRemediationGapMultiplier(nextInt(10) + "h")
+ //voluntarily offset the remediation to be able to detect issues
+ .setDefRemediationGapMultiplier((nextInt(10) + 10) + "h")
.setDefRemediationFunction("LINEAR_OFFSET")
- .setCreatedAt(System.currentTimeMillis())
- .setUpdatedAt(System.currentTimeMillis())
+ .setCreatedAt(currentTimeMillis)
+ .setUpdatedAt(currentTimeMillis + 5)
.setScope(Scope.MAIN);
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java
index 233dff60d44..b9bf5f88018 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java
@@ -42,7 +42,7 @@ public class CreateRuleDescSectionsTable extends CreateTableChange {
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setIsNullable(false).setLimit(50).build())
- .addColumn(newClobColumnDefBuilder().setColumnName("description").setIsNullable(false).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName("content").setIsNullable(false).build())
.build());
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java
index 84d46409d4c..2306f580e56 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java
@@ -31,7 +31,7 @@ public class DbVersion95 implements DbVersion {
.add(6403, "Upsert value of type in 'user_tokens'", UpsertUserTokensTypeValue.class)
.add(6404, "Make column 'type' in 'user_tokens' not nullable", MakeTypeColumnNotNullableOnUserTokens.class)
.add(6405, "Create table RULE_DESC_SECTIONS", CreateRuleDescSectionsTable.class)
- .add(6406, "Insert descriptions from RULES into RULE_DESC_SECTIONS", InsertRuleDescriptionIntoRuleDescSections.class)
+ .add(6406, "Insert description from RULES into RULE_DESC_SECTIONS", InsertRuleDescriptionIntoRuleDescSections.class)
.add(6407, "Create index for RULE_DESC_SECTIONS", CreateIndexForRuleDescSections.class)
.add(6408, "Drop column DESCRIPTIONS from RULES table", DropRuleDescriptionColumn.class)
;
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSections.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSections.java
index 2cec6a3f2a7..97ab8896093 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSections.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSections.java
@@ -36,7 +36,7 @@ public class InsertRuleDescriptionIntoRuleDescSections extends DataChange {
private static final String SELECT_EXISTING_RULE_DESCRIPTIONS = "select uuid, description from rules where description is not null "
+ "and uuid not in (select rule_uuid from " + RULE_DESCRIPTION_SECTIONS_TABLE + ")";
- private static final String INSERT_INTO_RULE_DESC_SECTIONS = "insert into " + RULE_DESCRIPTION_SECTIONS_TABLE + " (uuid, rule_uuid, kee, description) values "
+ private static final String INSERT_INTO_RULE_DESC_SECTIONS = "insert into " + RULE_DESCRIPTION_SECTIONS_TABLE + " (uuid, rule_uuid, kee, content) values "
+ "(?,?,?,?)";
private final UuidFactory uuidFactory;
@@ -60,7 +60,7 @@ public class InsertRuleDescriptionIntoRuleDescSections extends DataChange {
insertRuleDescSections(context, selectRuleDb);
}
- private List findExistingRuleDescriptions(Context context) throws SQLException {
+ private static List findExistingRuleDescriptions(Context context) throws SQLException {
return context.prepareSelect(SELECT_EXISTING_RULE_DESCRIPTIONS)
.list(r -> new RuleDb(r.getString(1), r.getString(2)));
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest.java
index 7022cf49b60..ffc2d4e5a9a 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest.java
@@ -72,7 +72,7 @@ public class CreateIndexForRuleDescSectionsTest {
ruleParams.put("uuid", RandomStringUtils.randomAlphanumeric(40));
ruleParams.put("rule_uuid", ruleUuid);
ruleParams.put("kee", key);
- ruleParams.put("description", "descriptions");
+ ruleParams.put("content", "content blablablabla");
db.executeInsert("rule_desc_sections", ruleParams);
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest.java
index eb717af0e07..69c018e7389 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest.java
@@ -96,12 +96,12 @@ public class InsertRuleDescriptionIntoRuleDescSectionsTest {
assertThat(result1)
.containsEntry("RULE_UUID", uuid1)
.containsEntry("KEE", DEFAULT_DESCRIPTION_KEY)
- .containsEntry("DESCRIPTION", description1)
+ .containsEntry("CONTENT", description1)
.extractingByKey("UUID").isNotNull();
}
private Map findRuleSectionDescription(String uuid) {
- return db.selectFirst("select uuid, kee, rule_uuid, description from "
+ return db.selectFirst("select uuid, kee, rule_uuid, content from "
+ RULE_DESCRIPTION_SECTIONS_TABLE + " where rule_uuid = '" + uuid + "'");
}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest/schema.sql
index b0f0270437e..2a49eaf32d2 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest/schema.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest/schema.sql
@@ -2,6 +2,6 @@ CREATE TABLE "RULE_DESC_SECTIONS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"RULE_UUID" CHARACTER VARYING(40) NOT NULL,
"KEE" CHARACTER VARYING(50) NOT NULL,
- "DESCRIPTION" CHARACTER LARGE OBJECT NOT NULL
+ "CONTENT" CHARACTER LARGE OBJECT NOT NULL
);
ALTER TABLE "RULE_DESC_SECTIONS" ADD CONSTRAINT "PK_RULE_DESC_SECTIONS" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest/schema.sql
index f7d903dcf47..1b23e275ba2 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest/schema.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest/schema.sql
@@ -2,7 +2,7 @@ CREATE TABLE "RULE_DESC_SECTIONS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"RULE_UUID" CHARACTER VARYING(40) NOT NULL,
"KEE" CHARACTER VARYING(50) NOT NULL,
- "DESCRIPTION" CHARACTER LARGE OBJECT NOT NULL
+ "CONTENT" CHARACTER LARGE OBJECT NOT NULL
);
ALTER TABLE "RULE_DESC_SECTIONS" ADD CONSTRAINT "PK_RULE_DESC_SECTIONS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_RULE_DESC_SECTIONS_KEE" ON "RULE_DESC_SECTIONS"("RULE_UUID" NULLS FIRST, "KEE" NULLS FIRST);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java
index f4a61eec7cd..0bfb7851a1a 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java
@@ -71,9 +71,9 @@ public class RuleDescriptionFormatter {
"Rule " + descriptionFormat + " contains section(s) but has no format set");
switch (nonNullDescriptionFormat) {
case MARKDOWN:
- return Markdown.convertToHtml(ruleDescriptionSectionDto.getDescription());
+ return Markdown.convertToHtml(ruleDescriptionSectionDto.getContent());
case HTML:
- return ruleDescriptionSectionDto.getDescription();
+ return ruleDescriptionSectionDto.getContent();
default:
throw new IllegalStateException(format("Rule description section format '%s' is unknown for rule key '%s'", descriptionFormat, ruleKey));
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java
index 25e492ebb80..e550548cbdf 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java
@@ -48,7 +48,7 @@ public class RuleDescriptionFormatterTest {
public void getHtmlDescriptionAsIs() {
RuleDefinitionDto rule = new RuleDefinitionDto().setDescriptionFormat(RuleDto.Format.HTML).addRuleDescriptionSectionDto(HTML_SECTION);
String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
- assertThat(html).isEqualTo(HTML_SECTION.getDescription());
+ assertThat(html).isEqualTo(HTML_SECTION.getContent());
}
@Test
@@ -69,10 +69,10 @@ public class RuleDescriptionFormatterTest {
@Test
public void getHtmlDescriptionForRuleForIndexingDtoAsIs() {
Set sectionsDtos = Sets.newHashSet(
- createDefaultRuleDescriptionSection("uuid", HTML_SECTION.getDescription()));
+ createDefaultRuleDescriptionSection("uuid", HTML_SECTION.getContent()));
RuleForIndexingDto rule = createRuleForIndexingDto(sectionsDtos, RuleDto.Format.HTML);
String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
- assertThat(html).isEqualTo(HTML_SECTION.getDescription());
+ assertThat(html).isEqualTo(HTML_SECTION.getContent());
}
@Test
@@ -85,7 +85,7 @@ public class RuleDescriptionFormatterTest {
@Test
public void handleNullDescriptionFormatForRuleForIndexingDto() {
Set sectionsDtos = Sets.newHashSet(
- createDefaultRuleDescriptionSection("uuid", HTML_SECTION.getDescription()));
+ createDefaultRuleDescriptionSection("uuid", HTML_SECTION.getContent()));
RuleForIndexingDto rule = createRuleForIndexingDto(sectionsDtos, null);
String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
assertThat(result).isNull();
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
index 57db0bb1390..da0ca92e525 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
@@ -422,7 +422,7 @@ public class CachingRuleFinderTest {
assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0]));
assertThat(rule.getTags()).isEmpty();
- assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDefaultRuleDescriptionSectionDto().getDescription());
+ assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDefaultRuleDescriptionSectionDto().getContent());
assertThat(rule.getParams()).hasSize(1);
org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next();
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
index 5540f8f376c..42a9db4f2eb 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -57,6 +57,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.rule.DeprecatedRuleKeyDto;
import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDescriptionSectionDto;
import org.sonar.db.rule.RuleDto.Format;
import org.sonar.db.rule.RuleDto.Scope;
import org.sonar.db.rule.RuleParamDto;
@@ -400,12 +401,16 @@ public class RegisterRules implements Startable {
.setIsAdHoc(false)
.setCreatedAt(system2.now())
.setUpdatedAt(system2.now());
- if (isNotEmpty(ruleDef.htmlDescription())) {
- ruleDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), ruleDef.htmlDescription()));
+ String htmlDescription = ruleDef.htmlDescription();
+ if (isNotEmpty(htmlDescription)) {
+ ruleDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), htmlDescription));
ruleDto.setDescriptionFormat(Format.HTML);
- } else if (isNotEmpty(ruleDef.markdownDescription())) {
- ruleDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), ruleDef.markdownDescription()));
- ruleDto.setDescriptionFormat(Format.MARKDOWN);
+ } else {
+ String markdownDescription = ruleDef.markdownDescription();
+ if (isNotEmpty(markdownDescription)) {
+ ruleDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), markdownDescription));
+ ruleDto.setDescriptionFormat(Format.MARKDOWN);
+ }
}
DebtRemediationFunction debtRemediationFunction = ruleDef.debtRemediationFunction();
@@ -487,25 +492,26 @@ public class RegisterRules implements Startable {
private boolean mergeDescription(RulesDefinition.Rule rule, RuleDefinitionDto ruleDefinitionDto) {
boolean changed = false;
- String currentDescription = ruleDefinitionDto.getDefaultRuleDescriptionSectionDto() != null ? ruleDefinitionDto.getDefaultRuleDescriptionSectionDto().getDescription() : null;
- if (isHtmlDescriptionUpdated(rule, currentDescription)) {
- ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), rule.htmlDescription()));
+ String currentDescription = Optional.ofNullable(ruleDefinitionDto.getDefaultRuleDescriptionSectionDto())
+ .map(RuleDescriptionSectionDto::getContent)
+ .orElse(null);
+
+ String htmlDescription = rule.htmlDescription();
+ String markdownDescription = rule.markdownDescription();
+ if (isDescriptionUpdated(htmlDescription, currentDescription)) {
+ ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), htmlDescription));
ruleDefinitionDto.setDescriptionFormat(Format.HTML);
changed = true;
- } else if (isMarkdownDescriptionUpdated(rule, currentDescription)) {
- ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), rule.markdownDescription()));
+ } else if (isDescriptionUpdated(markdownDescription, currentDescription)) {
+ ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), markdownDescription));
ruleDefinitionDto.setDescriptionFormat(Format.MARKDOWN);
changed = true;
}
return changed;
}
- private static boolean isMarkdownDescriptionUpdated(RulesDefinition.Rule rule, @Nullable String currentDescription) {
- return isNotEmpty(rule.markdownDescription()) && !Objects.equals(rule.markdownDescription(), currentDescription);
- }
-
- private static boolean isHtmlDescriptionUpdated(RulesDefinition.Rule def, @Nullable String currentDescription) {
- return isNotEmpty(def.htmlDescription()) && !Objects.equals(def.htmlDescription(), currentDescription);
+ private static boolean isDescriptionUpdated(@Nullable String description, @Nullable String currentDescription) {
+ return isNotEmpty(description) && !Objects.equals(description, currentDescription);
}
private static boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDefinitionDto dto) {
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
index 34d1c8deaad..5f45832020f 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
@@ -49,6 +49,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.rule.DeprecatedRuleKeyDto;
import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.rule.RuleDescriptionSectionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleDto.Scope;
import org.sonar.db.rule.RuleParamDto;
@@ -88,6 +89,7 @@ import static org.sonar.api.server.rule.RulesDefinition.NewRepository;
import static org.sonar.api.server.rule.RulesDefinition.NewRule;
import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10;
import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021;
+import static org.sonar.db.rule.RuleDescriptionSectionDto.DEFAULT_KEY;
import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection;
@RunWith(DataProviderRunner.class)
@@ -140,7 +142,7 @@ public class RegisterRulesTest {
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3);
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
assertThat(rule1.getName()).isEqualTo("One");
- assertThat(rule1.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Description of One");
+ assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One");
assertThat(rule1.getSeverityString()).isEqualTo(BLOCKER);
assertThat(rule1.getTags()).isEmpty();
assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag2", "tag3");
@@ -159,7 +161,7 @@ public class RegisterRulesTest {
RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), HOTSPOT_RULE_KEY);
assertThat(hotspotRule.getName()).isEqualTo("Hotspot");
- assertThat(hotspotRule.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Minimal hotspot");
+ assertThat(hotspotRule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Minimal hotspot");
assertThat(hotspotRule.getCreatedAt()).isEqualTo(DATE1.getTime());
assertThat(hotspotRule.getUpdatedAt()).isEqualTo(DATE1.getTime());
assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant());
@@ -188,7 +190,7 @@ public class RegisterRulesTest {
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(2);
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), EXTERNAL_RULE_KEY1);
assertThat(rule1.getName()).isEqualTo("One");
- assertThat(rule1.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Description of One");
+ assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One");
assertThat(rule1.getSeverityString()).isEqualTo(BLOCKER);
assertThat(rule1.getTags()).isEmpty();
assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag2", "tag3");
@@ -207,7 +209,7 @@ public class RegisterRulesTest {
RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), EXTERNAL_HOTSPOT_RULE_KEY);
assertThat(hotspotRule.getName()).isEqualTo("Hotspot");
- assertThat(hotspotRule.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Minimal hotspot");
+ assertThat(hotspotRule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Minimal hotspot");
assertThat(hotspotRule.getCreatedAt()).isEqualTo(DATE1.getTime());
assertThat(hotspotRule.getUpdatedAt()).isEqualTo(DATE1.getTime());
assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant());
@@ -334,18 +336,7 @@ public class RegisterRulesTest {
verifyIndicesNotMarkedAsInitialized();
// rule1 has been updated
rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
- assertThat(rule1.getName()).isEqualTo("One v2");
- assertThat(rule1.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Description of One v2");
- assertThat(rule1.getSeverityString()).isEqualTo(INFO);
- assertThat(rule1.getTags()).containsOnly("usertag1", "usertag2");
- assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag4");
- assertThat(rule1.getConfigKey()).isEqualTo("config1 v2");
- assertThat(rule1.getNoteData()).isEqualTo("user *note*");
- assertThat(rule1.getNoteUserUuid()).isEqualTo("marius");
- assertThat(rule1.getStatus()).isEqualTo(READY);
- assertThat(rule1.getType()).isEqualTo(RuleType.BUG.getDbConstant());
- assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime());
- assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2.getTime());
+ assertThatRule1IsV2(rule1);
List params = dbClient.ruleDao().selectRuleParamsByRuleKey(db.getSession(), RULE_KEY1);
assertThat(params).hasSize(2);
@@ -368,6 +359,30 @@ public class RegisterRulesTest {
// verify repositories
assertThat(dbClient.ruleRepositoryDao().selectAll(db.getSession())).extracting(RuleRepositoryDto::getKey).containsOnly("fake");
+
+ system.setNow(DATE3.getTime());
+ execute(new FakeRepositoryV3());
+ rule3 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY3);
+ assertThat(rule3.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Rule Three V2");
+ assertThat(rule3.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN);
+ }
+
+ private void assertThatRule1IsV2(RuleDto rule1) {
+ assertThat(rule1.getName()).isEqualTo("One v2");
+ RuleDescriptionSectionDto defaultRuleDescriptionSection = rule1.getDefaultRuleDescriptionSection();
+ assertThat(defaultRuleDescriptionSection.getContent()).isEqualTo("Description of One v2");
+ assertThat(defaultRuleDescriptionSection.getKey()).isEqualTo(DEFAULT_KEY);
+ assertThat(rule1.getDescriptionFormat()).isEqualTo(RuleDto.Format.HTML);
+ assertThat(rule1.getSeverityString()).isEqualTo(INFO);
+ assertThat(rule1.getTags()).containsOnly("usertag1", "usertag2");
+ assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag4");
+ assertThat(rule1.getConfigKey()).isEqualTo("config1 v2");
+ assertThat(rule1.getNoteData()).isEqualTo("user *note*");
+ assertThat(rule1.getNoteUserUuid()).isEqualTo("marius");
+ assertThat(rule1.getStatus()).isEqualTo(READY);
+ assertThat(rule1.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+ assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime());
+ assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2.getTime());
}
@Test
@@ -449,7 +464,7 @@ public class RegisterRulesTest {
// rule1 has been updated
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("fake", "rule"));
assertThat(rule1.getName()).isEqualTo("Name2");
- assertThat(rule1.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Description");
+ assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description");
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isOne();
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero();
@@ -528,7 +543,7 @@ public class RegisterRulesTest {
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository, ruleKey2));
assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo("Name2");
- assertThat(rule2.getDefaultRuleDescriptionSection().getDescription()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getDescription());
+ assertThat(rule2.getDefaultRuleDescriptionSection().getContent()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getContent());
SearchIdResult searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid());
@@ -570,7 +585,7 @@ public class RegisterRulesTest {
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository2, ruleKey));
assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo("Name2");
- assertThat(rule2.getDefaultRuleDescriptionSection().getDescription()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getDescription());
+ assertThat(rule2.getDefaultRuleDescriptionSection().getContent()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getContent());
SearchIdResult searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid());
@@ -610,7 +625,7 @@ public class RegisterRulesTest {
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repo2, ruleKey2));
assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo(rule1.getName());
- assertThat(rule2.getDefaultRuleDescriptionSection().getDescription()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getDescription());
+ assertThat(rule2.getDefaultRuleDescriptionSection().getContent()).isEqualTo(rule1.getDefaultRuleDescriptionSection().getContent());
assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getUuids())
.containsOnly(rule2.getUuid());
@@ -688,7 +703,7 @@ public class RegisterRulesTest {
// rule1 has been updated
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("fake", "rule"));
assertThat(rule1.getName()).isEqualTo("Name");
- assertThat(rule1.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Desc2");
+ assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Desc2");
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isOne();
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc1"), new SearchOptions()).getTotal()).isZero();
@@ -702,7 +717,7 @@ public class RegisterRulesTest {
NewRepository repo = context.createExternalRepository("fake", rule.getLanguage());
repo.createRule(rule.getRuleKey())
.setName(rule.getName())
- .setHtmlDescription(rule.getDefaultRuleDescriptionSectionDto().getDescription());
+ .setHtmlDescription(rule.getDefaultRuleDescriptionSectionDto().getContent());
repo.done();
});
@@ -1100,6 +1115,19 @@ public class RegisterRulesTest {
}
}
+ static class FakeRepositoryV3 implements RulesDefinition {
+ @Override
+ public void define(Context context) {
+ NewRepository repo = context.createRepository("fake", "java");
+ // rule 3 is dropped
+ repo.createRule(RULE_KEY3.rule())
+ .setName("Three")
+ .setMarkdownDescription("Rule Three V2");
+
+ repo.done();
+ }
+ }
+
static class ExternalRuleRepository implements RulesDefinition {
@Override
public void define(Context context) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
index de4bbb89cf6..bf324780112 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
@@ -102,7 +102,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
importedRule.setType(exportRuleDto.getRuleType().name());
exportRuleDto.getRuleDescriptionSections()
.stream()
- .map(r -> new NewRuleDescriptionSection(r.getKey(), r.getDescription()))
+ .map(r -> new NewRuleDescriptionSection(r.getKey(), r.getContent()))
.forEach(importedRule::addRuleDescriptionSection);
importedRule.setParameters(exportRuleDto.getParams().stream().collect(Collectors.toMap(ExportRuleParamDto::getKey, ExportRuleParamDto::getValue)));
importedRules.add(importedRule);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileParser.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileParser.java
index f345d2fc4d4..ec4db716e3c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileParser.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileParser.java
@@ -55,7 +55,7 @@ public class QProfileParser {
private static final String ATTRIBUTE_DESCRIPTION_SECTIONS = "descriptionSections";
private static final String ATTRIBUTE_DESCRIPTION_SECTION = "descriptionSection";
private static final String ATTRIBUTE_DESCRIPTION_SECTION_KEY = "key";
- private static final String ATTRIBUTE_DESCRIPTION_SECTION_DESCRIPTION = "content";
+ private static final String ATTRIBUTE_DESCRIPTION_SECTION_CONTENT = "content";
private static final String ATTRIBUTE_REPOSITORY_KEY = "repositoryKey";
private static final String ATTRIBUTE_KEY = "key";
private static final String ATTRIBUTE_PRIORITY = "priority";
@@ -87,14 +87,14 @@ public class QProfileParser {
xml.prop(ATTRIBUTE_TEMPLATE_KEY, ruleToExport.getTemplateRuleKey().rule());
if (!ruleToExport.getRuleDescriptionSections().isEmpty()) {
ruleToExport.getDefaultRuleDescriptionSectionDto()
- .map(RuleDescriptionSectionDto::getDescription)
+ .map(RuleDescriptionSectionDto::getContent)
.ifPresent(desc -> xml.prop(ATTRIBUTE_DESCRIPTION, desc));
}
xml.begin(ATTRIBUTE_DESCRIPTION_SECTIONS);
for (RuleDescriptionSectionDto ruleDescriptionSection : ruleToExport.getRuleDescriptionSections()) {
xml.begin(ATTRIBUTE_DESCRIPTION_SECTION)
.prop(ATTRIBUTE_DESCRIPTION_SECTION_KEY, ruleDescriptionSection.getKey())
- .prop(ATTRIBUTE_DESCRIPTION_SECTION_DESCRIPTION, ruleDescriptionSection.getDescription())
+ .prop(ATTRIBUTE_DESCRIPTION_SECTION_CONTENT, ruleDescriptionSection.getContent())
.end();
}
xml.end(ATTRIBUTE_DESCRIPTION_SECTIONS);
@@ -234,7 +234,7 @@ public class QProfileParser {
String nodeName = propCursor.getLocalName();
if (StringUtils.equals(ATTRIBUTE_DESCRIPTION_SECTION_KEY, nodeName)) {
key = StringUtils.trim(propCursor.collectDescendantText(false));
- } else if (StringUtils.equals(ATTRIBUTE_DESCRIPTION_SECTION_DESCRIPTION, nodeName)) {
+ } else if (StringUtils.equals(ATTRIBUTE_DESCRIPTION_SECTION_CONTENT, nodeName)) {
description = StringUtils.trim(propCursor.collectDescendantText(false));
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/NewRuleDescriptionSection.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/NewRuleDescriptionSection.java
index 081262028d2..7ab1ed79522 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/NewRuleDescriptionSection.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/NewRuleDescriptionSection.java
@@ -22,18 +22,18 @@ package org.sonar.server.rule;
public class NewRuleDescriptionSection {
private final String key;
- private final String description;
+ private final String content;
- public NewRuleDescriptionSection(String key, String description) {
+ public NewRuleDescriptionSection(String key, String content) {
this.key = key;
- this.description = description;
+ this.content = content;
}
public String getKey() {
return key;
}
- public String getDescription() {
- return description;
+ public String getContent() {
+ return content;
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
index 4b36e35c7f6..1834a4a76cb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
@@ -177,7 +177,7 @@ public class RuleCreator {
}
private static boolean noDescriptionSectionHasContent(NewCustomRule newRule) {
- return newRule.getRuleDescriptionSections().stream().map(NewRuleDescriptionSection::getDescription).allMatch(Strings::isNullOrEmpty);
+ return newRule.getRuleDescriptionSections().stream().map(NewRuleDescriptionSection::getContent).allMatch(Strings::isNullOrEmpty);
}
private static void validateRuleKey(List errors, String ruleKey) {
@@ -224,7 +224,7 @@ public class RuleCreator {
RuleDescriptionSectionDto ruleDescriptionSectionDto = RuleDescriptionSectionDto.builder()
.uuid(uuidFactory.create())
.key(ruleDescriptionSection.getKey())
- .description(ruleDescriptionSection.getDescription())
+ .content(ruleDescriptionSection.getContent())
.build();
ruleDefinition.addRuleDescriptionSectionDto(ruleDescriptionSectionDto);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java
index a3245751914..9eaa2f03fc9 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java
@@ -66,7 +66,7 @@ public class ListAction implements RulesWsAction {
listResponseBuilder.build().writeTo(wsResponse.stream().output());
}
- private ListResponse.Rule toRule(ListResponse.Rule.Builder ruleBuilder, RuleDefinitionDto dto) {
+ private static ListResponse.Rule toRule(ListResponse.Rule.Builder ruleBuilder, RuleDefinitionDto dto) {
return ruleBuilder
.clear()
.setRepository(dto.getRepositoryKey())
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
index 4b4afd81a9a..9095b67cceb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
@@ -340,7 +340,7 @@ public class RuleMapper {
private static String concatenateSectionTemporaryForSonar16302(RuleDefinitionDto ruleDto) {
return ruleDto.getRuleDescriptionSectionDtos().stream()
- .map(RuleDescriptionSectionDto::getDescription)
+ .map(RuleDescriptionSectionDto::getContent)
.collect(joining());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
index 542424a8661..a1b2120ef7c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
@@ -166,8 +166,8 @@ public class QProfileBackuperImplTest {
"" + activeRule.getSeverityString() + "" +
"" + rule.getName() + "" +
"" + templateRule.getKey().rule() + "" +
- "" + rule.getDefaultRuleDescriptionSectionDto().getDescription() + "" +
- "default" + rule.getDefaultRuleDescriptionSectionDto().getDescription() + "" +
+ "" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "" +
+ "default" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "" +
"" +
"" + param.getName() + "" +
"20" +
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileParserTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileParserTest.java
index aab08268815..f832b5fdce4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileParserTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileParserTest.java
@@ -67,7 +67,7 @@ public class QProfileParserTest {
"CRITICAL" +
"custom rule name" +
"rule_mc8" +
- "defaultcustom rule description" +
+ "defaultcustom rule section content" +
"" +
"bar" +
"baz" +
@@ -81,6 +81,6 @@ public class QProfileParserTest {
assertThat(importedRule.getRuleDescriptionSections()).hasSize(1);
var section = importedRule.getRuleDescriptionSections().iterator().next();
assertThat(section.getKey()).isEqualTo("default");
- assertThat(section.getDescription()).isEqualTo("custom rule description");
+ assertThat(section.getContent()).isEqualTo("custom rule section content");
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
index 428f4d4ed04..4e850f33292 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
@@ -96,7 +96,7 @@ public class RuleCreatorTest {
assertThat(rule.getPluginKey()).isEqualTo("sonarjava");
assertThat(rule.getTemplateUuid()).isEqualTo(templateRule.getUuid());
assertThat(rule.getName()).isEqualTo("My custom");
- assertThat(rule.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("Some description");
+ assertThat(rule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Some description");
assertThat(rule.getSeverityString()).isEqualTo("MAJOR");
assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY);
assertThat(rule.getLanguage()).isEqualTo("java");
@@ -144,7 +144,7 @@ public class RuleCreatorTest {
assertThat(rule.getPluginKey()).isEqualTo("sonarjava");
assertThat(rule.getTemplateUuid()).isEqualTo(templateRule.getUuid());
assertThat(rule.getName()).isEqualTo("My custom");
- assertThat(rule.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("new description section");
+ assertThat(rule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("new description section");
assertThat(rule.getSeverityString()).isEqualTo("MAJOR");
assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY);
assertThat(rule.getLanguage()).isEqualTo("java");
@@ -345,7 +345,7 @@ public class RuleCreatorTest {
// These values should be the same than before
assertThat(result.getName()).isEqualTo("Old name");
- assertThat(result.getDefaultRuleDescriptionSectionDto().getDescription()).isEqualTo("Old description");
+ assertThat(result.getDefaultRuleDescriptionSectionDto().getContent()).isEqualTo("Old description");
assertThat(result.getSeverityString()).isEqualTo(Severity.INFO);
List params = dbTester.getDbClient().ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
index 8cce0607d88..bc9480a8981 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
@@ -367,7 +367,7 @@ public class RuleUpdaterTest {
RuleDto customRuleReloaded = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, customRule.getKey());
assertThat(customRuleReloaded).isNotNull();
assertThat(customRuleReloaded.getName()).isEqualTo("New name");
- assertThat(customRuleReloaded.getDefaultRuleDescriptionSection().getDescription()).isEqualTo("New description");
+ assertThat(customRuleReloaded.getDefaultRuleDescriptionSection().getContent()).isEqualTo("New description");
assertThat(customRuleReloaded.getSeverityString()).isEqualTo("MAJOR");
assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.READY);
--
2.39.5