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() {
import java.util.List;
/**
- * Loads definitions of rules from a XML file.
+ * Helper class to load {@link RulesDefinition} extension point from a XML file.
+ *
+ * <h3>Example</h3>
+ * <pre>
+ * 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();
+ * }
+ * }
+ * </pre>
*
* <h3>XML Format</h3>
* <pre>
* <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>