aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-09 17:56:32 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-09 17:56:32 +0100
commitbd814b0f9f41fbb27b24e280c95cec341f83a38a (patch)
tree6a733a9a9e842a6970749dec973ea95961f228b1 /sonar-plugin-api/src
parenteb1c4e9fd43cdf253b9eefa75755a7bebd0347c2 (diff)
parenta2fa3e4651b30a3cb9284a34656ed8ecfc13d274 (diff)
downloadsonarqube-bd814b0f9f41fbb27b24e280c95cec341f83a38a.tar.gz
sonarqube-bd814b0f9f41fbb27b24e280c95cec341f83a38a.zip
Merge remote-tracking branch 'origin/branch-5.0'
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java7
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/CheckFactoryTest.java6
5 files changed, 29 insertions, 8 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 35447556df9..06091f37297 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
@@ -63,4 +63,11 @@ public interface ActiveRule {
*/
@CheckForNull
String internalKey();
+
+ /**
+ * Optional rule key of the template rule.
+ * @since 4.5.3
+ */
+ @CheckForNull
+ String templateRuleKey();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java
index ab8ff4fbdec..5cdc2aba2b3 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java
@@ -28,6 +28,7 @@ import org.sonar.api.utils.SonarException;
import org.sonar.check.RuleProperty;
import javax.annotation.CheckForNull;
+
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
@@ -122,10 +123,12 @@ public class Checks<C> {
}
for (ActiveRule activeRule : activeRules.findByRepository(repository)) {
- String engineKey = StringUtils.defaultIfBlank(activeRule.internalKey(), activeRule.ruleKey().rule());
+ String engineKey = StringUtils.defaultIfBlank(activeRule.templateRuleKey(), activeRule.ruleKey().rule());
Object checkClassesOrObject = checksByEngineKey.get(engineKey);
- Object obj = instantiate(activeRule, checkClassesOrObject);
- add(activeRule.ruleKey(), (C) obj);
+ if (checkClassesOrObject != null) {
+ Object obj = instantiate(activeRule, checkClassesOrObject);
+ add(activeRule.ruleKey(), (C) obj);
+ }
}
return this;
}
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 08d34525d69..bfe7b620828 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
@@ -31,13 +31,14 @@ import java.util.Map;
public class DefaultActiveRule implements ActiveRule {
private final RuleKey ruleKey;
private final String name;
- private final String severity, internalKey, language;
+ private final String severity, internalKey, language, templateRuleKey;
private final Map<String, String> params;
DefaultActiveRule(NewActiveRule newActiveRule) {
this.severity = newActiveRule.severity;
this.name = newActiveRule.name;
this.internalKey = newActiveRule.internalKey;
+ this.templateRuleKey = newActiveRule.templateRuleKey;
this.ruleKey = newActiveRule.ruleKey;
this.params = ImmutableMap.copyOf(newActiveRule.params);
this.language = newActiveRule.language;
@@ -77,4 +78,9 @@ public class DefaultActiveRule implements ActiveRule {
public String internalKey() {
return internalKey;
}
+
+ @Override
+ public String templateRuleKey() {
+ return templateRuleKey;
+ }
}
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 3f20d89bf3f..07e85dc9a76 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
@@ -36,7 +36,7 @@ public class NewActiveRule {
String name;
String severity = Severity.defaultSeverity();
Map<String, String> params = new HashMap<String, String>();
- String internalKey, language;
+ String internalKey, language, templateRuleKey;
private final ActiveRulesBuilder builder;
NewActiveRule(ActiveRulesBuilder builder, RuleKey ruleKey) {
@@ -59,6 +59,11 @@ public class NewActiveRule {
return this;
}
+ public NewActiveRule setTemplateRuleKey(@Nullable String templateRuleKey) {
+ this.templateRuleKey = templateRuleKey;
+ return this;
+ }
+
public NewActiveRule setLanguage(@Nullable String language) {
this.language = language;
return this;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/CheckFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/CheckFactoryTest.java
index 2cb3c372f4d..4d5b9a5e7fc 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/CheckFactoryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/CheckFactoryTest.java
@@ -114,9 +114,9 @@ public class CheckFactoryTest {
}
@Test
- public void use_engine_key() {
- RuleKey ruleKey = RuleKey.of("squid", "One");
- builder.create(ruleKey).setInternalKey("S0001").activate();
+ public void use_template_rule_key() {
+ RuleKey ruleKey = RuleKey.of("squid", "S0001_123");
+ builder.create(ruleKey).setTemplateRuleKey("S0001").activate();
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithKey.class);