aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Giffon <eric.giffon@sonarsource.com>2023-05-08 17:01:38 +0200
committersonartech <sonartech@sonarsource.com>2023-05-16 20:02:49 +0000
commit0f6906caea05555b37525e165b363d45521ed7f6 (patch)
tree2bddc60e63e202d5997fbfec631ea205b44e33fd
parent317e473e154d014b6c3d258fddbc82ffe8b7093a (diff)
downloadsonarqube-0f6906caea05555b37525e165b363d45521ed7f6.tar.gz
sonarqube-0f6906caea05555b37525e165b363d45521ed7f6.zip
SONAR-19197 Add field for code variants to scanner-engine
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java4
-rw-r--r--sonar-scanner-protocol/src/main/protobuf/scanner_report.proto1
3 files changed, 8 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
index 0e0cd3205b0..5e3b7a6d254 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
@@ -131,6 +131,10 @@ public class IssuePublisher {
applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
builder.setQuickFixAvailable(issue.isQuickFixAvailable());
issue.ruleDescriptionContextKey().ifPresent(builder::setRuleDescriptionContextKey);
+ List<String> codeVariants = issue.codeVariants();
+ if (codeVariants != null) {
+ builder.addAllCodeVariants(codeVariants);
+ }
return builder.build();
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java
index 9bc0da72b25..faaea60e599 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java
@@ -127,7 +127,8 @@ public class IssuePublisherTest {
.forRule(JAVA_RULE_KEY)
.overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL)
.setQuickFixAvailable(true)
- .setRuleDescriptionContextKey(ruleDescriptionContextKey);
+ .setRuleDescriptionContextKey(ruleDescriptionContextKey)
+ .setCodeVariants(List.of("variant1", "variant2"));
when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);
@@ -139,6 +140,7 @@ public class IssuePublisherTest {
assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
assertThat(argument.getValue().getQuickFixAvailable()).isTrue();
assertThat(argument.getValue().getRuleDescriptionContextKey()).isEqualTo(ruleDescriptionContextKey);
+ assertThat(argument.getValue().getCodeVariantsList()).containsExactly("variant1", "variant2");
}
@Test
diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
index 62973c2e01e..335df02507f 100644
--- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
+++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
@@ -200,6 +200,7 @@ message Issue {
bool quickFixAvailable = 8;
optional string ruleDescriptionContextKey = 9;
repeated MessageFormatting msgFormatting = 10;
+ repeated string codeVariants = 11;
}
message ExternalIssue {