From 9d0db7ccf1b038e4b17729499cedda8b167b2770 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 29 Oct 2015 22:51:31 +0100 Subject: [PATCH] Complete javadoc of RulesDefinitionXmlLoader --- .../sonar/api/server/rule/RuleTagFormat.java | 5 +- .../server/rule/RulesDefinitionXmlLoader.java | 53 +++++++++++++++---- .../api/server/rule/RuleTagFormatTest.java | 1 + 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java index 3885bede912..89776d6050a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java @@ -22,12 +22,13 @@ package org.sonar.api.server.rule; import org.apache.commons.lang.StringUtils; /** + * The characters allowed in rule tags are the same as those on StackOverflow, basically lower-case + * letters, digits, plus (+), sharp (#), dash (-) and dot (.) + * See http://meta.stackoverflow.com/questions/22624/what-symbols-characters-are-not-allowed-in-tags * @since 4.2 */ public class RuleTagFormat { - // Allowed characters are the same as those on StackOverflow - // see http://meta.stackoverflow.com/questions/22624/what-symbols-characters-are-not-allowed-in-tags private static final String VALID_CHARACTERS_REGEX = "^[a-z0-9\\+#\\-\\.]+$"; private RuleTagFormat() { 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 20c85db7444..6e0bfeda433 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 @@ -40,39 +40,70 @@ import java.util.ArrayList; import java.util.List; /** - * Loads definitions of rules from a XML file. + * Helper class to load {@link RulesDefinition} extension point from a XML file. + * + *

Example

+ *
+ * public class MyRules implements RulesDefinition {
+ *
+ *   private final RulesDefinitionXmlLoader xmlLoader;
+ *
+ *   public MyRules(RulesDefinitionXmlLoader xmlLoader) {
+ *     this.xmlLoader = xmlLoader;
+ *   }
+ *
+ *   {@literal @}Override
+ *   public void define(Context context) {
+ *     NewRepository repository = context.createRepository("my-repo", "my-lang");
+ *     xmlLoader.load(repository, getClass().getResourceAsStream("/my-rules.xml"), StandardCharsets.UTF_8.name());
+ *     repository.done();
+ *   }
+ * }
+ * 
* *

XML Format

*
  * <rules>
  *   <rule>
- *     <!-- required fields -->
- *     <key>the-rule-key</key>
- *     <name>The purpose of the rule</name>
- *
- *     <!-- optional fields -->
- *     <description>
- *       <![CDATA[The description]]>
+ *     <key>the-required-rule-key</key>*
+ *     <name>The required purpose of the rule</name>
+ **     <description>
+ *       <![CDATA[Required HTML description]]>
  *     </description>
+ *
+ *     <!-- Optional key for configuration of some rule engines -->
  *     <internalKey>Checker/TreeWalker/LocalVariableName</internalKey>
+ *
+ *     <!-- Default severity when enabling the rule in a Quality profile.  -->
+ *     <!-- Possible values are INFO, MINOR, MAJOR (default), CRITICAL, BLOCKER. -->
  *     <severity>BLOCKER</severity>
- *     <cardinality>MULTIPLE</cardinality>
+ *
+ *     <!-- Possible values are SINGLE (default) and MULTIPLE for template rules -->
+ *     <cardinality>SINGLE</cardinality>
+ *
+ *     <!-- Status displayed in rules console. Possible values are BETA, READY (default), DEPRECATED. -->
  *     <status>BETA</status>
+ *
+ *     <!-- Optional tags. See org.sonar.api.server.rule.RuleTagFormat. -->
  *     <tag>style</tag>
  *     <tag>security</tag>
+ *
  *     <param>
  *       <key>the-param-key</key>
  *       <description>
- *         <![CDATA[the param-description]]>
+ *         <![CDATA[the optional param description]]>
  *       </description>
+ *       <!-- Optional field to define the default value used when enabling the rule in a Quality profile -->
  *       <defaultValue>42</defaultValue>
  *     </param>
  *     <param>
  *       <key>another-param</key>
  *     </param>
  *
- *     <!-- deprecated fields -->
+ *     <!-- Deprecated field, replaced by "internalKey" -->
  *     <configKey>Checker/TreeWalker/LocalVariableName</configKey>
+ *
+ *     <!-- Deprecated field, replaced by "severity" -->
  *     <priority>BLOCKER</priority>
  *   </rule>
  * </rules>
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
index 799df3a20c4..d42daa246cf 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
@@ -39,6 +39,7 @@ public class RuleTagFormatTest {
     assertThat(RuleTagFormat.isValid("c++")).isTrue();
     assertThat(RuleTagFormat.isValid("f#")).isTrue();
     assertThat(RuleTagFormat.isValid("c++11")).isTrue();
+    assertThat(RuleTagFormat.isValid("c.d")).isTrue();
   }
 
   @Test
-- 
2.39.5