.setSeverity(Severity.MINOR);
x1Rule
- .setDebtCharacteristic("INTEGRATION_TESTABILITY")
+ .setDebtSubCharacteristic("INTEGRATION_TESTABILITY")
.setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
x1Rule.createParam("acceptWhitespace")
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");
* .setSeverity(Severity.MINOR);
*
* x1Rule
- * .setDebtCharacteristic("INTEGRATION_TESTABILITY")
+ * .setDebtSubCharacteristic("INTEGRATION_TESTABILITY")
* .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
*
* x1Rule.createParam("acceptWhitespace")
* </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 {
*
* }
* }
* </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 {
*
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();
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;
}
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));
}
}
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;
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);
}
@CheckForNull
- public String debtCharacteristic() {
- return debtCharacteristic;
+ public String debtSubCharacteristic() {
+ return debtSubCharacteristic;
}
@CheckForNull
.setSeverity(Severity.BLOCKER)
.setInternalKey("/something")
.setStatus(RuleStatus.BETA)
- .setDebtCharacteristic("COMPILER")
+ .setDebtSubCharacteristic("COMPILER")
.setEffortToFixDescription("squid.S115.effortToFix")
.setTags("one", "two")
.addTags("two", "three", "four");
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");
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();
}
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]'");
}
}
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]'");
}
}
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()));
@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;
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");
.setInternalKey("config1")
.setTags("tag1", "tag3", "tag5");
- rule1.setDebtCharacteristic("MEMORY_EFFICIENCY")
+ rule1.setDebtSubCharacteristic("MEMORY_EFFICIENCY")
.setDebtRemediationFunction(rule1.debtRemediationFunctions().linearWithOffset("5d", "10h"))
.setEffortToFixDescription("squid.S115.effortToFix");