Package net.sourceforge.pmd
Class RuleSetLoader
- java.lang.Object
-
- net.sourceforge.pmd.RuleSetLoader
-
public final class RuleSetLoader extends Object
Configurable object to load rulesets from XML resources. This can be configured using a fluent API, see egwarnDeprecated(boolean). To create a new ruleset, useloadFromResource(String)or some such overload.
-
-
Constructor Summary
Constructors Constructor Description RuleSetLoader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RuleSetLoaderenableCompatibility(boolean enable)Enable translating old rule references to newer ones, if they have been moved or renamed.RuleSetLoaderfilterAbovePriority(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.List<RuleSet>getStandardRuleSets()Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each language.RuleSetLoaderincludeDeprecatedRuleReferences(boolean enable)Follow deprecated rule references.RuleSetloadFromResource(String rulesetPath)Parses and returns a ruleset from its location.List<RuleSet>loadFromResources(String first, String... rest)Parses several resources into a list of rulesets.List<RuleSet>loadFromResources(Collection<String> paths)Parses several resources into a list of rulesets.RuleSetLoaderloadResourcesWith(ClassLoader classLoader)Specify that the given classloader should be used to resolve paths to external ruleset references.RuleSetFactorytoFactory()Deprecated.RuleSetFactoryis deprecated, replace its usages with usages of this class, or of static factory methods ofRuleSetRuleSetLoaderwarnDeprecated(boolean warn)Log a warning when referencing a deprecated rule.
-
-
-
Method Detail
-
loadResourcesWith
public RuleSetLoader loadResourcesWith(ClassLoader classLoader)
Specify that the given classloader should be used to resolve paths to external ruleset references. The default uses PMD's own classpath.
-
filterAbovePriority
public RuleSetLoader filterAbovePriority(RulePriority minimumPriority)
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
public RuleSetLoader warnDeprecated(boolean warn)
Log a warning when referencing a deprecated rule. This is enabled by default.- Returns:
- This instance, modified
-
enableCompatibility
public RuleSetLoader enableCompatibility(boolean enable)
Enable translating old rule references to newer ones, if they have been moved or renamed. This is enabled by default, if disabled, unresolved references will not be translated and will produce an error.- Returns:
- This instance, modified
-
includeDeprecatedRuleReferences
public RuleSetLoader includeDeprecatedRuleReferences(boolean enable)
Follow deprecated rule references. By default this is off, and those references will be ignored (with a warning depending onenableCompatibility(boolean)).- Returns:
- This instance, modified
-
toFactory
@Deprecated public RuleSetFactory toFactory()
Deprecated.RuleSetFactoryis deprecated, replace its usages with usages of this class, or of static factory methods ofRuleSetCreate a new rule set factory, if you have to (that class is deprecated). That factory will use the configuration that was set using the setters of this.
-
loadFromResource
public RuleSet loadFromResource(String rulesetPath)
Parses and returns a ruleset from its location. The location may be a file system path, or a resource path (seeloadResourcesWith(ClassLoader)).This replaces
RuleSetFactory.createRuleSet(String), but does not split commas.- Parameters:
rulesetPath- A reference to a single ruleset- Throws:
RuleSetLoadException- If any error occurs (eg, invalid syntax, or resource not found)
-
loadFromResources
public List<RuleSet> loadFromResources(Collection<String> paths)
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
public List<RuleSet> loadFromResources(String first, String... rest)
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
public static RuleSetLoader fromPmdConfig(PMDConfiguration configuration)
Configure a new ruleset factory builder according to the parameters of the given PMD configuration.
-
getStandardRuleSets
public List<RuleSet> 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.
-
-