Package net.sourceforge.pmd
Class RuleSetFactory
- java.lang.Object
-
- net.sourceforge.pmd.RuleSetFactory
-
public class RuleSetFactory extends Object
RuleSetFactory is responsible for creating RuleSet instances from XML content. By default Rules will be loaded using theRulePriority.LOW
priority, with Rule deprecation warnings off. By default, the ruleset compatibility filter is active, too. SeeRuleSetFactoryCompatibility
.
-
-
Constructor Summary
Constructors Constructor Description RuleSetFactory()
Deprecated.RuleSetFactory(ClassLoader classLoader, RulePriority minimumPriority, boolean warnDeprecated, boolean enableCompatibility)
RuleSetFactory(RuleSetFactory factory, boolean warnDeprecated)
Constructor copying all configuration from another factory.RuleSetFactory(ResourceLoader resourceLoader, RulePriority minimumPriority, boolean warnDeprecated, boolean enableCompatibility)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RuleSet
createNewRuleSet(String name, String description, String fileName, Collection<String> excludePatterns, Collection<String> includePatterns, Collection<Rule> rules)
Creates a new ruleset with the given metadata such as name, description, fileName, exclude/include patterns are used.RuleSet
createRuleSet(String referenceString)
Create a RuleSet from a RuleSet reference ID string.RuleSet
createRuleSet(RuleSetReferenceId ruleSetReferenceId)
Create a RuleSet from a RuleSetReferenceId.RuleSet
createRuleSetCopy(RuleSet original)
Creates a copy of the given ruleset.RuleSets
createRuleSets(String referenceString)
Create a RuleSets from a comma separated list of RuleSet reference IDs.RuleSets
createRuleSets(List<RuleSetReferenceId> ruleSetReferenceIds)
Create a RuleSets from a list of RuleSetReferenceIds.RuleSet
createSingleRuleRuleSet(Rule rule)
Creates a new RuleSet containing a single rule.Iterator<RuleSet>
getRegisteredRuleSets()
Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each Language with Rule support.
-
-
-
Constructor Detail
-
RuleSetFactory
@Deprecated public RuleSetFactory()
Deprecated.
-
RuleSetFactory
@Deprecated public RuleSetFactory(ClassLoader classLoader, RulePriority minimumPriority, boolean warnDeprecated, boolean enableCompatibility)
-
RuleSetFactory
@Deprecated public RuleSetFactory(ResourceLoader resourceLoader, RulePriority minimumPriority, boolean warnDeprecated, boolean enableCompatibility)
-
RuleSetFactory
public RuleSetFactory(RuleSetFactory factory, boolean warnDeprecated)
Constructor copying all configuration from another factory.- Parameters:
factory
- The factory whose configuration to copy.warnDeprecated
- Whether deprecation warnings are to be produced by this factory.
-
-
Method Detail
-
getRegisteredRuleSets
public Iterator<RuleSet> getRegisteredRuleSets() throws RuleSetNotFoundException
Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each Language with Rule support.- Returns:
- An Iterator of RuleSet objects.
- Throws:
RuleSetNotFoundException
- if the ruleset file could not be found
-
createRuleSets
public RuleSets createRuleSets(String referenceString) throws RuleSetNotFoundException
Create a RuleSets from a comma separated list of RuleSet reference IDs. This is a convenience method which callsRuleSetReferenceId.parse(String)
, and then callscreateRuleSets(List)
. The currently configured ResourceLoader is used.- Parameters:
referenceString
- A comma separated list of RuleSet reference IDs.- Returns:
- The new RuleSets.
- Throws:
RuleSetNotFoundException
- if unable to find a resource.
-
createRuleSets
public RuleSets createRuleSets(List<RuleSetReferenceId> ruleSetReferenceIds) throws RuleSetNotFoundException
Create a RuleSets from a list of RuleSetReferenceIds. The currently configured ResourceLoader is used.- Parameters:
ruleSetReferenceIds
- The List of RuleSetReferenceId of the RuleSets to create.- Returns:
- The new RuleSets.
- Throws:
RuleSetNotFoundException
- if unable to find a resource.
-
createRuleSet
public RuleSet createRuleSet(String referenceString) throws RuleSetNotFoundException
Create a RuleSet from a RuleSet reference ID string. This is a convenience method which callsRuleSetReferenceId.parse(String)
, gets the first item in the List, and then callscreateRuleSet(RuleSetReferenceId)
. The currently configured ResourceLoader is used.- Parameters:
referenceString
- A comma separated list of RuleSet reference IDs.- Returns:
- A new RuleSet.
- Throws:
RuleSetNotFoundException
- if unable to find a resource.
-
createRuleSet
public RuleSet createRuleSet(RuleSetReferenceId ruleSetReferenceId) throws RuleSetNotFoundException
Create a RuleSet from a RuleSetReferenceId. Priority filtering is ignored when loading a single Rule. The currently configured ResourceLoader is used.- Parameters:
ruleSetReferenceId
- The RuleSetReferenceId of the RuleSet to create.- Returns:
- A new RuleSet.
- Throws:
RuleSetNotFoundException
- if unable to find a resource.
-
createRuleSetCopy
public RuleSet createRuleSetCopy(RuleSet original)
Creates a copy of the given ruleset. All properties like name, description, fileName and exclude/include patterns are copied.Note: The rule instances are shared between the original and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the original ruleset and the new ruleset are used in different threads.
- Parameters:
original
- the original rule set to copy from- Returns:
- the copy
-
createNewRuleSet
public RuleSet createNewRuleSet(String name, String description, String fileName, Collection<String> excludePatterns, Collection<String> includePatterns, Collection<Rule> rules)
Creates a new ruleset with the given metadata such as name, description, fileName, exclude/include patterns are used. The rules are taken from the given collection.Note: The rule instances are shared between the collection and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the rules of the collection are also referenced by other rulesets and used in different threads.
- Parameters:
name
- the name of the rulesetdescription
- the descriptionfileName
- the filenameexcludePatterns
- list of exclude patterns, if any is not a valid regular expression, it will be ignoredincludePatterns
- list of include patterns, if any is not a valid regular expression, it will be ignoredrules
- the collection with the rules to add to the new ruleset- Returns:
- the new ruleset
-
-