Merge branch 'issue-1360-ruleset-compatibility'
This commit is contained in:
@ -54,6 +54,8 @@ import net.sourceforge.pmd.util.IOUtil;
|
||||
* <li>A comma separated list of input paths to process for source files.
|
||||
* This may include files, directories, archives (e.g. ZIP files), etc.
|
||||
* {@link #getInputPaths()}</li>
|
||||
* <li>A flag which controls, whether {@link RuleSetFactoryCompatibility} filter
|
||||
* should be used or not: #isRuleSetFactoryCompatibilityEnabled;
|
||||
* </ul>
|
||||
* <p>
|
||||
* <ul>
|
||||
@ -94,6 +96,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
private RulePriority minimumPriority = RulePriority.LOW;
|
||||
private String inputPaths;
|
||||
private String inputUri;
|
||||
private boolean ruleSetFactoryCompatibilityEnabled = true;
|
||||
|
||||
// Reporting options
|
||||
private String reportFormat;
|
||||
@ -512,4 +515,26 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
public void setFailOnViolation(boolean failOnViolation) {
|
||||
this.failOnViolation = failOnViolation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the rule set factory compatibility feature is enabled.
|
||||
*
|
||||
* @return true, if the rule set factory compatibility feature is enabled
|
||||
*
|
||||
* @see RuleSetFactoryCompatibility
|
||||
*/
|
||||
public boolean isRuleSetFactoryCompatibilityEnabled() {
|
||||
return ruleSetFactoryCompatibilityEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule set factory compatibility feature enabled/disabled.
|
||||
*
|
||||
* @param ruleSetFactoryCompatibilityEnabled <code>true</code> if the feature should be enabled
|
||||
*
|
||||
* @see RuleSetFactoryCompatibility
|
||||
*/
|
||||
public void setRuleSetFactoryCompatibilityEnabled(boolean ruleSetFactoryCompatibilityEnabled) {
|
||||
this.ruleSetFactoryCompatibilityEnabled = ruleSetFactoryCompatibilityEnabled;
|
||||
}
|
||||
}
|
@ -67,6 +67,9 @@ public final class RulesetsFactoryUtils {
|
||||
public static RuleSetFactory getRulesetFactory(PMDConfiguration configuration) {
|
||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||
ruleSetFactory.setMinimumPriority(configuration.getMinimumPriority());
|
||||
if (!configuration.isRuleSetFactoryCompatibilityEnabled()) {
|
||||
ruleSetFactory.disableCompatibilityFilter();
|
||||
}
|
||||
return ruleSetFactory;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class PMDTask extends Task {
|
||||
private boolean shortFilenames;
|
||||
private String suppressMarker;
|
||||
private String rulesetFiles;
|
||||
private boolean noRuleSetCompatibility;
|
||||
private String encoding;
|
||||
private int threads;
|
||||
private int minimumPriority;
|
||||
@ -236,4 +237,11 @@ public class PMDTask extends Task {
|
||||
return nestedRules;
|
||||
}
|
||||
|
||||
public boolean isNoRuleSetCompatibility() {
|
||||
return noRuleSetCompatibility;
|
||||
}
|
||||
|
||||
public void setNoRuleSetCompatibility(boolean noRuleSetCompatibility) {
|
||||
this.noRuleSetCompatibility = noRuleSetCompatibility;
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class PMDTaskImpl {
|
||||
this.failOnRuleViolation = true;
|
||||
}
|
||||
configuration.setRuleSets(task.getRulesetFiles());
|
||||
configuration.setRuleSetFactoryCompatibilityEnabled(!task.isNoRuleSetCompatibility());
|
||||
if (task.getEncoding() != null) {
|
||||
configuration.setSourceEncoding(task.getEncoding());
|
||||
}
|
||||
@ -100,6 +101,9 @@ public class PMDTaskImpl {
|
||||
// Setup RuleSetFactory and validate RuleSets
|
||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||
ruleSetFactory.setClassLoader(configuration.getClassLoader());
|
||||
if (!configuration.isRuleSetFactoryCompatibilityEnabled()) {
|
||||
ruleSetFactory.disableCompatibilityFilter();
|
||||
}
|
||||
try {
|
||||
// This is just used to validate and display rules. Each thread will
|
||||
// create its own ruleset
|
||||
|
@ -81,6 +81,9 @@ public class PMDParameters {
|
||||
@Parameter(names = {"-failOnViolation", "--failOnViolation"}, arity = 1, description = "By default PMD exits with status 4 if violations are found. Disable this option with '-failOnViolation false' to exit with 0 instead and just write the report.")
|
||||
private boolean failOnViolation = true;
|
||||
|
||||
@Parameter(names = "-norulesetcompatibility", description = "Disable the ruleset compatibility filter. The filter is active by default and tries automatically 'fix' old ruleset files with old rule names")
|
||||
private boolean noRuleSetCompatibility = false;
|
||||
|
||||
// this has to be a public static class, so that JCommander can use it!
|
||||
public static class PropertyConverter implements IStringConverter<Properties> {
|
||||
|
||||
@ -133,6 +136,7 @@ public class PMDParameters {
|
||||
configuration.setReportProperties(params.getProperties());
|
||||
configuration.setReportShortNames(params.isShortnames());
|
||||
configuration.setRuleSets(params.getRulesets());
|
||||
configuration.setRuleSetFactoryCompatibilityEnabled(!params.noRuleSetCompatibility);
|
||||
configuration.setShowSuppressedViolations(params.isShowsuppressed());
|
||||
configuration.setSourceEncoding(params.getEncoding());
|
||||
configuration.setStressTest(params.isStress());
|
||||
|
@ -135,3 +135,7 @@ you'll need a java8 runtime environment.
|
||||
* CPD: If a complete filename is specified, the language dependent filename filter is not applied. This allows
|
||||
to scan files, that are not using the standard file extension. If a directory is specified, the filename filter
|
||||
is still applied and only those files with the correct file extension of the language are scanned.
|
||||
* New command line parameter for PMD: `-norulesetcompatibility` - this disables the ruleset factory
|
||||
compatibility filter and fails, if e.g. an old rule name is used in the ruleset.
|
||||
See also [#1360](https://sourceforge.net/p/pmd/bugs/1360/).
|
||||
This option is also available for the ant task: `<noRuleSetCompatibility>true</noRuleSetCompatibility>`.
|
||||
|
Reference in New Issue
Block a user