use of org.sonar.api.server.debt.DebtRemediationFunction in project sonarqube by SonarSource.
the class RuleMapper method setDebtRemediationFunctionFields.
private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
if (shouldReturnField(fieldsToReturn, FIELD_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_REM_FUNCTION)) {
DebtRemediationFunction debtRemediationFunction = debtRemediationFunction(ruleDto);
if (debtRemediationFunction != null) {
if (debtRemediationFunction.type() != null) {
ruleResponse.setRemFnType(debtRemediationFunction.type().name());
// Set deprecated field
ruleResponse.setDebtRemFnType(debtRemediationFunction.type().name());
}
String gapMultiplier = debtRemediationFunction.gapMultiplier();
if (gapMultiplier != null) {
ruleResponse.setRemFnGapMultiplier(gapMultiplier);
// Set deprecated field
ruleResponse.setDebtRemFnCoeff(gapMultiplier);
}
String baseEffort = debtRemediationFunction.baseEffort();
if (baseEffort != null) {
ruleResponse.setRemFnBaseEffort(baseEffort);
// Set deprecated field
ruleResponse.setDebtRemFnOffset(baseEffort);
}
}
}
}
use of org.sonar.api.server.debt.DebtRemediationFunction in project sonarqube by SonarSource.
the class RuleMapper method setDefaultDebtRemediationFunctionFields.
private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_DEFAULT_REM_FUNCTION)) {
DebtRemediationFunction defaultDebtRemediationFunction = defaultDebtRemediationFunction(ruleDto);
if (defaultDebtRemediationFunction != null) {
String gapMultiplier = defaultDebtRemediationFunction.gapMultiplier();
if (gapMultiplier != null) {
ruleResponse.setDefaultRemFnGapMultiplier(gapMultiplier);
// Set deprecated field
ruleResponse.setDefaultDebtRemFnCoeff(gapMultiplier);
}
String baseEffort = defaultDebtRemediationFunction.baseEffort();
if (baseEffort != null) {
ruleResponse.setDefaultRemFnBaseEffort(baseEffort);
// Set deprecated field
ruleResponse.setDefaultDebtRemFnOffset(baseEffort);
}
if (defaultDebtRemediationFunction.type() != null) {
ruleResponse.setDefaultRemFnType(defaultDebtRemediationFunction.type().name());
// Set deprecated field
ruleResponse.setDefaultDebtRemFnType(defaultDebtRemediationFunction.type().name());
}
}
}
}
use of org.sonar.api.server.debt.DebtRemediationFunction in project sonarqube by SonarSource.
the class RegisterRules method mergeDebtDefinitions.
private boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto) {
// Debt definitions are set to null if the sub-characteristic and the remediation function are null
DebtRemediationFunction debtRemediationFunction = def.debtRemediationFunction();
boolean hasDebt = debtRemediationFunction != null;
if (hasDebt) {
return mergeDebtDefinitions(dto, debtRemediationFunction.type().name(), debtRemediationFunction.gapMultiplier(), debtRemediationFunction.baseEffort(), def.gapDescription());
}
return mergeDebtDefinitions(dto, null, null, null, null);
}
use of org.sonar.api.server.debt.DebtRemediationFunction in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoaderTest method test_deprecated_remediation_function.
@Test
public void test_deprecated_remediation_function() {
String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>" + " <description>Desc</description>" + " <effortToFixDescription>lines</effortToFixDescription>" + " <debtRemediationFunction>LINEAR_OFFSET</debtRemediationFunction>" + " <debtRemediationFunctionCoefficient>2d 3h</debtRemediationFunctionCoefficient>" + " <debtRemediationFunctionOffset>5min</debtRemediationFunctionOffset>" + " </rule>" + "</rules>";
RulesDefinition.Rule rule = load(xml).rule("1");
assertThat(rule.gapDescription()).isEqualTo("lines");
DebtRemediationFunction function = rule.debtRemediationFunction();
assertThat(function).isNotNull();
assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
assertThat(function.gapMultiplier()).isEqualTo("2d3h");
assertThat(function.baseEffort()).isEqualTo("5min");
}
use of org.sonar.api.server.debt.DebtRemediationFunction in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoaderTest method test_linear_remediation_function.
@Test
public void test_linear_remediation_function() throws Exception {
String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>" + " <description>Desc</description>" + " <gapDescription>lines</gapDescription>" + " <remediationFunction>LINEAR</remediationFunction>" + " <remediationFunctionGapMultiplier>2d 3h</remediationFunctionGapMultiplier>" + " </rule>" + "</rules>";
RulesDefinition.Rule rule = load(xml).rule("1");
assertThat(rule.gapDescription()).isEqualTo("lines");
DebtRemediationFunction function = rule.debtRemediationFunction();
assertThat(function).isNotNull();
assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
assertThat(function.gapMultiplier()).isEqualTo("2d3h");
assertThat(function.baseEffort()).isNull();
}
Aggregations