From faa74b33eb99d62ad8c6ee760a9367ec62b8dc00 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 3 Dec 2015 18:37:23 +0100 Subject: SONAR-7049 check max length of rule/rule param fields --- .../org/sonar/api/server/rule/RulesDefinition.java | 18 ++++++++++++++++-- .../api/server/rule/RulesDefinitionXmlLoader.java | 7 ++++--- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'sonar-plugin-api') diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index e9c878c0218..15e96c7189c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -426,6 +426,9 @@ public interface RulesDefinition { } interface NewExtendedRepository { + /** + * Create a rule with specified key. Max length of key is 200 characters. + */ NewRule createRule(String ruleKey); @CheckForNull @@ -692,6 +695,10 @@ public interface RulesDefinition { return this; } + /** + * The optional description, in HTML format, has no max length. It's exclusive with markdown description + * (see {@link #setMarkdownDescription(String)}) + */ public NewRule setHtmlDescription(@Nullable String s) { if (markdownDescription != null) { throw new IllegalStateException(String.format("Rule '%s' already has a Markdown description", this)); @@ -716,6 +723,10 @@ public interface RulesDefinition { return this; } + /** + * The optional description, in a restricted Markdown format, has no max length. It's exclusive with HTML description + * (see {@link #setHtmlDescription(String)}) + */ public NewRule setMarkdownDescription(@Nullable String s) { if (htmlDescription != null) { throw new IllegalStateException(String.format("Rule '%s' already has an HTML description", this)); @@ -792,6 +803,9 @@ public interface RulesDefinition { return this; } + /** + * Create a parameter with given unique key. Max length of key is 128 characters. + */ public NewParam createParam(String paramKey) { if (paramsByKey.containsKey(paramKey)) { throw new IllegalArgumentException(String.format("The parameter '%s' is declared several times on the rule %s", paramKey, this)); @@ -1020,7 +1034,7 @@ public interface RulesDefinition { } /** - * Plain-text description. Can be null. + * Plain-text description. Can be null. Max length is 4000 characters. */ public NewParam setDescription(@Nullable String s) { this.description = StringUtils.defaultIfBlank(s, null); @@ -1028,7 +1042,7 @@ public interface RulesDefinition { } /** - * Empty default value will be converted to null. + * Empty default value will be converted to null. Max length is 4000 characters. */ public NewParam setDefaultValue(@Nullable String s) { this.defaultValue = Strings.emptyToNull(s); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java index 8a8096e4ebf..f088221b883 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java @@ -74,10 +74,10 @@ import static org.apache.commons.lang.StringUtils.trim; *
  * <rules>
  *   <rule>
- *     <!-- required key -->
+ *     <!-- required key. Max length is 200. -->
  *     <key>the-rule-key</key>
  *
- *     <!-- required name -->
+ *     <!-- required name. Max length is 200. -->
  *     <name>The purpose of the rule</name>
  *
  *     <!-- required description, in HTML format -->
@@ -98,11 +98,12 @@ import static org.apache.commons.lang.StringUtils.trim;
  *     <!-- Status displayed in rules console. Possible values are BETA, READY (default), DEPRECATED. -->
  *     <status>BETA</status>
  *
- *     <!-- Optional tags. See org.sonar.api.server.rule.RuleTagFormat. -->
+ *     <!-- Optional tags. See org.sonar.api.server.rule.RuleTagFormat. The maximal length of all tags is 4000. -->
  *     <tag>style</tag>
  *     <tag>security</tag>
  *
  *     <param>
+ *       <!-- Status displayed in rules console. Possible values are BETA, READY (default), DEPRECATED. -->
  *       <key>the-param-key</key>
  *       <description>
  *         <![CDATA[the optional description, in HTML format]]>
-- 
cgit v1.2.3