]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13591 Fix copy of issue tags from rule tags
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 7 Jul 2020 08:09:34 +0000 (10:09 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Jul 2020 20:05:35 +0000 (20:05 +0000)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java

index ebac3901e197ed9c9e5a1ec27ea9337a989dcc0d..6d91f1d758c1425f0f8895033ecd4617e583b712 100644 (file)
@@ -97,7 +97,8 @@ public class XooRulesDefinition implements RulesDefinition {
     ruleWithParameters.createParam("float").setType(RuleParamType.FLOAT);
 
     NewRule oneIssuePerLine = repo.createRule(OneIssuePerLineSensor.RULE_KEY).setName("One Issue Per Line")
-      .setHtmlDescription("Generate an issue on each line of a file. It requires the metric \"lines\".");
+      .setHtmlDescription("Generate an issue on each line of a file. It requires the metric \"lines\".")
+      .setTags("line");
     oneIssuePerLine
       .setDebtRemediationFunction(oneIssuePerLine.debtRemediationFunctions().linear("1min"))
       .setGapDescription("It takes about 1 minute to an experienced software craftsman to remove a line of code");
index 602981259fc24317a789ea27835b96e5248575d6..6b5a9fa6e1bf6831d5e468067e4d110d9f572304 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.util.cache;
 
-import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableSet;
 import java.io.BufferedOutputStream;
@@ -116,7 +115,7 @@ public class ProtobufIssueDiskCache implements DiskCache<DefaultIssue> {
     defaultIssue.setAttributes(next.getAttributesMap());
     defaultIssue.setAuthorLogin(next.hasAuthorLogin() ? next.getAuthorLogin() : null);
     next.getCommentsList().forEach(c -> defaultIssue.addComment(toDefaultIssueComment(c)));
-    defaultIssue.setTags(ImmutableSet.copyOf(TAGS_SPLITTER.split(next.hasTags() ? "" : next.getTags())));
+    defaultIssue.setTags(ImmutableSet.copyOf(TAGS_SPLITTER.split(next.getTags())));
     defaultIssue.setLocations(next.hasLocations() ? next.getLocations() : null);
     defaultIssue.setIsFromExternalRuleEngine(next.getIsFromExternalRuleEngine());
     defaultIssue.setCreationDate(new Date(next.getCreationDate()));
index bcea933ce76c496861aa0f5540fe7571d3954a9c..7779b704c23164807365034a528917545e51e3e8 100644 (file)
@@ -132,6 +132,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .setProjectKey(project.getKey())
       .setSeverity(BLOCKER)
       .setStatus(STATUS_OPEN)
+      .setTags(singletonList("test"))
       .setNew(false)
       .setCopied(true)
       .setType(RuleType.BUG)
@@ -164,6 +165,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
     assertThat(result.getSeverity()).isEqualTo(BLOCKER);
     assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
     assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+    assertThat(result.getTags()).containsExactlyInAnyOrder("test");
 
     List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"));
     assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE);
@@ -171,6 +173,50 @@ public class PersistIssuesStepTest extends BaseStepTest {
       entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
   }
 
+  @Test
+  public void insert_copied_issue_with_minimal_info() {
+    RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
+    db.rules().insert(rule);
+    OrganizationDto organizationDto = db.organizations().insert();
+    ComponentDto project = db.components().insertPrivateProject(organizationDto);
+    ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+    when(system2.now()).thenReturn(NOW);
+
+    protoIssueCache.newAppender().append(new DefaultIssue()
+      .setKey("ISSUE")
+      .setType(RuleType.CODE_SMELL)
+      .setRuleKey(rule.getKey())
+      .setComponentUuid(file.uuid())
+      .setComponentKey(file.getKey())
+      .setProjectUuid(project.uuid())
+      .setProjectKey(project.getKey())
+      .setSeverity(BLOCKER)
+      .setStatus(STATUS_OPEN)
+      .setNew(false)
+      .setCopied(true)
+      .setType(RuleType.BUG)
+      .setCreationDate(new Date(NOW))
+      .setSelectedAt(NOW))
+      .close();
+
+    TestComputationStepContext context = new TestComputationStepContext();
+    underTest.execute(context);
+
+    IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE");
+    assertThat(result.getKey()).isEqualTo("ISSUE");
+    assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
+    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
+    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
+    assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+    assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
+    assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+    assertThat(result.getTags()).isEmpty();
+
+    assertThat(dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"))).isEmpty();
+    assertThat(context.getStatistics().getAll()).contains(
+      entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
+  }
+
   @Test
   public void insert_merged_issue() {
     RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));