]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4908 rename RulesDefinition#setDebtCharacteristic() to setDebtSubCharacteristic()
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 25 Mar 2014 17:02:53 +0000 (18:02 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 25 Mar 2014 17:02:53 +0000 (18:02 +0100)
-> better follow SQALE method

plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java
sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
sonar-server/src/test/java/org/sonar/server/rule/DeprecatedRulesDefinitionTest.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java

index 8bea7cbab69a002b22577b42e6a8fc88eb919c1c..b00b46df9a15476e78ef438ac35ac0d28d1c6236 100644 (file)
@@ -52,7 +52,7 @@ public class XooRulesDefinition implements RulesDefinition {
       .setSeverity(Severity.MINOR);
 
     x1Rule
-      .setDebtCharacteristic("INTEGRATION_TESTABILITY")
+      .setDebtSubCharacteristic("INTEGRATION_TESTABILITY")
       .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
 
     x1Rule.createParam("acceptWhitespace")
index 229e07ca1471086cfb1df7a3226caa9a57041cc5..1508db93b13c7897a1ab522eb1e64b831ea981fe 100644 (file)
@@ -44,7 +44,7 @@ public class XooRulesDefinitionTest {
     assertThat(x1.tags()).containsOnly("style", "security");
     assertThat(x1.htmlDescription()).isNotEmpty();
 
-    assertThat(x1.debtCharacteristic()).isEqualTo("INTEGRATION_TESTABILITY");
+    assertThat(x1.debtSubCharacteristic()).isEqualTo("INTEGRATION_TESTABILITY");
     assertThat(x1.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
     assertThat(x1.debtRemediationFunction().factor()).isEqualTo("1h");
     assertThat(x1.debtRemediationFunction().offset()).isEqualTo("30min");
index 79d08f46588c78c41a8b4c7320b69a79f3da9c4e..fff3f96e797fb2de62a5a58dbb65dcb93d727174 100644 (file)
@@ -75,7 +75,7 @@ import java.util.Set;
  *     .setSeverity(Severity.MINOR);
  *
  *     x1Rule
- *       .setDebtCharacteristic("INTEGRATION_TESTABILITY")
+ *       .setDebtSubCharacteristic("INTEGRATION_TESTABILITY")
  *       .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
  *
  *     x1Rule.createParam("acceptWhitespace")
@@ -90,7 +90,7 @@ import java.util.Set;
  * </pre>
  * <p/>
  * If rules are declared in a XML file with the standard SonarQube format, then it can be loaded by using :
- *
+ * <p/>
  * <pre>
  * public class JsSquidRulesDefinition implements RulesDefinition {
  *
@@ -109,10 +109,10 @@ import java.util.Set;
  *   }
  * }
  * </pre>
- *
+ * <p/>
  * In the above example, XML file must contain name and description of each rule. If it's not the case, then the
  * (deprecated) English bundles can be used :
- *
+ * <p/>
  * <pre>
  * public class JsSquidRulesDefinition implements RulesDefinition {
  *
@@ -376,7 +376,7 @@ public interface RulesDefinition extends ServerExtension {
     private String name, htmlDescription, internalKey, severity = Severity.MAJOR;
     private boolean template;
     private RuleStatus status = RuleStatus.defaultStatus();
-    private String debtCharacteristic;
+    private String debtSubCharacteristic;
     private DebtRemediationFunction debtRemediationFunction;
     private String effortToFixDescription;
     private final Set<String> tags = Sets.newTreeSet();
@@ -440,11 +440,14 @@ public interface RulesDefinition extends ServerExtension {
       return this;
     }
 
-    public NewRule setDebtCharacteristic(@Nullable String debtCharacteristic) {
-      this.debtCharacteristic = debtCharacteristic;
+    public NewRule setDebtSubCharacteristic(@Nullable String s) {
+      this.debtSubCharacteristic = s;
       return this;
     }
 
+    /**
+     * Factory of {@link org.sonar.api.server.debt.DebtRemediationFunction}
+     */
     public DebtRemediationFunctions debtRemediationFunctions() {
       return functions;
     }
@@ -517,8 +520,8 @@ public interface RulesDefinition extends ServerExtension {
       if (Strings.isNullOrEmpty(htmlDescription)) {
         throw new IllegalStateException(String.format("HTML description of rule %s is empty", this));
       }
-      if ((Strings.isNullOrEmpty(debtCharacteristic) && debtRemediationFunction != null) || (!Strings.isNullOrEmpty(debtCharacteristic) && debtRemediationFunction == null)) {
-        throw new IllegalStateException(String.format("Both debt characteristic and debt remediation function should be defined on rule '%s'", this));
+      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));
       }
     }
 
@@ -533,7 +536,7 @@ public interface RulesDefinition extends ServerExtension {
     private final Repository repository;
     private final String repoKey, key, name, htmlDescription, internalKey, severity;
     private final boolean template;
-    private final String debtCharacteristic;
+    private final String debtSubCharacteristic;
     private final DebtRemediationFunction debtRemediationFunction;
     private final String effortToFixDescription;
     private final Set<String> tags;
@@ -550,7 +553,7 @@ public interface RulesDefinition extends ServerExtension {
       this.severity = newRule.severity;
       this.template = newRule.template;
       this.status = newRule.status;
-      this.debtCharacteristic = newRule.debtCharacteristic;
+      this.debtSubCharacteristic = newRule.debtSubCharacteristic;
       this.debtRemediationFunction = newRule.debtRemediationFunction;
       this.effortToFixDescription = newRule.effortToFixDescription;
       this.tags = ImmutableSortedSet.copyOf(newRule.tags);
@@ -591,8 +594,8 @@ public interface RulesDefinition extends ServerExtension {
     }
 
     @CheckForNull
-    public String debtCharacteristic() {
-      return debtCharacteristic;
+    public String debtSubCharacteristic() {
+      return debtSubCharacteristic;
     }
 
     @CheckForNull
index 96351855f531a878ed39b9beab039baf8bff5fd8..186fe99dc228a3727a57dbf2322d1e246b80a533 100644 (file)
@@ -71,7 +71,7 @@ public class RulesDefinitionTest {
       .setSeverity(Severity.BLOCKER)
       .setInternalKey("/something")
       .setStatus(RuleStatus.BETA)
-      .setDebtCharacteristic("COMPILER")
+      .setDebtSubCharacteristic("COMPILER")
       .setEffortToFixDescription("squid.S115.effortToFix")
       .setTags("one", "two")
       .addTags("two", "three", "four");
@@ -93,7 +93,7 @@ public class RulesDefinitionTest {
     assertThat(rule.internalKey()).isEqualTo("/something");
     assertThat(rule.template()).isFalse();
     assertThat(rule.status()).isEqualTo(RuleStatus.BETA);
-    assertThat(rule.debtCharacteristic()).isEqualTo("COMPILER");
+    assertThat(rule.debtSubCharacteristic()).isEqualTo("COMPILER");
     assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
     assertThat(rule.debtRemediationFunction().factor()).isEqualTo("1h");
     assertThat(rule.debtRemediationFunction().offset()).isEqualTo("10min");
@@ -120,7 +120,7 @@ public class RulesDefinitionTest {
     assertThat(rule.internalKey()).isNull();
     assertThat(rule.status()).isEqualTo(RuleStatus.defaultStatus());
     assertThat(rule.tags()).isEmpty();
-    assertThat(rule.debtCharacteristic()).isNull();
+    assertThat(rule.debtSubCharacteristic()).isNull();
     assertThat(rule.debtRemediationFunction()).isNull();
   }
 
@@ -302,12 +302,12 @@ public class RulesDefinitionTest {
   public void fail_if_define_characteristic_without_function() {
     RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
     newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
-      .setDebtCharacteristic("COMPILER");
+      .setDebtSubCharacteristic("COMPILER");
     try {
       newRepository.done();
       fail();
     } catch (IllegalStateException e) {
-      assertThat(e).hasMessage("Both debt characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
+      assertThat(e).hasMessage("Both debt sub-characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
     }
   }
 
@@ -315,13 +315,13 @@ public class RulesDefinitionTest {
   public void fail_if_define_function_without_characteristic() {
     RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
     RulesDefinition.NewRule newRule = newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
-      .setDebtCharacteristic("");
+      .setDebtSubCharacteristic("");
     newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min"));
     try {
       newRepository.done();
       fail();
     } catch (IllegalStateException e) {
-      assertThat(e).hasMessage("Both debt characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
+      assertThat(e).hasMessage("Both debt sub-characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
     }
   }
 
index d9bd3ea9e3415c19f50bcab15a088220ab467b4c..343e76c9a3e2568e9beecb9de7536f87bdf39311 100644 (file)
@@ -111,7 +111,7 @@ public class DeprecatedRulesDefinition implements RulesDefinition {
   private void updateRuleDebtDefinitions(NewRule newRule, String repoKey, String ruleKey, List<RuleDebt> ruleDebts){
     RuleDebt ruleDebt = findRequirement(ruleDebts, repoKey, ruleKey);
     if (ruleDebt != null) {
-      newRule.setDebtCharacteristic(ruleDebt.characteristicKey());
+      newRule.setDebtSubCharacteristic(ruleDebt.characteristicKey());
       switch (ruleDebt.function()) {
         case LINEAR :
           newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linear(ruleDebt.factor()));
index 9155a6e9edf60970186b08bc8206151459f464b2..e592464e105c17f87bb09a128035a7d15c7cb8f7 100644 (file)
@@ -549,7 +549,7 @@ public class RuleRegistration implements Startable {
 
   @CheckForNull
   private CharacteristicDto findCharacteristic(RulesDefinition.Rule ruleDef, @Nullable Integer overridingCharacteristicId, List<CharacteristicDto> characteristicDtos) {
-    String key = ruleDef.debtCharacteristic();
+    String key = ruleDef.debtSubCharacteristic();
     // Rule is not linked to a default characteristic or characteristic has been disabled by user, nothing to do
     if (key == null) {
       return null;
index cc48bef99aa233815f8297f6e71f9a585323d9f7..a69875ff4b58fe369920a887c35bdf75f94a9d2f 100644 (file)
@@ -180,7 +180,7 @@ public class DeprecatedRulesDefinitionTest {
     RulesDefinition.Rule rule = checkstyle.rule("ConstantName");
     assertThat(rule).isNotNull();
     assertThat(rule.key()).isEqualTo("ConstantName");
-    assertThat(rule.debtCharacteristic()).isEqualTo("MEMORY_EFFICIENCY");
+    assertThat(rule.debtSubCharacteristic()).isEqualTo("MEMORY_EFFICIENCY");
     assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
     assertThat(rule.debtRemediationFunction().factor()).isEqualTo("1d");
     assertThat(rule.debtRemediationFunction().offset()).isEqualTo("10min");
index b4b2f85ee6acf382bd7da8b364e5c57797c31ea5..5e3ebe8b9d766d83a0836fe99dd00561f30fa252 100644 (file)
@@ -288,7 +288,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
         .setInternalKey("config1")
         .setTags("tag1", "tag3", "tag5");
 
-      rule1.setDebtCharacteristic("MEMORY_EFFICIENCY")
+      rule1.setDebtSubCharacteristic("MEMORY_EFFICIENCY")
         .setDebtRemediationFunction(rule1.debtRemediationFunctions().linearWithOffset("5d", "10h"))
         .setEffortToFixDescription("squid.S115.effortToFix");