aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-20 18:57:40 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-20 18:57:40 +0100
commitd93268cebc05e32cf5fee908538350d44859962b (patch)
tree93856a6dbcfcf0724a1a7dc3fb61650f1bb9e6aa /sonar-batch
parentdd1478fd1c40ceca4382eda011c3f093ba75dfe5 (diff)
downloadsonarqube-d93268cebc05e32cf5fee908538350d44859962b.tar.gz
sonarqube-d93268cebc05e32cf5fee908538350d44859962b.zip
SONAR-5056 Fix issue when removing characteristic and rules linked with default characteristic linked on it was updated
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java11
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml9
3 files changed, 22 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
index 75afe603f4f..701a5b9f81e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
@@ -81,7 +81,7 @@ public class RulesProvider extends ProviderAdapter {
if (ruleDto.hasCharacteristic()) {
newRule.setDebtCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key());
- newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, newRule, durations));
+ newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations));
}
for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) {
@@ -103,7 +103,7 @@ public class RulesProvider extends ProviderAdapter {
return characteristic;
}
- private DebtRemediationFunction effectiveFunction(RuleDto ruleDto, RuleKey ruleKey, NewRule newRule, Durations durations) {
+ private DebtRemediationFunction effectiveFunction(RuleDto ruleDto, RuleKey ruleKey, Durations durations) {
String function = ruleDto.getRemediationFunction();
String defaultFunction = ruleDto.getDefaultRemediationFunction();
if (function != null) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
index d87e6b3189b..08106710bfe 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
@@ -174,6 +174,17 @@ public class RulesProviderTest extends AbstractDaoTestCase {
}
@Test
+ public void build_rules_with_default_characteristic_and_disable_characteristic() throws Exception {
+ setupData("build_rules_with_default_characteristic_and_disable_characteristic");
+
+ Rules rules = provider.provide(ruleDao, debtModel, durations);
+
+ Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull"));
+ assertThat(rule.debtCharacteristic()).isNull();
+ assertThat(rule.debtRemediationFunction()).isNull();
+ }
+
+ @Test
public void fail_if_characteristic_not_found() throws Exception {
setupData("fail_if_characteristic_not_found");
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml b/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml
new file mode 100644
index 00000000000..695d1dfcb4e
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml
@@ -0,0 +1,9 @@
+<dataset>
+
+ <rules id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle" name="Avoid Null" description="Should avoid NULL" status="READY" priority="1"
+ characteristic_id="-1" default_characteristic_id="103"
+ remediation_function="[null]" default_remediation_function="LINEAR"
+ remediation_factor="[null]" default_remediation_factor="2h"
+ remediation_offset="[null]" default_remediation_offset="[null]"/>
+
+</dataset>