private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
if (shouldReturnField(fieldsToReturn, FIELD_EFFORT_TO_FIX_DESCRIPTION) && ruleDto.getGapDescription() != null) {
ruleResponse.setEffortToFixDescription(ruleDto.getGapDescription());
+ ruleResponse.setGapDescription(ruleDto.getGapDescription());
}
}
if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION)) {
DebtRemediationFunction defaultDebtRemediationFunction = defaultDebtRemediationFunction(ruleDto);
if (defaultDebtRemediationFunction != null) {
- if (defaultDebtRemediationFunction.coefficient() != null) {
- ruleResponse.setDefaultDebtRemFnCoeff(defaultDebtRemediationFunction.coefficient());
+ String gapMultiplier = defaultDebtRemediationFunction.coefficient();
+ if (gapMultiplier != null) {
+ ruleResponse.setDefaultRemFnGapMultiplier(gapMultiplier);
+ // Set deprecated field
+ ruleResponse.setDefaultDebtRemFnCoeff(gapMultiplier);
}
- if (defaultDebtRemediationFunction.offset() != null) {
- ruleResponse.setDefaultDebtRemFnOffset(defaultDebtRemediationFunction.offset());
+ String baseEffort = defaultDebtRemediationFunction.offset();
+ 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());
}
}
DebtRemediationFunction debtRemediationFunction = debtRemediationFunction(ruleDto);
if (debtRemediationFunction != null) {
if (debtRemediationFunction.type() != null) {
+ ruleResponse.setRemFnType(debtRemediationFunction.type().name());
+ // Set deprecated field
ruleResponse.setDebtRemFnType(debtRemediationFunction.type().name());
}
- if (debtRemediationFunction.coefficient() != null) {
- ruleResponse.setDebtRemFnCoeff(debtRemediationFunction.coefficient());
+ String gapMultiplier = debtRemediationFunction.coefficient();
+ if (gapMultiplier != null) {
+ ruleResponse.setRemFnGapMultiplier(gapMultiplier);
+ // Set deprecated field
+ ruleResponse.setDebtRemFnCoeff(gapMultiplier);
}
- if (debtRemediationFunction.offset() != null) {
- ruleResponse.setDebtRemFnOffset(debtRemediationFunction.offset());
+ String baseEffort = debtRemediationFunction.offset();
+ if (baseEffort != null) {
+ ruleResponse.setRemFnBaseEffort(baseEffort);
+ // Set deprecated field
+ ruleResponse.setDebtRemFnOffset(baseEffort);
}
}
}
}
protected void doDefinition(WebService.NewAction action) {
- action.setDescription("Search for a collection of relevant rules matching a specified query")
+ action.setDescription("Search for a collection of relevant rules matching a specified query.<br/>" +
+ "Since 5.5, following fields in the response have been deprecated :" +
+ "<ul><li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
+ "<li>\"debtRemFnCoeff\" becomes \"debtRemFnGapMultiplier\"</li>" +
+ "<li>\"defaultDebtRemFnCoeff\" becomes \"defaultDebtRemFnGapMultiplier\"</li>" +
+ "<li>\"debtRemFnOffset\" becomes \"debtRemFnBaseEffort\"</li>" +
+ "<li>\"defaultDebtRemFnOffset\" becomes \"defaultDebtRemFnBaseEffort\"</li></ul>")
.setResponseExample(Resources.getResource(getClass(), "example-search.json"))
.setSince("4.4")
.setHandler(this);
import org.sonarqube.ws.Rules.UpdateResponse;
import static java.util.Collections.singletonList;
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public static final String PARAM_KEY = "key";
public static final String PARAM_TAGS = "tags";
public static final String PARAM_MARKDOWN_NOTE = "markdown_note";
- public static final String PARAM_DEBT_SUB_CHARACTERISTIC = "debt_sub_characteristic";
- public static final String PARAM_DEBT_REMEDIATION_FN_TYPE = "debt_remediation_fn_type";
- public static final String PARAM_DEBT_REMEDIATION_FN_OFFSET = "debt_remediation_fn_offset";
- public static final String PARAM_DEBT_REMEDIATION_FY_COEFF = "debt_remediation_fy_coeff";
+ public static final String PARAM_REMEDIATION_FN_TYPE = "remediation_fn_type";
+ public static final String DEPRECATED_PARAM_REMEDIATION_FN_TYPE = "debt_remediation_fn_type";
+ public static final String PARAM_REMEDIATION_FN_BASE_EFFORT = "remediation_fn_base_effort";
+ public static final String DEPRECATED_PARAM_REMEDIATION_FN_OFFSET = "debt_remediation_fn_offset";
+ public static final String PARAM_REMEDIATION_FN_GAP_MULTIPLIER = "remediation_fy_gap_multiplier";
+ public static final String DEPRECATED_PARAM_REMEDIATION_FN_COEFF = "debt_remediation_fy_coeff";
public static final String PARAM_NAME = "name";
public static final String PARAM_DESCRIPTION = "markdown_description";
public static final String PARAM_SEVERITY = "severity";
"if the parameter is not set.")
.setExampleValue("my *note*");
- action.createParam(PARAM_DEBT_SUB_CHARACTERISTIC)
+ action.createParam("debt_sub_characteristic")
.setDescription("Debt characteristics are no more supported. This parameter is ignored.")
.setDeprecatedSince("5.5");
- action.createParam(PARAM_DEBT_REMEDIATION_FN_TYPE)
+ action.createParam(PARAM_REMEDIATION_FN_TYPE)
+ .setDescription("Type of the remediation function of the rule")
+ .setPossibleValues(DebtRemediationFunction.Type.values())
+ .setSince("5.5");
+
+ action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_TYPE)
+ .setDeprecatedSince("5.5")
.setPossibleValues(DebtRemediationFunction.Type.values());
- action.createParam(PARAM_DEBT_REMEDIATION_FN_OFFSET)
- .setExampleValue("1d");
+ action.createParam(PARAM_REMEDIATION_FN_BASE_EFFORT)
+ .setDescription("Base effort of the remediation function of the rule")
+ .setExampleValue("1d")
+ .setSince("5.5");
+
+ action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET)
+ .setDeprecatedSince("5.5");
- action.createParam(PARAM_DEBT_REMEDIATION_FY_COEFF)
- .setExampleValue("3min");
+ action.createParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER)
+ .setDeprecatedSince("Gap multiplier of the remediation function of the rule")
+ .setExampleValue("3min")
+ .setSince("5.5");
+
+ action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_COEFF)
+ .setDeprecatedSince("5.5");
action
.createParam(PARAM_NAME)
}
private void readDebt(Request request, RuleUpdate update) {
- String value = request.param(PARAM_DEBT_REMEDIATION_FN_TYPE);
+ String value = defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_TYPE), request.param(DEPRECATED_PARAM_REMEDIATION_FN_TYPE));
if (value != null) {
if (StringUtils.isBlank(value)) {
update.setDebtRemediationFunction(null);
} else {
DebtRemediationFunction fn = new DefaultDebtRemediationFunction(
- DebtRemediationFunction.Type.valueOf(value), request.param(PARAM_DEBT_REMEDIATION_FY_COEFF),
- request.param(PARAM_DEBT_REMEDIATION_FN_OFFSET));
+ DebtRemediationFunction.Type.valueOf(value),
+ defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), request.param(DEPRECATED_PARAM_REMEDIATION_FN_COEFF)),
+ defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_BASE_EFFORT), request.param(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET)));
update.setDebtRemediationFunction(fn);
}
}
"sysTags": ["brain-overload"],
"debtSubChar": "39",
"debtRemFnType": "CONSTANT_ISSUE",
- "debtRemFnOffset": "10min",
+ "debtRemFnBaseEffort": "10min",
"lang": "java",
"langName": "Java",
"type": "CODE_SMELL",
request.execute().assertJson(getClass(), "encode_html_description_of_manual_rule.json");
}
+ @Test
+ public void show_deprecated_rule_rem_function_fields() throws Exception {
+ RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001"))
+ .setName("Rule S001")
+ .setDescription("Rule S001 <b>description</b>")
+ .setSeverity(Severity.MINOR)
+ .setStatus(RuleStatus.BETA)
+ .setConfigKey("InternalKeyS001")
+ .setLanguage("xoo")
+ .setDefaultRemediationFunction("LINEAR_OFFSET")
+ .setDefaultRemediationGapMultiplier("6d")
+ .setDefaultRemediationBaseEffort("11h")
+ .setRemediationFunction("LINEAR_OFFSET")
+ .setRemediationGapMultiplier("5d")
+ .setRemediationBaseEffort("10h");
+ ruleDao.insert(session, ruleDto);
+ session.commit();
+
+ WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
+ .setParam("key", ruleDto.getKey().toString());
+ request.execute().assertJson(getClass(), "show_deprecated_rule_rem_function_fields.json");
+ }
+
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+import static org.sonar.api.server.debt.DebtRemediationFunction.Type.LINEAR;
+import static org.sonar.api.server.debt.DebtRemediationFunction.Type.LINEAR_OFFSET;
+import static org.sonar.server.rule.ws.UpdateAction.PARAM_REMEDIATION_FN_BASE_EFFORT;
+import static org.sonar.server.rule.ws.UpdateAction.PARAM_REMEDIATION_FN_GAP_MULTIPLIER;
+import static org.sonar.server.rule.ws.UpdateAction.PARAM_REMEDIATION_FN_TYPE;
public class UpdateActionMediumTest {
session.close();
}
+ @Test
+ public void update_rule_remediation_function() throws Exception {
+ RuleDto rule = RuleTesting.newXooX1()
+ .setDefaultRemediationFunction(LINEAR.toString())
+ .setDefaultRemediationGapMultiplier("10d")
+ .setDefaultRemediationBaseEffort(null)
+ .setRemediationFunction(null)
+ .setRemediationGapMultiplier(null)
+ .setRemediationBaseEffort(null);
+ ruleDao.insert(session, rule);
+ session.commit();
+
+ WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update")
+ .setParam("key", rule.getKey().toString())
+ .setParam(PARAM_REMEDIATION_FN_TYPE, LINEAR_OFFSET.toString())
+ .setParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER, "15d")
+ .setParam(PARAM_REMEDIATION_FN_BASE_EFFORT, "5min")
+ ;
+ request.execute().assertJson(getClass(), "update_rule_remediation_function.json");
+ }
+
+ @Test
+ public void update_custom_rule_with_deprecated_remediation_function_parameters() throws Exception {
+ RuleDto rule = RuleTesting.newXooX1()
+ .setDefaultRemediationFunction(LINEAR_OFFSET.toString())
+ .setDefaultRemediationGapMultiplier("10d")
+ .setDefaultRemediationBaseEffort("5min")
+ .setRemediationFunction(LINEAR_OFFSET.toString())
+ .setRemediationGapMultiplier("15min")
+ .setRemediationBaseEffort("3h");
+ ruleDao.insert(session, rule);
+ session.commit();
+
+ WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update")
+ .setParam("key", rule.getKey().toString())
+ .setParam("debt_remediation_fn_type", LINEAR_OFFSET.toString())
+ .setParam("debt_remediation_fy_coeff", "11d")
+ .setParam("debt_remediation_fn_offset", "6min");
+ request.execute().assertJson(getClass(), "deprecated_remediation_function.json");
+ }
+
@Test
public void update_custom_rule() throws Exception {
// Template rule
--- /dev/null
+{
+ "rule": {
+ "internalKey": "InternalKeyS001",
+ "isTemplate": false,
+ "key": "java:S001",
+ "lang": "xoo",
+ "name": "Rule S001",
+ "repo": "java",
+ "severity": "MINOR",
+ "status": "BETA",
+ "remFnType": "LINEAR_OFFSET",
+ "debtRemFnType": "LINEAR_OFFSET",
+ "debtRemFnCoeff": "5d",
+ "remFnGapMultiplier": "5d",
+ "debtRemFnOffset": "10h",
+ "remFnBaseEffort": "10h",
+ "defaultDebtRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultDebtRemFnCoeff": "6d",
+ "defaultRemFnGapMultiplier": "6d",
+ "defaultDebtRemFnOffset": "11h",
+ "defaultRemFnBaseEffort": "11h",
+ "debtOverloaded": true,
+ "effortToFixDescription": "java.S001.effortToFix",
+ "gapDescription": "java.S001.effortToFix"
+ }
+}
"severity": "MINOR",
"status": "BETA",
"isTemplate": false,
- "debtRemFnType": "LINEAR_OFFSET",
- "debtRemFnCoeff": "5d",
- "debtRemFnOffset": "10h",
- "defaultDebtRemFnType": "LINEAR",
- "defaultDebtRemFnCoeff": "5min",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "5d",
+ "remFnBaseEffort": "10h",
+ "defaultRemFnType": "LINEAR",
+ "defaultRemFnGapMultiplier": "5min",
"debtOverloaded": true,
"lang": "xoo"
}
{
"rule": {
- "debtRemFnType": "LINEAR_OFFSET",
- "debtRemFnCoeff": "5d",
- "debtRemFnOffset": "10h",
- "defaultDebtRemFnType": "LINEAR_OFFSET",
- "defaultDebtRemFnCoeff": "5d",
- "defaultDebtRemFnOffset": "10h",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "5d",
+ "remFnBaseEffort": "10h",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnGapMultiplier": "5d",
+ "defaultRemFnBaseEffort": "10h",
"debtOverloaded": false,
- "effortToFixDescription": "java.S001.effortToFix",
+ "gapDescription": "java.S001.effortToFix",
"htmlDesc": "Rule S001 <b>description</b>",
"internalKey": "InternalKeyS001",
"isTemplate": false,
"severity": "MINOR",
"status": "BETA",
"isTemplate": false,
- "debtRemFnType": "LINEAR_OFFSET",
- "debtRemFnCoeff": "5d",
- "debtRemFnOffset": "10h",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "5d",
+ "remFnBaseEffort": "10h",
"debtOverloaded": true,
"lang": "xoo"
}
--- /dev/null
+{
+ "rule": {
+ "key": "xoo:x1",
+ "defaultDebtRemFnType": "LINEAR_OFFSET",
+ "defaultDebtRemFnCoeff": "10d",
+ "defaultDebtRemFnOffset": "5min",
+ "effortToFixDescription": "xoo.x1.effortToFix",
+ "debtRemFnType": "LINEAR_OFFSET",
+ "debtRemFnCoeff": "11d",
+ "debtRemFnOffset": "6min",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnGapMultiplier": "10d",
+ "defaultRemFnBaseEffort": "5min",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "11d",
+ "remFnBaseEffort": "6min",
+ "gapDescription": "xoo.x1.effortToFix",
+ }
+}
--- /dev/null
+{
+ "rule": {
+ "key": "xoo:x1",
+ "defaultRemFnType": "LINEAR",
+ "defaultRemFnGapMultiplier": "10d",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "15d",
+ "remFnBaseEffort": "5min",
+ "gapDescription": "xoo.x1.effortToFix"
+ }
+}
optional string lang = 19;
optional string langName = 20;
optional Params params = 21;
- // debt fields, unsupported since 5.5
+ // characteristic fields, unsupported since 5.5
optional string unusedDefaultDebtChar = 23;
optional string unusedDefaultDebtSubChar = 24;
optional string unusedDebtChar = 25;
optional string unusedDebtCharName = 27;
optional string unusedDebtSubCharName = 28;
+ // Deprecated since 5.5, replaced by defaultRemFnType
optional string defaultDebtRemFnType = 29;
+ // Deprecated since 5.5, replaced by defaultRemFnGapMultiplier
optional string defaultDebtRemFnCoeff = 30;
+ // Deprecated since 5.5, replaced by defaultRemFnBaseEffort
optional string defaultDebtRemFnOffset = 31;
+ // Deprecated since 5.5, replaced by gapDescription
optional string effortToFixDescription = 32;
optional bool debtOverloaded = 33;
+ // Deprecated since 5.5, replaced by remFnType
optional string debtRemFnType = 34;
+ // Deprecated since 5.5, replaced by remFnGapMultiplier
optional string debtRemFnCoeff = 35;
+ // Deprecated since 5.5, replaced by remFnBaseEffort
optional string debtRemFnOffset = 36;
+
+ optional string defaultRemFnType = 38;
+ optional string defaultRemFnGapMultiplier = 39;
+ optional string defaultRemFnBaseEffort = 40;
+ optional string remFnType = 41;
+ optional string remFnGapMultiplier = 42;
+ optional string remFnBaseEffort = 43;
+ optional string gapDescription = 44;
+
optional sonarqube.ws.commons.RuleType type = 37;
message Params {