Package net.sourceforge.pmd.lang.rule
Class RuleSetLoader
java.lang.Object
net.sourceforge.pmd.lang.rule.RuleSetLoader
Configurable object to load rulesets from XML resources.
This can be configured using a fluent API, see eg
warnDeprecated(boolean).
To create a new ruleset, use loadFromResource(String)
or some such overload.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfilterAbovePriority(RulePriority minimumPriority) Filter loaded rules to only those that match or are above the given priority.static RuleSetLoaderfromPmdConfig(PMDConfiguration configuration) Configure a new ruleset factory builder according to the parameters of the given PMD configuration.Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each language.includeDeprecatedRuleReferences(boolean enable) Follow deprecated rule references.loadFromResource(String rulesetPath) Parses and returns a ruleset from its location.loadFromResources(String first, String... rest) Parses several resources into a list of rulesets.loadFromResources(Collection<String> paths) Parses several resources into a list of rulesets.loadFromString(String filename, String rulesetXmlContent) Parses and returns a ruleset from string content.loadResourcesWith(ClassLoader classLoader) Specify that the given classloader should be used to resolve paths to external ruleset references.warnDeprecated(boolean warn) Log a warning when referencing a deprecated rule.withLanguages(LanguageRegistry languageRegistry)
-
Constructor Details
-
RuleSetLoader
public RuleSetLoader()Create a new RuleSetLoader with a default configuration. The defaults are described on each configuration method of this class.
-
-
Method Details
-
loadResourcesWith
Specify that the given classloader should be used to resolve paths to external ruleset references. The default uses PMD's own classpath. -
withLanguages
-
filterAbovePriority
Filter loaded rules to only those that match or are above the given priority. The default isRulePriority.LOW, ie, no filtering occurs.- Returns:
- This instance, modified
-
warnDeprecated
Log a warning when referencing a deprecated rule. This is enabled by default.- Returns:
- This instance, modified
-
includeDeprecatedRuleReferences
Follow deprecated rule references. By default this is off, and those references will be ignored.- Returns:
- This instance, modified
-
loadFromResource
Parses and returns a ruleset from its location. The location may be a file system path, or a resource path (seeloadResourcesWith(ClassLoader)).- Parameters:
rulesetPath- A reference to a single ruleset- Throws:
RuleSetLoadException- If any error occurs (eg, invalid syntax, or resource not found)
-
loadFromString
Parses and returns a ruleset from string content.- Parameters:
filename- The symbolic "file name", for error messages.rulesetXmlContent- Xml file contents- Throws:
RuleSetLoadException- If any error occurs (eg, invalid syntax)
-
loadFromResources
Parses several resources into a list of rulesets.- Parameters:
paths- Paths- Throws:
RuleSetLoadException- If any error occurs (eg, invalid syntax, or resource not found), for any of the parametersNullPointerException- If the parameter, or any component is null
-
loadFromResources
Parses several resources into a list of rulesets.- Parameters:
first- First pathrest- Paths- Throws:
RuleSetLoadException- If any error occurs (eg, invalid syntax, or resource not found), for any of the parametersNullPointerException- If the parameter, or any component is null
-
fromPmdConfig
Configure a new ruleset factory builder according to the parameters of the given PMD configuration. -
getStandardRuleSets
Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each language. This uses the classpath of the resource loader (loadResourcesWith(ClassLoader)).- Returns:
- A list of all category rulesets
- Throws:
RuleSetLoadException- If a standard ruleset cannot be loaded. This is a corner case, that probably should not be caught by clients. The standard rulesets are well-formed, at least in stock PMD distributions.
-