]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5137 Add rule param type to WS response, use it in rule activation dialog
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 25 Jul 2014 09:32:42 +0000 (11:32 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 28 Jul 2014 08:45:32 +0000 (10:45 +0200)
Merged from branch-4.4 9646b5948e635505fdd66c48efffbc6b444c0c1c

server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_custom_rule.json
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_active_rules_params.json
server/sonar-web/src/main/hbs/coding-rules/coding-rules-quality-profile-activation.hbs

index dba6cd180a70a09ad7e62edd5d96cce63abe52e5..30c0430e7ec4b900061ef4b8b12494904208700f 100644 (file)
@@ -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<RuleDoc, RuleMappingContext> {
     map("htmlDesc", new Mapper<RuleDoc, RuleMappingContext>() {
       @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", "<br/>");
+            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<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.NOTE.field()) {
@@ -154,7 +158,8 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
           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();
         }
index 2e3f3fa36ef869c98932223f10acd0d6716fd1b6..8ee000b5f6b29e8afc068ba24a76401473f4f7c1 100644 (file)
@@ -18,8 +18,9 @@
     "params": [
       {
         "key": "regex",
-        "htmlDesc": "Reg ex",
-        "defaultValue": "a.*"
+        "desc": "Reg ex",
+        "defaultValue": "a.*",
+        "type": "STRING"
       }
     ]
   }
index ec25f48afc4cc665009f364eec50153d28e6d1cc..03d35338f6cf041e06e86d2d6bd6c1ee66e5e7dd 100644 (file)
@@ -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"
       }
     ]
   }
index d604642ce4ef15d0c26cca6c2000598697a8b506..560972b992b0454dfd1f17b35ea732692d28ce0e 100644 (file)
             {{#eq type 'TEXT'}}
               <textarea class="width100" rows="3" name="{{key}}" placeholder="{{defaultValue}}">{{value}}</textarea>
             {{else}}
+              {{#eq type 'BOOLEAN'}}
+              <select name="{{key}}" value="{{value}}">
+                <option value="{{defaultValue}}">{{t 'default'}}</option>
+                <option value="true"{{#eq value 'true'}} selected="selected"{{/eq}}>{{t 'true'}}</option>
+                <option value="false"{{#eq value 'false'}} selected="selected"{{/eq}}>{{t 'false'}}</option>
+              </select>
+              {{else}}
               <input type="text" name="{{key}}" value="{{value}}" placeholder="{{defaultValue}}">
+              {{/eq}}
             {{/eq}}
             <div class="note">{{description}}</div>
             {{#if extra}}