Browse Source

Fix quality flaws

tags/4.3
Julien Lancelot 10 years ago
parent
commit
c7a069f5fd

+ 6
- 0
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java View File

@@ -52,6 +52,10 @@ public class DebtRemediationFunction {
// TODO validate factor and offset format
this.factor = StringUtils.deleteWhitespace(factor);
this.offset = StringUtils.deleteWhitespace(offset);
validate();
}

private void validate(){
switch (type) {
case LINEAR:
if (this.factor == null || this.offset != null) {
@@ -68,6 +72,8 @@ public class DebtRemediationFunction {
throw new ValidationException(String.format("%s is invalid, Constant/issue remediation function should only define an offset", this));
}
break;
default:
throw new IllegalStateException(String.format("Remediation function of %s is unknown", this));
}
}


+ 17
- 12
sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java View File

@@ -171,7 +171,7 @@ public class DebtRulesXMLImporter implements ServerExtension {
}

@CheckForNull
private RuleDebt processRule(RuleKey ruleKey, Properties properties){
private RuleDebt processRule(RuleKey ruleKey, Properties properties) {
try {
return createRule(ruleKey, properties);
} catch (DebtRemediationFunction.ValidationException e) {
@@ -189,17 +189,22 @@ public class DebtRulesXMLImporter implements ServerExtension {
Property offsetProperty = properties.offset();
String offset = offsetProperty != null ? offsetProperty.toDuration() : null;

String functionKey = function.getTextValue();
if ("linear_threshold".equals(functionKey) && factor != null) {
LOG.warn(String.format("Linear with threshold function is no longer used, remediation function of '%s' is replaced by linear.", ruleKey));
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.createLinear(factor));
} else if ("constant_resource".equals(functionKey)) {
LOG.warn(String.format("Constant/file function is no longer used, technical debt definitions on '%s' are ignored.", ruleKey));
} else if (DebtRemediationFunction.Type.CONSTANT_ISSUE.name().toLowerCase().equals(functionKey) && factor != null && offset == null) {
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.createConstantPerIssue(factor));
} else {
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.create(DebtRemediationFunction.Type.valueOf(functionKey.toUpperCase()), factor, offset));
}
return createRuleDebt(ruleKey, function.getTextValue(), factor, offset);
}
return null;
}

@CheckForNull
private RuleDebt createRuleDebt(RuleKey ruleKey, String function, @Nullable String factor, @Nullable String offset) {
if ("linear_threshold".equals(function) && factor != null) {
LOG.warn(String.format("Linear with threshold function is no longer used, remediation function of '%s' is replaced by linear.", ruleKey));
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.createLinear(factor));
} else if ("constant_resource".equals(function)) {
LOG.warn(String.format("Constant/file function is no longer used, technical debt definitions on '%s' are ignored.", ruleKey));
} else if (DebtRemediationFunction.Type.CONSTANT_ISSUE.name().equalsIgnoreCase(function) && factor != null && offset == null) {
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.createConstantPerIssue(factor));
} else {
return new RuleDebt().setRuleKey(ruleKey).setFunction(DebtRemediationFunction.create(DebtRemediationFunction.Type.valueOf(function.toUpperCase()), factor, offset));
}
return null;
}

Loading…
Cancel
Save