diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-23 20:55:46 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-23 20:56:27 +0200 |
commit | e4fdef49e36d269ef5365a3056af67c8c3d5aceb (patch) | |
tree | dcec45821e3d24e946eb13c1f80f8bebcf17804f /sonar-plugin-api | |
parent | 0a123014a0781a516b580d4fa9ce76532f23071f (diff) | |
download | sonarqube-e4fdef49e36d269ef5365a3056af67c8c3d5aceb.tar.gz sonarqube-e4fdef49e36d269ef5365a3056af67c8c3d5aceb.zip |
SONAR-5417 Add rule name to active rule
Diffstat (limited to 'sonar-plugin-api')
4 files changed, 23 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java index 3e3d18651e9..d24fa2eed84 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java @@ -22,6 +22,7 @@ package org.sonar.api.batch.rule; import org.sonar.api.rule.RuleKey; import javax.annotation.CheckForNull; + import java.util.Map; /** @@ -33,6 +34,12 @@ public interface ActiveRule { RuleKey ruleKey(); /** + * Name of the rule. + * @since 4.5 + */ + String name(); + + /** * Non-null severity. * @see org.sonar.api.rule.Severity */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java index 5eeea77687d..b37fc6a8890 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java @@ -24,16 +24,19 @@ import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.rule.RuleKey; import javax.annotation.concurrent.Immutable; + import java.util.Map; @Immutable class DefaultActiveRule implements ActiveRule { private final RuleKey ruleKey; + private final String name; private final String severity, internalKey, language; private final Map<String, String> params; DefaultActiveRule(NewActiveRule newActiveRule) { this.severity = newActiveRule.severity; + this.name = newActiveRule.name; this.internalKey = newActiveRule.internalKey; this.ruleKey = newActiveRule.ruleKey; this.params = ImmutableMap.copyOf(newActiveRule.params); @@ -46,6 +49,11 @@ class DefaultActiveRule implements ActiveRule { } @Override + public String name() { + return name; + } + + @Override public String severity() { return severity; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java index dd4b53d5953..3f20d89bf3f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java @@ -33,6 +33,7 @@ import java.util.Map; */ public class NewActiveRule { final RuleKey ruleKey; + String name; String severity = Severity.defaultSeverity(); Map<String, String> params = new HashMap<String, String>(); String internalKey, language; @@ -43,6 +44,11 @@ public class NewActiveRule { this.ruleKey = ruleKey; } + public NewActiveRule setName(String name) { + this.name = name; + return this; + } + public NewActiveRule setSeverity(@Nullable String severity) { this.severity = StringUtils.defaultIfBlank(severity, Severity.defaultSeverity()); return this; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java index 584b1ea7663..3d2ac27b8a1 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java @@ -40,6 +40,7 @@ public class ActiveRulesBuilderTest { public void build_rules() throws Exception { ActiveRules activeRules = new ActiveRulesBuilder() .create(RuleKey.of("squid", "S0001")) + .setName("My Rule") .setSeverity(Severity.CRITICAL) .setInternalKey("__S0001__") .setParam("min", "20") @@ -58,6 +59,7 @@ public class ActiveRulesBuilderTest { ActiveRule squid1 = activeRules.find(RuleKey.of("squid", "S0001")); assertThat(squid1.ruleKey().repository()).isEqualTo("squid"); assertThat(squid1.ruleKey().rule()).isEqualTo("S0001"); + assertThat(squid1.name()).isEqualTo("My Rule"); assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL); assertThat(squid1.internalKey()).isEqualTo("__S0001__"); assertThat(squid1.params()).hasSize(1); |