diff options
author | Eric Giffon <eric.giffon@sonarsource.com> | 2023-05-03 12:33:31 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-05-16 20:02:49 +0000 |
commit | 317e473e154d014b6c3d258fddbc82ffe8b7093a (patch) | |
tree | 1f61a36abcbc7c65a2cdea8d2cf2e0805cfbab01 /sonar-core | |
parent | 073183e7f180ad6d4dbf90d9a73164516cb9668a (diff) | |
download | sonarqube-317e473e154d014b6c3d258fddbc82ffe8b7093a.tar.gz sonarqube-317e473e154d014b6c3d258fddbc82ffe8b7093a.zip |
SONAR-19197 Add code_variants to issues table
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java | 17 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java | 8 |
2 files changed, 22 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index f310c527e39..b66bfe94f31 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -77,6 +77,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String authorLogin = null; private List<DefaultIssueComment> comments = null; private Set<String> tags = null; + private Set<String> codeVariants = null; // temporarily an Object as long as DefaultIssue is used by sonar-batch private Object locations = null; @@ -653,7 +654,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. @Override public Set<String> tags() { if (tags == null) { - return ImmutableSet.of(); + return Set.of(); } else { return ImmutableSet.copyOf(tags); } @@ -664,6 +665,20 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + @Override + public Set<String> codeVariants() { + if (codeVariants == null) { + return Set.of(); + } else { + return ImmutableSet.copyOf(codeVariants); + } + } + + public DefaultIssue setCodeVariants(Collection<String> codeVariants) { + this.codeVariants = new LinkedHashSet<>(codeVariants); + return this; + } + public Optional<String> getRuleDescriptionContextKey() { return Optional.ofNullable(ruleDescriptionContextKey); } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java index 3fdc6daa25e..e51e8b13e3d 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java @@ -21,6 +21,7 @@ package org.sonar.core.issue; import java.text.SimpleDateFormat; import java.util.List; +import java.util.Set; import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.sonar.api.issue.Issue; @@ -29,7 +30,6 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -73,7 +73,9 @@ public class DefaultIssueTest { .setCloseDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-21")) .setSelectedAt(1400000000000L) .setRuleDescriptionContextKey(TEST_CONTEXT_KEY) - .setType(RuleType.BUG); + .setType(RuleType.BUG) + .setTags(Set.of("tag1", "tag2")) + .setCodeVariants(Set.of("variant1", "variant2")); assertThat((Object) issue.getLocations()).isEqualTo("loc"); assertThat(issue.locationsChanged()).isTrue(); @@ -109,6 +111,8 @@ public class DefaultIssueTest { assertThat(issue.selectedAt()).isEqualTo(1400000000000L); assertThat(issue.getRuleDescriptionContextKey()).contains(TEST_CONTEXT_KEY); assertThat(issue.type()).isEqualTo(RuleType.BUG); + assertThat(issue.tags()).containsOnly("tag1", "tag2"); + assertThat(issue.codeVariants()).containsOnly("variant1", "variant2"); } @Test |