aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorBenjamin Campomenosi <benjamin.campomenosi@sonarsource.com>2023-04-14 12:11:57 +0200
committersonartech <sonartech@sonarsource.com>2023-04-24 20:04:24 +0000
commit331777b6396ea814563c31974197f2364c64342c (patch)
tree55534a601ba25b951bb02b02b4574e8805c098ab /sonar-plugin-api-impl
parent6730a1380566fba85f5fa859a84eb237d336a757 (diff)
downloadsonarqube-331777b6396ea814563c31974197f2364c64342c.tar.gz
sonarqube-331777b6396ea814563c31974197f2364c64342c.zip
SONAR-19050 update RuleDto to add characteristics
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java17
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java14
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java5
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java10
4 files changed, 26 insertions, 20 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
index 42418950a25..d2e606bee1a 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
@@ -26,8 +26,8 @@ import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.issue.ExternalIssue;
import org.sonar.api.batch.sensor.issue.NewExternalIssue;
-import org.sonar.api.code.CodeCharacteristic;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.rules.RuleType;
import static java.lang.String.format;
@@ -39,6 +39,7 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
private Long effort;
private Severity severity;
private RuleType type;
+ private RuleCharacteristic characteristic;
private String engineId;
private String ruleId;
@@ -100,9 +101,8 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
}
@CheckForNull
- @Override
- public CodeCharacteristic characteristic() {
- throw new IllegalStateException("Not implemented yet");
+ public RuleCharacteristic characteristic() {
+ return characteristic;
}
@Override
@@ -133,14 +133,15 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
}
@Override
- public DefaultExternalIssue type(RuleType type) {
- this.type = type;
+ public DefaultExternalIssue characteristic(RuleCharacteristic characteristic) {
+ this.characteristic = characteristic;
return this;
}
@Override
- public NewExternalIssue characteristic(CodeCharacteristic characteristic) {
- throw new IllegalStateException("Not implemented yet");
+ public DefaultExternalIssue type(RuleType type) {
+ this.type = type;
+ return this;
}
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java
index 52a243b8fca..aefa37f67e7 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java
@@ -26,7 +26,7 @@ import org.sonar.api.batch.sensor.internal.DefaultStorable;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.rule.AdHocRule;
import org.sonar.api.batch.sensor.rule.NewAdHocRule;
-import org.sonar.api.code.CodeCharacteristic;
+import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.rules.RuleType;
import static org.apache.commons.lang.StringUtils.isNotBlank;
@@ -35,6 +35,8 @@ import static org.sonar.api.utils.Preconditions.checkState;
public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewAdHocRule {
private Severity severity;
private RuleType type;
+
+ private RuleCharacteristic characteristic;
private String name;
private String description;
private String engineId;
@@ -97,8 +99,8 @@ public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewA
@CheckForNull
@Override
- public CodeCharacteristic characteristic() {
- throw new IllegalStateException("Not implemented yet");
+ public RuleCharacteristic characteristic() {
+ return characteristic;
}
@Override
@@ -132,8 +134,8 @@ public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewA
}
@Override
- public NewAdHocRule characteristic(CodeCharacteristic characteristic) {
- throw new IllegalStateException("Not implemented yet");
+ public DefaultAdHocRule characteristic(RuleCharacteristic characteristic) {
+ this.characteristic = characteristic;
+ return this;
}
-
}
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java
index 25cb562857d..46a9b8e8e46 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java
@@ -31,6 +31,7 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.rules.RuleType;
import static org.assertj.core.api.Assertions.assertThat;
@@ -69,7 +70,8 @@ public class DefaultExternalIssueTest {
.forRule(RuleKey.of("repo", "rule"))
.remediationEffortMinutes(10L)
.type(RuleType.BUG)
- .severity(Severity.BLOCKER);
+ .severity(Severity.BLOCKER)
+ .characteristic(RuleCharacteristic.SECURE);
assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile);
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_repo", "rule"));
@@ -79,6 +81,7 @@ public class DefaultExternalIssueTest {
assertThat(issue.remediationEffort()).isEqualTo(10L);
assertThat(issue.type()).isEqualTo(RuleType.BUG);
assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
+ assertThat(issue.characteristic()).isEqualTo(RuleCharacteristic.SECURE);
assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!");
issue.save();
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java
index 945b145fedf..6ba0c8dde7b 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.rule.NewAdHocRule;
+import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.rules.RuleType;
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,8 +43,9 @@ public class DefaultAdHocRuleTest {
.name("name")
.description("desc")
.severity(Severity.BLOCKER)
- .type(RuleType.CODE_SMELL);
- rule.save();
+ .type(RuleType.CODE_SMELL)
+ .characteristic(RuleCharacteristic.COMPLIANT);
+ rule.save();
assertThat(rule.engineId()).isEqualTo("engine");
assertThat(rule.ruleId()).isEqualTo("ruleId");
@@ -51,11 +53,10 @@ public class DefaultAdHocRuleTest {
assertThat(rule.description()).isEqualTo("desc");
assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
-
+ assertThat(rule.characteristic()).isEqualTo(RuleCharacteristic.COMPLIANT);
verify(storage).store(any(DefaultAdHocRule.class));
}
-
@Test
public void description_is_optional() {
SensorStorage storage = mock(SensorStorage.class);
@@ -118,7 +119,6 @@ public class DefaultAdHocRuleTest {
.hasMessageContaining("Name is mandatory");
}
-
@Test
public void fail_to_store_if_no_severity() {
SensorStorage storage = mock(SensorStorage.class);