]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20021 Add clean code attribute to RuleDto and IssueDto
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Wed, 2 Aug 2023 09:31:28 +0000 (11:31 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Aug 2023 20:02:47 +0000 (20:02 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/rule/RuleDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java

index 5a3f2a1214c648e6a6e6629032403b1605c4d455..6d6d1f8d4c8d5d333932bbf513098d261d98b180 100644 (file)
@@ -142,7 +142,7 @@ public class IssueDaoIT {
     IssueDto issue = underTest.selectOrFailByKey(db.getSession(), ISSUE_KEY1);
 
     assertThat(issue).usingRecursiveComparison()
-      .ignoringFields("filePath", "issueCreationDate", "issueUpdateDate", "issueCloseDate")
+      .ignoringFields("filePath", "issueCreationDate", "issueUpdateDate", "issueCloseDate", "cleanCodeAttribute")
       .isEqualTo(expected);
     assertThat(issue.parseMessageFormattings()).isEqualTo(MESSAGE_FORMATTING);
     assertThat(issue.getIssueCreationDate()).isNotNull();
@@ -150,6 +150,7 @@ public class IssueDaoIT {
     assertThat(issue.getIssueCloseDate()).isNotNull();
     assertThat(issue.getRuleRepo()).isEqualTo(RULE.getRepositoryKey());
     assertThat(issue.getRule()).isEqualTo(RULE.getRuleKey());
+    assertThat(issue.getCleanCodeAttribute()).isEqualTo(RULE.getCleanCodeAttribute());
     assertThat(issue.parseLocations()).isNull();
   }
 
@@ -776,6 +777,7 @@ public class IssueDaoIT {
     dto.setCodeVariants(Set.of("variant1", "variant2"));
     return dto;
   }
+
   private void prepareTables() {
     underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY1)
       .setMessage("the message")
index 498680a187310499a2c71077635b048c8abdec85..d705cfdf883bb709ad0a7f61ebf0133d01bb7a4c 100644 (file)
@@ -37,6 +37,7 @@ import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
+import org.sonar.api.rules.CleanCodeAttribute;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.server.debt.DebtRemediationFunction;
@@ -238,6 +239,7 @@ public class RuleDaoIT {
     assertThat(actual.getRuleDescriptionSectionDtos()).usingRecursiveFieldByFieldElementComparator()
       .containsExactlyInAnyOrderElementsOf(expected.getRuleDescriptionSectionDtos());
     assertThat(actual.getEducationPrinciples()).isEqualTo(expected.getEducationPrinciples());
+    assertThat(actual.getCleanCodeAttribute()).isEqualTo(expected.getCleanCodeAttribute());
   }
 
   @Test
@@ -456,6 +458,7 @@ public class RuleDaoIT {
       .setSystemTags(newHashSet("systag1", "systag2"))
       .setSecurityStandards(newHashSet("owaspTop10:a1", "cwe:123"))
       .setType(RuleType.BUG)
+      .setCleanCodeAttribute(CleanCodeAttribute.CLEAR)
       .setScope(Scope.ALL)
       .setCreatedAt(1_500_000_000_000L)
       .setUpdatedAt(2_000_000_000_000L);
@@ -488,6 +491,7 @@ public class RuleDaoIT {
     assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN);
     assertThat(ruleDto.getRuleDescriptionSectionDtos()).usingRecursiveFieldByFieldElementComparator()
       .containsOnly(sectionDto);
+    assertThat(ruleDto.getCleanCodeAttribute()).isEqualTo(CleanCodeAttribute.CLEAR);
   }
 
   @Test
@@ -517,6 +521,7 @@ public class RuleDaoIT {
       .setSecurityStandards(newHashSet("owaspTop10:a1", "cwe:123"))
       .setScope(Scope.ALL)
       .setType(RuleType.BUG)
+      .setCleanCodeAttribute(CleanCodeAttribute.TRUSTWORTHY)
       .setUpdatedAt(2_000_000_000_000L);
 
     underTest.update(db.getSession(), ruleToUpdate);
index 06334fd6de6b0ad14b3d33f9d61b8dd9d338bc1a..0cd237eaedb32242480663476fb9d1c5b49d09bf 100644 (file)
@@ -34,6 +34,7 @@ import javax.annotation.Nullable;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.CleanCodeAttribute;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.issue.DefaultIssue;
@@ -53,6 +54,7 @@ public final class IssueDto implements Serializable {
   private static final Splitter STRING_LIST_SPLITTER = Splitter.on(STRING_LIST_SEPARATOR).trimResults().omitEmptyStrings();
 
   private int type;
+  private CleanCodeAttribute cleanCodeAttribute;
   private String kee;
   private String componentUuid;
   private String projectUuid;
@@ -492,6 +494,7 @@ public final class IssueDto implements Serializable {
     this.ruleRepo = rule.getRepositoryKey();
     this.language = rule.getLanguage();
     this.isExternal = rule.isExternal();
+    this.cleanCodeAttribute = rule.getCleanCodeAttribute();
     return this;
   }
 
@@ -744,6 +747,15 @@ public final class IssueDto implements Serializable {
     return this;
   }
 
+  public CleanCodeAttribute getCleanCodeAttribute() {
+    return cleanCodeAttribute;
+  }
+
+  public IssueDto setCleanCodeAttribute(CleanCodeAttribute cleanCodeAttribute) {
+    this.cleanCodeAttribute = cleanCodeAttribute;
+    return this;
+  }
+
   public Optional<String> getClosedChangeData() {
     return Optional.ofNullable(closedChangeData);
   }
index d88245d7486615b9d81ada79d7e898d55af77bb7..ba3d01d4aa7146095dbe6bc5d5d779e36dd3a22f 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rules.CleanCodeAttribute;
 import org.sonar.api.rules.RuleType;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -98,6 +99,7 @@ public class RuleDto {
   private String systemTagsField = null;
   private String securityStandardsField = null;
   private int type = 0;
+  private CleanCodeAttribute cleanCodeAttribute = null;
   private Scope scope = null;
 
   private RuleKey key = null;
@@ -241,7 +243,7 @@ public class RuleDto {
     return deserializeStringSet(educationPrinciplesField);
   }
 
-  public RuleDto setEducationPrinciples(Set<String> educationPrinciples){
+  public RuleDto setEducationPrinciples(Set<String> educationPrinciples) {
     this.educationPrinciplesField = serializeStringSet(educationPrinciples);
     return this;
   }
@@ -395,6 +397,15 @@ public class RuleDto {
     return this;
   }
 
+  public CleanCodeAttribute getCleanCodeAttribute() {
+    return cleanCodeAttribute;
+  }
+
+  public RuleDto setCleanCodeAttribute(CleanCodeAttribute cleanCodeAttribute) {
+    this.cleanCodeAttribute = cleanCodeAttribute;
+    return this;
+  }
+
   public long getCreatedAt() {
     return createdAt;
   }
index c24e040a0a0427df5922ad2099aeadc036d3e2c3..0a6bb0f7a4151c6210a6ac32e5a98195ac8119ad 100644 (file)
@@ -32,6 +32,7 @@
     r.plugin_name as ruleRepo,
     r.language as language,
     r.security_standards as securityStandards,
+    r.clean_code_attribute as cleanCodeAttribute,
     p.kee as componentKey,
     i.component_uuid as componentUuid,
     p.path as filePath,
     r.rule_type as ruleType,
     r.plugin_name as ruleRepo,
     r.plugin_rule_key as ruleKey,
+    r.clean_code_attribute as cleanCodeAttribute,
     i.message as message,
     i.message_formattings as messageFormattings,
     i.severity as severity,
index fcd120cd8b5269384c7d28947c4fc6380a6cdbbe..953157fac2974cbb7a1ad73a3ad89dbdc666aaec 100644 (file)
@@ -39,7 +39,8 @@
     r.ad_hoc_description as "adHocDescription",
     r.ad_hoc_severity as "adHocSeverity",
     r.ad_hoc_type as "adHocType",
-    r.education_principles as "educationPrinciplesField"
+    r.education_principles as "educationPrinciplesField",
+    r.clean_code_attribute as "cleanCodeAttribute"
   </sql>
 
   <sql id="leftOuterJoinRulesDescriptionSections">
       ad_hoc_severity,
       ad_hoc_type,
       education_principles,
+      clean_code_attribute,
       created_at,
       updated_at
     )
       #{adHocSeverity,jdbcType=VARCHAR},
       #{adHocType,jdbcType=TINYINT},
       #{educationPrinciplesField,jdbcType=VARCHAR},
+      #{cleanCodeAttribute,jdbcType=VARCHAR},
       #{createdAt,jdbcType=BIGINT},
       #{updatedAt,jdbcType=BIGINT}
     )
       ad_hoc_severity=#{adHocSeverity,jdbcType=VARCHAR},
       ad_hoc_type=#{adHocType,jdbcType=TINYINT},
       education_principles=#{educationPrinciplesField,jdbcType=VARCHAR},
+      clean_code_attribute=#{cleanCodeAttribute,jdbcType=VARCHAR},
       updated_at=#{updatedAt,jdbcType=BIGINT}
     where
       uuid=#{uuid,jdbcType=VARCHAR}
index 9949cb0188aaf861419be075a59dd18b577d79f5..766d78fcf50b863917b8e041a404883d9019e560 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.commons.lang.time.DateUtils;
 import org.junit.Test;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.CleanCodeAttribute;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.issue.DefaultIssue;
@@ -117,13 +118,14 @@ public class IssueDtoTest {
   public void set_rule() {
     IssueDto dto = new IssueDto()
       .setKee("100")
-      .setRule(new RuleDto().setUuid("uuid-1").setRuleKey("AvoidCycle").setRepositoryKey("java").setIsExternal(true))
+      .setRule(new RuleDto().setUuid("uuid-1").setRuleKey("AvoidCycle").setRepositoryKey("java").setIsExternal(true).setCleanCodeAttribute(CleanCodeAttribute.CLEAR))
       .setLanguage("xoo");
 
     assertThat(dto.getRuleUuid()).isEqualTo("uuid-1");
     assertThat(dto.getRuleRepo()).isEqualTo("java");
     assertThat(dto.getRule()).isEqualTo("AvoidCycle");
     assertThat(dto.getRuleKey()).hasToString("java:AvoidCycle");
+    assertThat(dto.getCleanCodeAttribute()).isEqualTo(CleanCodeAttribute.CLEAR);
     assertThat(dto.getLanguage()).isEqualTo("xoo");
     assertThat(dto.isExternal()).isTrue();
   }
index 6d5cc8f4cfd9909f983cbeb7d9ef2fc80b3ea67b..7fbae9e48d548f7e6401b6e76885257f912b6701 100644 (file)
@@ -26,6 +26,7 @@ import javax.annotation.Nullable;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
+import org.sonar.api.rules.CleanCodeAttribute;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.core.util.UuidFactory;
@@ -92,6 +93,7 @@ public class RuleTesting {
       .setName("name_" + randomAlphanumeric(5))
       .setDescriptionFormat(RuleDto.Format.HTML)
       .setType(CODE_SMELL)
+      .setCleanCodeAttribute(CleanCodeAttribute.CLEAR)
       .setStatus(RuleStatus.READY)
       .setConfigKey("configKey_" + ruleKey.rule())
       .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size())))