From: Julien Lancelot Date: Tue, 7 Jul 2020 08:09:34 +0000 (+0200) Subject: SONAR-13591 Fix copy of issue tags from rule tags X-Git-Tag: 8.5.0.37579~200 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=191fde8d2cfc1a69b4e981b67e4e0bdbb33bba7c;p=sonarqube.git SONAR-13591 Fix copy of issue tags from rule tags --- diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index ebac3901e19..6d91f1d758c 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -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"); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java index 602981259fc..6b5a9fa6e1b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java @@ -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.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())); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java index bcea933ce76..7779b704c23 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java @@ -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 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"));