import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.sonar.api.utils.Preconditions.checkState;
public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements Issue, NewIssue {
+ private final Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> overridenImpacts = new EnumMap<>(SoftwareQuality.class);
private RuleKey ruleKey;
private Double gap;
private Severity overriddenSeverity;
@Override
public DefaultIssue overrideImpact(SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) {
- return null;
+ overridenImpacts.put(softwareQuality, severity);
+ return this;
}
@Override
@Override
public Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> overridenImpacts() {
- return Collections.emptyMap();
+ return overridenImpacts;
}
@Override
import org.sonar.api.batch.sensor.issue.MessageFormatting;
import org.sonar.api.batch.sensor.issue.NewIssue.FlowType;
import org.sonar.api.batch.sensor.issue.fix.NewQuickFix;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(issue.isQuickFixAvailable()).isTrue();
}
+ @Test
+ public void issue_can_override_impacts() {
+ DefaultIssue issue = new DefaultIssue(project, storage).overrideImpact(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);
+
+ assertThat(issue.overridenImpacts()).containsEntry(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);
+ }
+
@Test
public void quickfix_only_sets_flag_to_true() {
DefaultIssue issue = new DefaultIssue(project);
*/
package org.sonar.scanner.issue;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
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.api.issue.impact.SoftwareQuality;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation;
builder.setRuleKey(issue.ruleKey().rule());
builder.setMsg(primaryMessage);
builder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings()));
+ builder.addAllOverridenImpacts(toProtobufImpacts(issue.overridenImpacts()));
locationBuilder.setMsg(primaryMessage);
locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings()));
return builder.build();
}
+ 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()));
+ return impacts;
+ }
+
private static List<ScannerReport.MessageFormatting> toProtobufMessageFormattings(List<MessageFormatting> messageFormattings) {
return messageFormattings.stream()
.map(m -> ScannerReport.MessageFormatting.newBuilder()
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation;
import org.sonar.api.batch.sensor.issue.internal.DefaultMessageFormatting;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.api.batch.sensor.issue.MessageFormatting.Type.CODE;
+import static org.sonar.api.issue.impact.SoftwareQuality.*;
@RunWith(MockitoJUnitRunner.class)
public class IssuePublisherTest {
- static final RuleKey JAVA_RULE_KEY = RuleKey.of("java", "AvoidCycle");
+ private static final RuleKey JAVA_RULE_KEY = RuleKey.of("java", "AvoidCycle");
private static final RuleKey NOSONAR_RULE_KEY = RuleKey.of("java", "NoSonarCheck");
private DefaultInputProject project;
.overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL)
.setQuickFixAvailable(true)
.setRuleDescriptionContextKey(ruleDescriptionContextKey)
- .setCodeVariants(List.of("variant1", "variant2"));
+ .setCodeVariants(List.of("variant1", "variant2"))
+ .overrideImpact(MAINTAINABILITY, org.sonar.api.issue.impact.Severity.HIGH)
+ .overrideImpact(RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);
when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);
assertThat(argument.getValue().getQuickFixAvailable()).isTrue();
assertThat(argument.getValue().getRuleDescriptionContextKey()).isEqualTo(ruleDescriptionContextKey);
assertThat(argument.getValue().getCodeVariantsList()).containsExactly("variant1", "variant2");
+
+ ScannerReport.Impact impact1 = ScannerReport.Impact.newBuilder().setSoftwareQuality(MAINTAINABILITY.name()).setSeverity("HIGH").build();
+ ScannerReport.Impact impact2 = ScannerReport.Impact.newBuilder().setSoftwareQuality(RELIABILITY.name()).setSeverity("LOW").build();
+ assertThat(argument.getValue().getOverridenImpactsList()).containsExactly(impact1, impact2);
}
@Test
optional string ruleDescriptionContextKey = 9;
repeated MessageFormatting msgFormatting = 10;
repeated string codeVariants = 11;
+ repeated Impact overridenImpacts = 12;
}
message ExternalIssue {
repeated Flow flow = 7;
IssueType type = 8;
repeated MessageFormatting msgFormatting = 9;
+ repeated Impact overridenImpacts = 10;
}
message AdHocRule {
string text = 1;
int64 timestamp = 2;
}
+
+message Impact {
+ string software_quality = 1;
+ string severity = 2;
+}
\ No newline at end of file