diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2022-02-25 14:40:37 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-25 20:02:54 +0000 |
commit | 97ad45993a48f860cf5957a204bca1fdbe4d7ee4 (patch) | |
tree | c0a36ee73983b05783a5626e565f535f5449e2dd /server | |
parent | c7ddcb150f644d0f3b7f6716f0f11276fa58e7d1 (diff) | |
download | sonarqube-97ad45993a48f860cf5957a204bca1fdbe4d7ee4.tar.gz sonarqube-97ad45993a48f860cf5957a204bca1fdbe4d7ee4.zip |
SONAR-13588 External issue tags should inherit external rule tags
Diffstat (limited to 'server')
2 files changed, 15 insertions, 4 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopier.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopier.java index f48110bb5ae..ad98507da26 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopier.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopier.java @@ -37,9 +37,7 @@ public class RuleTagsCopier extends IssueVisitor { if (issue.isNew()) { // analyzer can provide some tags. They must be merged with rule tags Rule rule = ruleRepository.getByKey(issue.ruleKey()); - if (!rule.isExternal()) { - issue.setTags(union(issue.tags(), rule.getTags())); - } + issue.setTags(union(issue.tags(), rule.getTags())); } } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopierTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopierTest.java index 51a5773d3a6..f6465fdea37 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopierTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleTagsCopierTest.java @@ -29,15 +29,18 @@ import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.sonar.db.rule.RuleTesting.XOO_X1; +import static org.sonar.db.rule.RuleTesting.XOO_X2; public class RuleTagsCopierTest { DumbRule rule = new DumbRule(XOO_X1); + DumbRule externalRule = new DumbRule(XOO_X2).setIsExternal(true); @org.junit.Rule - public RuleRepositoryRule ruleRepository = new RuleRepositoryRule().add(rule); + public RuleRepositoryRule ruleRepository = new RuleRepositoryRule().add(rule).add(externalRule); DefaultIssue issue = new DefaultIssue().setRuleKey(rule.getKey()); + DefaultIssue externalIssue = new DefaultIssue().setRuleKey(externalRule.getKey()); RuleTagsCopier underTest = new RuleTagsCopier(ruleRepository); @Test @@ -51,6 +54,16 @@ public class RuleTagsCopierTest { } @Test + public void copy_tags_if_new_external_issue() { + externalRule.setTags(Sets.newHashSet("es_lint", "java")); + externalIssue.setNew(true); + + underTest.onIssue(mock(Component.class), externalIssue); + + assertThat(externalIssue.tags()).containsExactly("es_lint", "java"); + } + + @Test public void do_not_copy_tags_if_existing_issue() { rule.setTags(Sets.newHashSet("bug", "performance")); issue.setNew(false).setTags(asList("misra")); |