aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-03-16 12:08:57 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-03-16 12:44:04 +0100
commit155d3d07c1e888a7cd51c57dceb58188e06635e7 (patch)
tree0083482d93768b943a7c30338d1ea8600f2752ef
parent1becdaad55517706a85ff5f2efeeac4d6cf42265 (diff)
downloadsonarqube-155d3d07c1e888a7cd51c57dceb58188e06635e7.tar.gz
sonarqube-155d3d07c1e888a7cd51c57dceb58188e06635e7.zip
SONAR-7453 Finish renaming of debt to effort
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/ShowAction.java7
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/rule/ws/example-show.json11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java20
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/SearchActionMediumTest/search_rules_with_deprecated_fields.json25
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_deprecated_rule_rem_function_fields.json15
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java33
-rw-r--r--sonar-ws/src/main/protobuf/ws-rules.proto2
9 files changed, 125 insertions, 26 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
index a502405ab5c..612df752a9b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
@@ -45,7 +45,9 @@ import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_CREATED_AT;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEBT_OVERLOADED;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEBT_REM_FUNCTION;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEFAULT_DEBT_REM_FUNCTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEFAULT_REM_FUNCTION;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_EFFORT_TO_FIX_DESCRIPTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_GAP_DESCRIPTION;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_HTML_DESCRIPTION;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_INTERNAL_KEY;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_IS_TEMPLATE;
@@ -55,6 +57,8 @@ import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_MARKDOWN_DESC
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_NAME;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_NOTE_LOGIN;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_PARAMS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_REM_FUNCTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_REM_FUNCTION_OVERLOADED;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_REPO;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_SEVERITY;
import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_STATUS;
@@ -104,7 +108,7 @@ public class RuleMapper {
setTemplateKey(ruleResponse, ruleDto, result, fieldsToReturn);
setDebtRemediationFunctionFields(ruleResponse, ruleDto, fieldsToReturn);
setDefaultDebtRemediationFunctionFields(ruleResponse, ruleDto, fieldsToReturn);
- setIsDebtOverloaded(ruleResponse, ruleDto, fieldsToReturn);
+ setIsRemediationFunctionOverloaded(ruleResponse, ruleDto, fieldsToReturn);
setEffortToFixDescription(ruleResponse, ruleDto, fieldsToReturn);
return ruleResponse.build();
@@ -117,20 +121,22 @@ public class RuleMapper {
}
private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
- if (shouldReturnField(fieldsToReturn, FIELD_EFFORT_TO_FIX_DESCRIPTION) && ruleDto.getGapDescription() != null) {
+ if ((shouldReturnField(fieldsToReturn, FIELD_EFFORT_TO_FIX_DESCRIPTION) || shouldReturnField(fieldsToReturn, FIELD_GAP_DESCRIPTION))
+ && ruleDto.getGapDescription() != null) {
ruleResponse.setEffortToFixDescription(ruleDto.getGapDescription());
ruleResponse.setGapDescription(ruleDto.getGapDescription());
}
}
- private static void setIsDebtOverloaded(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
- if (shouldReturnField(fieldsToReturn, FIELD_DEBT_OVERLOADED)) {
- ruleResponse.setDebtOverloaded(ruleToOverloaded(ruleDto));
+ private static void setIsRemediationFunctionOverloaded(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
+ if (shouldReturnField(fieldsToReturn, FIELD_DEBT_OVERLOADED) || shouldReturnField(fieldsToReturn, FIELD_REM_FUNCTION_OVERLOADED)) {
+ ruleResponse.setDebtOverloaded(isRemediationFunctionOverloaded(ruleDto));
+ ruleResponse.setRemFnOverloaded(isRemediationFunctionOverloaded(ruleDto));
}
}
private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
- if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION)) {
+ 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();
@@ -155,7 +161,7 @@ public class RuleMapper {
}
private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
- if (shouldReturnField(fieldsToReturn, FIELD_DEBT_REM_FUNCTION)) {
+ if (shouldReturnField(fieldsToReturn, FIELD_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_REM_FUNCTION)) {
DebtRemediationFunction debtRemediationFunction = debtRemediationFunction(ruleDto);
if (debtRemediationFunction != null) {
if (debtRemediationFunction.type() != null) {
@@ -297,7 +303,7 @@ public class RuleMapper {
return fieldsToReturn.isEmpty() || fieldsToReturn.contains(fieldName);
}
- private static boolean ruleToOverloaded(RuleDto rule) {
+ private static boolean isRemediationFunctionOverloaded(RuleDto rule) {
return rule.getRemediationFunction() != null;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
index 8d622a584d2..1f8662c6fb8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
@@ -125,7 +125,14 @@ public class SearchAction implements RulesWsAction {
}
WebService.NewParam paramFields = action.createParam(Param.FIELDS)
- .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default, except actives.")
+ .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default, except actives." +
+ "Since 5.5, following fields have been deprecated :" +
+ "<ul>" +
+ "<li>\"defaultDebtRemFn\" becomes \"defaultRemFn\"</li>" +
+ "<li>\"debtRemFn\" becomes \"remFn\"</li>" +
+ "<li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
+ "<li>\"debtOverloaded\" becomes \"remFnOverloaded\"</li>" +
+ "</ul>")
.setPossibleValues(OPTIONAL_FIELDS);
Iterator<String> it = OPTIONAL_FIELDS.iterator();
paramFields.setExampleValue(String.format("%s,%s", it.next(), it.next()));
@@ -166,11 +173,14 @@ public class SearchAction implements RulesWsAction {
protected void doDefinition(WebService.NewAction action) {
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>" +
+ "<ul>" +
+ "<li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
"<li>\"debtRemFnCoeff\" becomes \"remFnGapMultiplier\"</li>" +
"<li>\"defaultDebtRemFnCoeff\" becomes \"defaultRemFnGapMultiplier\"</li>" +
"<li>\"debtRemFnOffset\" becomes \"remFnBaseEffort\"</li>" +
- "<li>\"defaultDebtRemFnOffset\" becomes \"defaultRemFnBaseEffort\"</li></ul>")
+ "<li>\"defaultDebtRemFnOffset\" becomes \"defaultRemFnBaseEffort\"</li>" +
+ "<li>\"debtOverloaded\" becomes \"remFnOverloaded\"</li>" +
+ "</ul>")
.setResponseExample(Resources.getResource(getClass(), "example-search.json"))
.setSince("4.4")
.setHandler(this);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ShowAction.java
index 14a1616fafa..cfe1b320862 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ShowAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ShowAction.java
@@ -62,11 +62,14 @@ public class ShowAction implements RulesWsAction {
.createAction("show")
.setDescription("Get detailed information about a rule" +
"Since 5.5, following fields in the response have been deprecated :" +
- "<ul><li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
+ "<ul>" +
+ "<li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
"<li>\"debtRemFnCoeff\" becomes \"remFnGapMultiplier\"</li>" +
"<li>\"defaultDebtRemFnCoeff\" becomes \"defaultRemFnGapMultiplier\"</li>" +
"<li>\"debtRemFnOffset\" becomes \"remFnBaseEffort\"</li>" +
- "<li>\"defaultDebtRemFnOffset\" becomes \"defaultRemFnBaseEffort\"</li></ul>")
+ "<li>\"defaultDebtRemFnOffset\" becomes \"defaultRemFnBaseEffort\"</li>" +
+ "<li>\"debtOverloaded\" becomes \"remFnOverloaded\"</li>" +
+ "</ul>")
.setSince("4.2")
.setResponseExample(Resources.getResource(getClass(), "example-show.json"))
.setHandler(this);
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/rule/ws/example-show.json b/server/sonar-server/src/main/resources/org/sonar/server/rule/ws/example-show.json
index 48439fc3f05..3c313351cf1 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/rule/ws/example-show.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/rule/ws/example-show.json
@@ -9,9 +9,14 @@
"template": false,
"tags": [],
"sysTags": ["brain-overload"],
- "debtSubChar": "39",
- "debtRemFnType": "CONSTANT_ISSUE",
- "debtRemFnBaseEffort": "10min",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "5d",
+ "remFnBaseEffort": "10h",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnGapMultiplier": "6d",
+ "defaultRemFnBaseEffort": "11h",
+ "remFnOverloaded": true,
+ "gapDescription": "java.S001.effortToFix",
"lang": "java",
"langName": "Java",
"type": "CODE_SMELL",
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
index a52e8ba57cd..76d558ff0fb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
@@ -605,6 +605,26 @@ public class SearchActionMediumTest {
result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[]}");
}
+ @Test
+ public void search_rules_with_deprecated_fields() throws Exception {
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
+ .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
+ .setDefaultRemediationGapMultiplier("1h")
+ .setDefaultRemediationBaseEffort("15min")
+ .setRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
+ .setRemediationGapMultiplier("2h")
+ .setRemediationBaseEffort("25min"));
+ dbSession.commit();
+ ruleIndexer.index();
+
+ WsTester.TestRequest request = tester.wsTester()
+ .newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
+ .setParam(WebService.Param.FIELDS, "name,defaultDebtRemFn,debtRemFn,effortToFixDescription,debtOverloaded");
+ WsTester.Result result = request.execute();
+
+ result.assertJson(getClass(), "search_rules_with_deprecated_fields.json");
+ }
+
private ActiveRuleDto newActiveRule(QualityProfileDto profile, RuleDto rule) {
return ActiveRuleDto.createFor(profile, rule)
.setInheritance(null)
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/SearchActionMediumTest/search_rules_with_deprecated_fields.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/SearchActionMediumTest/search_rules_with_deprecated_fields.json
new file mode 100644
index 00000000000..6bac1056119
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/SearchActionMediumTest/search_rules_with_deprecated_fields.json
@@ -0,0 +1,25 @@
+{
+ "rules": [
+ {
+ "key": "xoo:x1",
+ "name": "Rule x1",
+ "defaultDebtRemFnType": "LINEAR_OFFSET",
+ "defaultDebtRemFnCoeff": "1h",
+ "defaultDebtRemFnOffset": "15min",
+ "effortToFixDescription": "xoo.x1.effortToFix",
+ "debtOverloaded": true,
+ "debtRemFnType": "LINEAR_OFFSET",
+ "debtRemFnCoeff": "2h",
+ "debtRemFnOffset": "25min",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnGapMultiplier": "1h",
+ "defaultRemFnBaseEffort": "15min",
+ "remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "2h",
+ "remFnBaseEffort": "25min",
+ "remFnOverloaded": true,
+ "gapDescription": "xoo.x1.effortToFix",
+ "type": "CODE_SMELL"
+ }
+ ]
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_deprecated_rule_rem_function_fields.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_deprecated_rule_rem_function_fields.json
index b017ed67c55..c519f2827fa 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_deprecated_rule_rem_function_fields.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_deprecated_rule_rem_function_fields.json
@@ -9,19 +9,20 @@
"severity": "MINOR",
"status": "BETA",
"remFnType": "LINEAR_OFFSET",
+ "remFnGapMultiplier": "5d",
+ "remFnBaseEffort": "10h",
+ "defaultRemFnType": "LINEAR_OFFSET",
+ "defaultRemFnGapMultiplier": "6d",
+ "defaultRemFnBaseEffort": "11h",
+ "remFnOverloaded": true,
+ "gapDescription": "java.S001.effortToFix",
"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"
+ "effortToFixDescription": "java.S001.effortToFix"
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java
index 503ba93a322..3060d43fc50 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java
@@ -56,17 +56,44 @@ public class RulesWsParameters {
public static final String FIELD_NOTE_LOGIN = "noteLogin";
public static final String FIELD_MARKDOWN_NOTE = "mdNote";
public static final String FIELD_HTML_NOTE = "htmlNote";
+
+ /**
+ * @deprecated since 5.5, replaced by {@link #FIELD_DEFAULT_REM_FUNCTION}
+ */
+ @Deprecated
public static final String FIELD_DEFAULT_DEBT_REM_FUNCTION = "defaultDebtRemFn";
+ public static final String FIELD_DEFAULT_REM_FUNCTION = "defaultRemFn";
+
+ /**
+ * @deprecated since 5.5, replaced by {@link #FIELD_REM_FUNCTION}
+ */
+ @Deprecated
+ public static final String FIELD_DEBT_REM_FUNCTION = "debtRemFn";
+ public static final String FIELD_REM_FUNCTION = "remFn";
+
+ /**
+ * @deprecated since 5.5, replaced by {@link #FIELD_GAP_DESCRIPTION}
+ */
+ @Deprecated
public static final String FIELD_EFFORT_TO_FIX_DESCRIPTION = "effortToFixDescription";
+ public static final String FIELD_GAP_DESCRIPTION = "gapDescription";
+
+ /**
+ * @deprecated since 5.5, replaced by {@link #FIELD_REM_FUNCTION_OVERLOADED}
+ */
+ @Deprecated
public static final String FIELD_DEBT_OVERLOADED = "debtOverloaded";
- public static final String FIELD_DEBT_REM_FUNCTION = "debtRemFn";
+ public static final String FIELD_REM_FUNCTION_OVERLOADED = "remFnOverloaded";
+
public static final String FIELD_PARAMS = "params";
public static final String FIELD_ACTIVES = "actives";
public static final Set<String> OPTIONAL_FIELDS = ImmutableSet.of(FIELD_REPO, FIELD_NAME, FIELD_CREATED_AT, FIELD_SEVERITY, FIELD_STATUS, FIELD_INTERNAL_KEY, FIELD_IS_TEMPLATE,
FIELD_TEMPLATE_KEY, FIELD_TAGS, FIELD_SYSTEM_TAGS, FIELD_LANGUAGE, FIELD_LANGUAGE_NAME, FIELD_HTML_DESCRIPTION, FIELD_MARKDOWN_DESCRIPTION, FIELD_NOTE_LOGIN,
- FIELD_MARKDOWN_NOTE, FIELD_HTML_NOTE, FIELD_DEFAULT_DEBT_REM_FUNCTION, FIELD_EFFORT_TO_FIX_DESCRIPTION, FIELD_DEBT_OVERLOADED, FIELD_DEBT_REM_FUNCTION, FIELD_PARAMS,
- FIELD_ACTIVES);
+ FIELD_MARKDOWN_NOTE, FIELD_HTML_NOTE,
+ FIELD_DEFAULT_DEBT_REM_FUNCTION, FIELD_EFFORT_TO_FIX_DESCRIPTION, FIELD_DEBT_OVERLOADED, FIELD_DEBT_REM_FUNCTION,
+ FIELD_DEFAULT_REM_FUNCTION, FIELD_GAP_DESCRIPTION, FIELD_REM_FUNCTION_OVERLOADED, FIELD_REM_FUNCTION,
+ FIELD_PARAMS, FIELD_ACTIVES);
private RulesWsParameters() {
// prevent instantiation
diff --git a/sonar-ws/src/main/protobuf/ws-rules.proto b/sonar-ws/src/main/protobuf/ws-rules.proto
index 46fc628ab16..08067de63ea 100644
--- a/sonar-ws/src/main/protobuf/ws-rules.proto
+++ b/sonar-ws/src/main/protobuf/ws-rules.proto
@@ -102,6 +102,7 @@ message Rule {
optional string defaultDebtRemFnOffset = 31;
// Deprecated since 5.5, replaced by gapDescription
optional string effortToFixDescription = 32;
+ // Deprecated since 5.5, replaced by remFnOverloaded
optional bool debtOverloaded = 33;
// Deprecated since 5.5, replaced by remFnType
optional string debtRemFnType = 34;
@@ -116,6 +117,7 @@ message Rule {
optional string remFnType = 41;
optional string remFnGapMultiplier = 42;
optional string remFnBaseEffort = 43;
+ optional bool remFnOverloaded = 45;
optional string gapDescription = 44;
optional sonarqube.ws.commons.RuleType type = 37;