diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-08 17:46:45 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-08 17:46:45 +0200 |
commit | 32f6d46600091ea351b1657eb6233f8648ec69cc (patch) | |
tree | 048208c44f47f96c4b6597bff484ea1874dcfe4a /sonar-plugin-api/src | |
parent | 2e975e173f3c8f84657b8cce7b00f0f9b78ee05f (diff) | |
download | sonarqube-32f6d46600091ea351b1657eb6233f8648ec69cc.tar.gz sonarqube-32f6d46600091ea351b1657eb6233f8648ec69cc.zip |
SONAR-5195 Rule templates should not define technical debt informations
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java | 3 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index 831a05f1155..ba5870588ca 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -687,6 +687,9 @@ public interface RulesDefinition extends ServerExtension { if ((Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction != null) || (!Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction == null)) { throw new IllegalStateException(String.format("Both debt sub-characteristic and debt remediation function should be defined on rule '%s'", this)); } + if (!Strings.isNullOrEmpty(debtSubCharacteristic) && template) { + throw new IllegalStateException(String.format("'%s' is a rule template, it should not define technical debt.", this)); + } } @Override diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java index 1027e8ba3fc..43a88eaffe0 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java @@ -340,4 +340,26 @@ public class RulesDefinitionTest { } } + /** + * SONAR-5195 + */ + @Test + public void fail_if_rule_template_define_technical_debt() { + RulesDefinition.NewRepository newRepo = context.createRepository("squid", "java"); + RulesDefinition.NewRule newRule = newRepo.createRule("XPath rule") + .setTemplate(true) + .setName("Insufficient branch coverage") + .setHtmlDescription("This rule allows to define some homemade Java rules with help of an XPath expression.") + .setSeverity(Severity.MAJOR) + .setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.UNIT_TESTS); + newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min")); + + try { + newRepo.done(); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("'[repository=squid, key=XPath rule]' is a rule template, it should not define technical debt."); + } + } + } |