]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 When loading rules on batch side, do not load rule debt informations if...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 13 Mar 2014 08:05:24 +0000 (09:05 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 13 Mar 2014 10:29:29 +0000 (11:29 +0100)
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_disable_characteristic.xml [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java

index 9d68bc326ab8e7144ea8eb586feaa0f5294a878c..75d7c9ae5876c5d08ffd01b7f9ff0f1337a01da4 100644 (file)
@@ -78,15 +78,17 @@ public class RulesProvider extends ProviderAdapter {
         .setDescription(ruleDto.getDescription())
         .setStatus(RuleStatus.valueOf(ruleDto.getStatus()));
       // TODO should we set metadata ?
-      Integer characteristicId = ruleDto.getCharacteristicId();
-      Integer defaultCharacteristicId = ruleDto.getDefaultCharacteristicId();
-      if (characteristicId != null) {
-        Characteristic characteristic = characteristic(characteristicId, ruleKey, debtModel);
-        updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getRemediationFunction(), ruleDto.getRemediationFactor(), ruleDto.getRemediationOffset(), durations);
-      } else if (defaultCharacteristicId != null) {
-        Characteristic characteristic = characteristic(defaultCharacteristicId, ruleKey, debtModel);
-        updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationFactor(),
-          ruleDto.getDefaultRemediationOffset(), durations);
+      if (!ruleDto.isCharacteristicDisabled()) {
+        Integer characteristicId = ruleDto.getCharacteristicId();
+        Integer defaultCharacteristicId = ruleDto.getDefaultCharacteristicId();
+        if (characteristicId != null) {
+          Characteristic characteristic = characteristic(characteristicId, ruleKey, debtModel);
+          updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getRemediationFunction(), ruleDto.getRemediationFactor(), ruleDto.getRemediationOffset(), durations);
+        } else if (defaultCharacteristicId != null) {
+          Characteristic characteristic = characteristic(defaultCharacteristicId, ruleKey, debtModel);
+          updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationFactor(),
+            ruleDto.getDefaultRemediationOffset(), durations);
+        }
       }
       for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) {
         newRule.addParam(ruleParamDto.getName())
index 5b457dd01c00a525515ab31835ed987ac549767d..14be820ef4f15419b2db98e771e8d4d56d71b14d 100644 (file)
@@ -144,6 +144,19 @@ public class RulesProviderTest extends AbstractDaoTestCase {
     assertThat(rule.offset()).isNull();
   }
 
+  @Test
+  public void build_rules_with_disable_characteristic() throws Exception {
+    setupData("build_rules_with_disable_characteristic");
+
+    Rules rules = provider.provide(ruleDao, debtModel, durations);
+
+    Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull"));
+    assertThat(rule.characteristic()).isNull();
+    assertThat(rule.function()).isNull();
+    assertThat(rule.factor()).isNull();
+    assertThat(rule.offset()).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_disable_characteristic.xml b/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_disable_characteristic.xml
new file mode 100644 (file)
index 0000000..eb181a7
--- /dev/null
@@ -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="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_factor="[null]" default_remediation_factor="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"/>
+
+</dataset>
index 1a15490d8a6d2b58e2b3e5803918aef505f7af6a..d0a8b978db3c1f4acbf6582561526b65cd258f1b 100644 (file)
@@ -32,7 +32,7 @@ import java.util.Date;
 
 public final class RuleDto {
 
-  public final static Integer DISABLED_CHARACTERISTIC_ID = -1;
+  public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
 
   private Integer id;
   private String repositoryKey;
@@ -314,8 +314,8 @@ public final class RuleDto {
     return this;
   }
 
-  public boolean isCharacteristicOverridden(){
-    return !DISABLED_CHARACTERISTIC_ID.equals(characteristicId);
+  public boolean isCharacteristicDisabled(){
+    return DISABLED_CHARACTERISTIC_ID.equals(characteristicId);
   }
 
   @Override