aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/issue')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ImpactMapper.java38
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java22
4 files changed, 55 insertions, 15 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
index ddb665c7965..d070a464cb4 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
@@ -34,12 +34,14 @@ import org.sonar.scanner.protocol.output.ScannerReport.Issue;
@ThreadSafe
public class DefaultFilterableIssue implements FilterableIssue {
private final Issue rawIssue;
+ private final String severity;
private final InputComponent component;
private DefaultInputProject project;
- public DefaultFilterableIssue(DefaultInputProject project, Issue rawIssue, InputComponent component) {
+ public DefaultFilterableIssue(DefaultInputProject project, Issue rawIssue, String severity, InputComponent component) {
this.project = project;
this.rawIssue = rawIssue;
+ this.severity = severity;
this.component = component;
}
@@ -55,7 +57,7 @@ public class DefaultFilterableIssue implements FilterableIssue {
@Override
public String severity() {
- return rawIssue.getSeverity().name();
+ return severity;
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ImpactMapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ImpactMapper.java
new file mode 100644
index 00000000000..76111b56055
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ImpactMapper.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.issue;
+
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.scanner.protocol.output.ScannerReport;
+
+public class ImpactMapper {
+ private ImpactMapper() {
+ }
+
+ public static ScannerReport.ImpactSeverity mapImpactSeverity(Severity severity) {
+ return switch (severity) {
+ case BLOCKER -> ScannerReport.ImpactSeverity.ImpactSeverity_BLOCKER;
+ case HIGH -> ScannerReport.ImpactSeverity.ImpactSeverity_HIGH;
+ case MEDIUM -> ScannerReport.ImpactSeverity.ImpactSeverity_MEDIUM;
+ case LOW -> ScannerReport.ImpactSeverity.ImpactSeverity_LOW;
+ case INFO -> ScannerReport.ImpactSeverity.ImpactSeverity_INFO;
+ };
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java
index cce20df21d8..948e9552370 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java
@@ -41,11 +41,11 @@ public class IssueFilters {
this.project = project;
}
- public boolean accept(InputComponent component, ScannerReport.Issue rawIssue) {
+ public boolean accept(InputComponent component, ScannerReport.Issue rawIssue, String severity) {
if (filterChain == null) {
throw new IllegalStateException("Issue filters must be registered before this class can be used");
}
- FilterableIssue fIssue = new DefaultFilterableIssue(project, rawIssue, component);
+ FilterableIssue fIssue = new DefaultFilterableIssue(project, rawIssue, severity, component);
return filterChain.accept(fIssue);
}
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 6de30db7829..da79ae46bd0 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
@@ -33,7 +33,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.DefaultActiveRule;
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;
@@ -78,9 +77,9 @@ public class IssuePublisher {
return false;
}
- ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity(), ((DefaultActiveRule) activeRule).impacts());
+ ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId());
- if (filters.accept(inputComponent, rawIssue)) {
+ if (filters.accept(inputComponent, rawIssue, activeRule.severity())) {
write(inputComponent.scannerId(), rawIssue);
return true;
}
@@ -108,29 +107,28 @@ public class IssuePublisher {
return str;
}
- private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef, String activeRuleSeverity,
- Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> activeRuleImpacts) {
+ private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef) {
String primaryMessage = nullToEmpty(issue.primaryLocation().message());
- org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
- Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRuleSeverity);
ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
// non-null fields
- builder.setSeverity(severity);
builder.setRuleRepository(issue.ruleKey().repository());
builder.setRuleKey(issue.ruleKey().rule());
builder.setMsg(primaryMessage);
builder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings()));
Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> overriddenImpacts = new EnumMap<>(issue.overridenImpacts());
- activeRuleImpacts.entrySet().forEach(e -> overriddenImpacts.putIfAbsent(e.getKey(), e.getValue()));
- builder.addAllOverridenImpacts(toProtobufImpacts(overriddenImpacts));
+ builder.addAllOverriddenImpacts(toProtobufImpacts(overriddenImpacts));
locationBuilder.setMsg(primaryMessage);
locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings()));
locationBuilder.setComponentRef(componentRef);
+ org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
+ if (overriddenSeverity != null) {
+ builder.setOverriddenSeverity(Severity.valueOf(overriddenSeverity.name()));
+ }
TextRange primaryTextRange = issue.primaryLocation().textRange();
if (primaryTextRange != null) {
builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
@@ -151,7 +149,9 @@ public class IssuePublisher {
private static List<ScannerReport.Impact> toProtobufImpacts(Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> softwareQualitySeverityMap) {
List<ScannerReport.Impact> impacts = new ArrayList<>();
- softwareQualitySeverityMap.forEach((q, s) -> impacts.add(ScannerReport.Impact.newBuilder().setSoftwareQuality(q.name()).setSeverity(s.name()).build()));
+ softwareQualitySeverityMap.forEach((q, s) -> impacts.add(ScannerReport.Impact.newBuilder()
+ .setSoftwareQuality(ScannerReport.SoftwareQuality.valueOf(q.name()))
+ .setSeverity(ImpactMapper.mapImpactSeverity(s)).build()));
return impacts;
}