]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16302 Renamed RULE_DESC_SECTIONS.DESCRIPTION to RULE_DESC_SECTIONS.CONTENT...
authorAurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com>
Thu, 28 Apr 2022 13:10:35 +0000 (15:10 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 6 May 2022 20:02:43 +0000 (20:02 +0000)
31 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java [new file with mode: 0644]
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSections.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/CreateIndexForRuleDescSectionsTest/schema.sql
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/InsertRuleDescriptionIntoRuleDescSectionsTest/schema.sql
server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileParser.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/NewRuleDescriptionSection.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileParserTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java

index 0837c3e28217f7e4340ac11046b1f23e9f19e8a5..e5709520abef11d14bc775f1350d5e54f6275bfa 100644 (file)
@@ -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));
   }
index 208987e3f754df46517dd85513fce24b4c2714bf..ae91fe2bbe77a7ccc27fbb66729845b6d21e52cf 100644 (file)
@@ -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);
     }
   }
 }
index 4cea9e1e39b4ca8acd1cbec526046c8321a18608..ed94cc4598aeb0216fbae800022f6a26e901843a 100644 (file)
@@ -6,7 +6,7 @@
   <sql id="selectRuleDescriptionSectionColumns">
     rds.uuid as "rds_uuid",
     rds.kee as "rds_kee",
-    rds.description as "rds_description",
+    rds.content as "rds_content",
   </sql>
 
   <sql id="leftOuterJoinRulesDescriptionSections">
@@ -50,7 +50,7 @@
     <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto">
       <id property="uuid" column="rds_uuid"/>
       <result property="key" column="rds_kee"/>
-      <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
+      <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
     </collection>
 
   </resultMap>
index 685b9be1a727429c6d153d9bd73da9f4f95d8952..ad74a26fab4587145d7abb63f7b167cf30cfa55d 100644 (file)
@@ -6,7 +6,7 @@
   <sql id="selectRuleDescriptionSectionColumns">
     rds.uuid as "rds_uuid",
     rds.kee as "rds_kee",
-    rds.description as "rds_description",
+    rds.content as "rds_content",
   </sql>
 
   <sql id="leftOuterJoinRulesDescriptionSections">
     <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto">
       <id property="uuid" column="rds_uuid"/>
       <result property="key" column="rds_kee"/>
-      <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
+      <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
     </collection>
   </resultMap>
 
     <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto">
       <id property="uuid" column="rds_uuid"/>
       <result property="key" column="rds_kee"/>
-      <result property="description" column="rds_description" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
+      <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
     </collection>
 
   </resultMap>
       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}
     )
   </insert>
 
index f04aa9a8c4dde6f9b5270bfb14eb69116372b1b5..b6fdecd4f33925a7b8e6bf64e2dfc56f3841e94d 100644 (file)
@@ -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);
index 5e4912e4e640b8adb6466b2d7046230ecc99a463..3806c062f8ffb377106c3eef8abbf250e63c155a 100644 (file)
@@ -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());
index 4654954af46f3759c72056564982fd76e843e708..849392b92d740a9be310e735b3f52fb506225a93 100644 (file)
@@ -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<RuleForIndexingDto> 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<RuleForIndexingDto> 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 (file)
index 0000000..229a186
--- /dev/null
@@ -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']");
+  }
+}
index 833f932a8b2dc1b16b9b4b244dc50bab65e7ca8a..d2c72d2ef46d9f30726ffdb8b78b5748f580de4e 100644 (file)
@@ -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);
   }
 
index 233dff60d440c299a7b001cb7ababd3d0355a031..b9bf5f88018c6e660e15c4da630daaf1666192cd 100644 (file)
@@ -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());
   }
 }
index 84d46409d4c672b3446cacb2ccda97e8b4d053fd..2306f580e56a0ac0e67fc9c3085979077788684b 100644 (file)
@@ -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)
     ;
index 2cec6a3f2a7207d66fa2978669060ab3b4dfdf96..97ab88960930fe0d9084063ddc95c04b7025e3c5 100644 (file)
@@ -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<RuleDb> findExistingRuleDescriptions(Context context) throws SQLException {
+  private static List<RuleDb> findExistingRuleDescriptions(Context context) throws SQLException {
     return context.prepareSelect(SELECT_EXISTING_RULE_DESCRIPTIONS)
       .list(r -> new RuleDb(r.getString(1), r.getString(2)));
   }
index 7022cf49b608086f5ddd5152f27e9605011bef67..ffc2d4e5a9a6a49396580a89369292a15585feed 100644 (file)
@@ -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);
   }
index eb717af0e07473cc91f5718b9e602ea80672bd63..69c018e73890658ab20c7d37d19e82e32f4719d6 100644 (file)
@@ -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<String, Object> 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 + "'");
   }
 
