diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2022-11-23 15:57:02 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-12-01 20:03:11 +0000 |
commit | 66b8bff0dcc778eb93da92cd408214bbfca82c2a (patch) | |
tree | e60388bdf0bdbc60434d00eae81b8e6dffe39fad /sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java | |
parent | 24d4519ea1b8a4426dd90e0bb80b2b09bd7a1c12 (diff) | |
download | sonarqube-66b8bff0dcc778eb93da92cd408214bbfca82c2a.tar.gz sonarqube-66b8bff0dcc778eb93da92cd408214bbfca82c2a.zip |
SONAR-17592 Persist Message formatting from plugin api
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java | 19 |
1 files changed, 18 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 8688c6a3ebe..d3a26a55d95 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 @@ -20,7 +20,9 @@ package org.sonar.scanner.issue; import java.util.Collection; +import java.util.List; import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.annotation.concurrent.ThreadSafe; import org.apache.commons.lang.StringUtils; @@ -32,6 +34,7 @@ import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.issue.Issue.Flow; +import org.sonar.api.batch.sensor.issue.MessageFormatting; import org.sonar.api.batch.sensor.issue.NewIssue.FlowType; import org.sonar.api.batch.sensor.issue.internal.DefaultIssueFlow; import org.sonar.scanner.protocol.Constants.Severity; @@ -112,7 +115,9 @@ public class IssuePublisher { builder.setRuleRepository(issue.ruleKey().repository()); builder.setRuleKey(issue.ruleKey().rule()); builder.setMsg(primaryMessage); + builder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); locationBuilder.setMsg(primaryMessage); + locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); locationBuilder.setComponentRef(componentRef); TextRange primaryTextRange = issue.primaryLocation().textRange(); @@ -129,6 +134,16 @@ public class IssuePublisher { return builder.build(); } + private static List<ScannerReport.MessageFormatting> toProtobufMessageFormattings(List<MessageFormatting> messageFormattings) { + return messageFormattings.stream() + .map(m -> ScannerReport.MessageFormatting.newBuilder() + .setStart(m.start()) + .setEnd(m.end()) + .setType(ScannerReport.MessageFormattingType.valueOf(m.type().name())) + .build()) + .collect(Collectors.toList()); + } + private static ScannerReport.ExternalIssue createReportExternalIssue(ExternalIssue issue, int componentRef) { // primary location of an external issue must have a message String primaryMessage = issue.primaryLocation().message(); @@ -144,8 +159,9 @@ public class IssuePublisher { builder.setEngineId(issue.engineId()); builder.setRuleId(issue.ruleId()); builder.setMsg(primaryMessage); + builder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); locationBuilder.setMsg(primaryMessage); - + locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); locationBuilder.setComponentRef(componentRef); TextRange primaryTextRange = issue.primaryLocation().textRange(); if (primaryTextRange != null) { @@ -175,6 +191,7 @@ public class IssuePublisher { String message = location.message(); if (message != null) { locationBuilder.setMsg(message); + locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(location.messageFormattings())); } TextRange textRange = location.textRange(); if (textRange != null) { |