From: Jean-Baptiste Lievremont Date: Fri, 25 Jul 2014 09:32:42 +0000 (+0200) Subject: SONAR-5137 Add rule param type to WS response, use it in rule activation dialog X-Git-Tag: 4.5-RC1~339^2~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d2074c3527fab592cd65e91d7e2286075f8f3e0b;p=sonarqube.git SONAR-5137 Add rule param type to WS response, use it in rule activation dialog Merged from branch-4.4 9646b5948e635505fdd66c48efffbc6b444c0c1c --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java index dba6cd180a7..30c0430e7ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java @@ -20,6 +20,7 @@ package org.sonar.server.rule.ws; import com.google.common.collect.Maps; +import org.apache.commons.lang.StringEscapeUtils; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.server.debt.DebtCharacteristic; @@ -36,7 +37,6 @@ import org.sonar.server.text.MacroInterpreter; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.Collection; import java.util.Map; @@ -81,14 +81,18 @@ public class RuleMapping extends BaseMapping { map("htmlDesc", new Mapper() { @Override public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { - if (rule.markdownDescription() != null) { - json.prop("htmlDesc", macroInterpreter.interpret(Markdown.convertToHtml(rule.markdownDescription()))); - } else { - json.prop("htmlDesc", macroInterpreter.interpret(rule.htmlDescription())); + String html = rule.htmlDescription(); + if (html != null) { + if (rule.isManual() || rule.templateKey() != null) { + String desc = StringEscapeUtils.escapeHtml(html); + desc = desc.replaceAll("\\n", "
"); + json.prop("htmlDesc", desc); + } else { + json.prop("htmlDesc", macroInterpreter.interpret(html)); + } } } }); - map("mdDesc", RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field()); map("noteLogin", RuleNormalizer.RuleField.NOTE_LOGIN.field()); map("mdNote", RuleNormalizer.RuleField.NOTE.field()); map("htmlNote", new IndexMapper(RuleNormalizer.RuleField.NOTE.field()) { @@ -154,7 +158,8 @@ public class RuleMapping extends BaseMapping { json .beginObject() .prop("key", param.key()) - .prop("htmlDesc", param.description() == null ? null : Markdown.convertToHtml(param.description())) + .prop("desc", param.description()) + .prop("type", param.type().type()) .prop("defaultValue", param.defaultValue()) .endObject(); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_custom_rule.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_custom_rule.json index 2e3f3fa36ef..8ee000b5f6b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_custom_rule.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_custom_rule.json @@ -18,8 +18,9 @@ "params": [ { "key": "regex", - "htmlDesc": "Reg ex", - "defaultValue": "a.*" + "desc": "Reg ex", + "defaultValue": "a.*", + "type": "STRING" } ] } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_active_rules_params.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_active_rules_params.json index ec25f48afc4..03d35338f6c 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_active_rules_params.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_active_rules_params.json @@ -4,13 +4,15 @@ "params": [ { "key": "my_var", - "htmlDesc": "My small description", - "defaultValue": "some value" + "desc": "My small description", + "defaultValue": "some value", + "type": "string" }, { "key": "the_var", - "htmlDesc": "My small description", - "defaultValue": "other value" + "desc": "My small description", + "defaultValue": "other value", + "type": "integer" } ] } diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-quality-profile-activation.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-quality-profile-activation.hbs index d604642ce4e..560972b992b 100644 --- a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-quality-profile-activation.hbs +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-quality-profile-activation.hbs @@ -43,7 +43,15 @@ {{#eq type 'TEXT'}} {{else}} + {{#eq type 'BOOLEAN'}} + + {{else}} + {{/eq}} {{/eq}}
{{description}}
{{#if extra}}