index b0f0270437ebb9a14d08926a5a30149353714e04..2a49eaf32d2d3b6d32e8f6c1516ec57b50d70ab2 100644 (file)
@@ -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");
index f7d903dcf472f928fe16ec1fb404af5dd4c6e056..1b23e275ba24f9aeb17c0537d95934d1beaff69f 100644 (file)
@@ -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);
index f4a61eec7cdd47786581e6d2526816652ddd1da0..0bfb7851a1aaa76083f4e5df997a0b0c04b88c3e 100644 (file)
@@ -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));
     }
index 25e492ebb80cdc92f52aef16e7bf995f7b253f2a..e550548cbdf2e51cc0a8162ec1dc9302632905fa 100644 (file)
@@ -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<RuleDescriptionSectionDto> 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<RuleDescriptionSectionDto> 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();
index 57db0bb1390013b66dbcd25ea931b17b8c1cab74..da0ca92e525d3cb67b242d5da9e4830e51e2bac4 100644 (file)
@@ -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();
index 5540f8f376cd4dbf8a499906f8b408915d8e9516..42a9db4f2eba14c199441d9efdf3541793834f28 100644 (file)
@@ -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) {
index 34d1c8deaad3869a37460d87ae3a28e323bbc7b9..5f45832020f8e7a7fdbf0c30e0d5b9a9033aa874 100644 (file)
@@ -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<RuleParamDto> 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<String> 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<String> 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) {
index de4bbb89cf6417808feaca7036e77b8b2f5a12bd..bf32478011201f66a351981e7fc7841ac9b6c3b5 100644 (file)
@@ -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);
index f345d2fc4d49caaf3965a17a13efa9f23ba2df77..ec4db716e3caae6b137cacdf4ba0d6138804dd43 100644 (file)
@@ -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));
         }
       }
index 081262028d21a7c339033cbf906e43e2513151a5..7ab1ed79522f419d2f44d59360ab67eb601d6817 100644 (file)
@@ -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;
   }
 }
index 4b36e35c7f68c51d3fade5b5ea16cb962739a5c5..1834a4a76cbdb260950bec6f16fb669f8e05a253 100644 (file)
@@ -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<String> 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);
       }
index a32457519141779157e92b1a95c95d9a1e864abd..9eaa2f03fc975ecaf9f75e548a59dfb25db780f3 100644 (file)
@@ -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())
index 4b4afd81a9a3246d9d19cd6d66c64fecd8d6c444..9095b67cceb152ca1a01a5c1a45a668220656b69 100644 (file)
@@ -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());
   }
 
index 542424a86616da129e9321a9d60a90338518a3ae..a1b2120ef7ce0d7bc3b5743e2aa94849f1393b28 100644 (file)
@@ -166,8 +166,8 @@ public class QProfileBackuperImplTest {
       "<priority>" + activeRule.getSeverityString() + "</priority>" +
       "<name>" + rule.getName() + "</name>" +
       "<templateKey>" + templateRule.getKey().rule() + "</templateKey>" +
-      "<description>" + rule.getDefaultRuleDescriptionSectionDto().getDescription() + "</description>" +
-      "<descriptionSections><descriptionSection><key>default</key><content>" + rule.getDefaultRuleDescriptionSectionDto().getDescription() + "</content></descriptionSection></descriptionSections>" +
+      "<description>" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "</description>" +
+      "<descriptionSections><descriptionSection><key>default</key><content>" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "</content></descriptionSection></descriptionSections>" +
       "<parameters><parameter>" +
       "<key>" + param.getName() + "</key>" +
       "<value>20</value>" +
index aab0826881533b357434dc218054be74ab8157f3..f832b5fdce4b414e36a5982ed6f2297105e88bbb 100644 (file)
@@ -67,7 +67,7 @@ public class QProfileParserTest {
       "<priority>CRITICAL</priority>" +
       "<name>custom rule name</name>" +
       "<templateKey>rule_mc8</templateKey>" +
-      "<descriptionSections><descriptionSection><key>default</key><content>custom rule description</content></descriptionSection></descriptionSections>" +
+      "<descriptionSections><descriptionSection><key>default</key><content>custom rule section content</content></descriptionSection></descriptionSections>" +
       "<parameters><parameter>" +
       "<key>bar</key>" +
       "<value>baz</value>" +
@@ -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");
   }
 }
index 428f4d4ed044269ed86f3ab1ac0d233c7760d25d..4e850f33292b71744b758f6de708cc9372fb477b 100644 (file)
@@ -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<RuleParamDto> params = dbTester.getDbClient().ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
index 8cce0607d88d3028ae37ecdd5c65ea2048ff614c..bc9480a89819b88f14d7207ddcb7846335e61c23 100644 (file)
@@ -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);