]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19197 Add field for code variants to scanner-engine
authorEric Giffon <eric.giffon@sonarsource.com>
Mon, 8 May 2023 15:01:38 +0000 (17:01 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 16 May 2023 20:02:49 +0000 (20:02 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java
sonar-scanner-protocol/src/main/protobuf/scanner_report.proto

index 0e0cd3205b052fff54c5934b6b1826c1c21565e7..5e3b7a6d254ad83819427048a8315f56fec351ac 100644 (file)
@@ -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();
   }
 
index 9bc0da72b25c1d3a210fd761ea32bb7e71b2ba03..faaea60e5995ccd5fd8a028de77012dae9c8cc77 100644 (file)
@@ -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
index 62973c2e01e0500923ca95169f8b43ebc6fc69d1..335df02507f6d956e58eceb0f6ae5583ae6f32f6 100644 (file)
@@ -200,6 +200,7 @@ message Issue {
   bool quickFixAvailable = 8;
   optional string ruleDescriptionContextKey = 9;
   repeated MessageFormatting msgFormatting = 10;
+  repeated string codeVariants = 11;
 }
 
 message ExternalIssue {