Provide a command line option for #1360 - "-noRuleSetCompatibility"

This commit is contained in:
Andreas Dangel
2016-05-18 20:38:44 +02:00
parent a8a18e6648
commit f32beeb726
6 changed files with 50 additions and 0 deletions

View File

@ -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;
@ -493,4 +496,27 @@ public class PMDConfiguration extends AbstractConfiguration {
public void setBenchmark(boolean benchmark) {
this.benchmark = benchmark;
}
/**
* 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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -78,6 +78,9 @@ public class PMDParameters {
@Parameter(names = "-auxclasspath", description = "Specifies the classpath for libraries used by the source code. This is used by the type resolution. Alternatively, a 'file://' URL to a text file containing path elements on consecutive lines can be specified.")
private String auxclasspath;
@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> {
@ -130,6 +133,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());

View File

@ -15,3 +15,8 @@
**Bugfixes:**
**API Changes:**
* 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>`.