Merge pull request #4795 from adangel:remove-ruleset-factory-compatibility

[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option --no-ruleset-compatibility #4795
This commit is contained in:
Andreas Dangel 2024-02-02 19:53:51 +01:00
commit a76ec3410c
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
19 changed files with 1118 additions and 184 deletions

View File

@ -203,6 +203,7 @@ Most notable changes:
an error message such as `[main] ERROR net.sourceforge.pmd.cli.commands.internal.PmdCommand - No such file false`.
* PMD tries to display a progress bar. If you don't want this (e.g. on a CI build server), you can disable this
with `--no-progress`.
* `--no-ruleset-compatibility` has been removed
### Custom distribution packages

View File

@ -106,6 +106,8 @@ in the Migration Guide.
* core
* [#1027](https://github.com/pmd/pmd/issues/1027): \[core] Apply the new PropertyDescriptor<Pattern> type where applicable
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
* [#4378](https://github.com/pmd/pmd/issues/4378): \[core] Ruleset loading processes commented rules
* [#4674](https://github.com/pmd/pmd/issues/4674): \[core] WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass
* [#4694](https://github.com/pmd/pmd/pull/4694): \[core] Fix line/col numbers in TokenMgrError
* [#4717](https://github.com/pmd/pmd/issues/4717): \[core] XSLTRenderer doesn't close report file
@ -207,6 +209,15 @@ The following previously deprecated classes have been removed:
* The node `ASTClassOrInterfaceBody` has been renamed to {% jdoc java::lang.ast.ASTClassBody %}. XPath rules
need to be adjusted.
**Removed functionality**
* The CLI parameter `--no-ruleset-compatibility` has been removed. It was only used to allow loading
some rulesets originally written for PMD 5 also in PMD 6 without fixing the rulesets.
* The class {% jdoc_old core::RuleSetFactoryCompatibility %} has been removed without replacement.
The different ways to enable/disable this filter in {% jdoc core::PMDConfiguration %}
(Property "RuleSetFactoryCompatibilityEnabled") and
{% jdoc ant::ant.PMDTask %} (Property "noRuleSetCompatibility") have been removed as well.
#### External Contributions
* [#4640](https://github.com/pmd/pmd/pull/4640): \[cli] Launch script fails if run via "bash pmd" - [Shai Bennathan](https://github.com/shai-bennathan) (@shai-bennathan)
* [#4673](https://github.com/pmd/pmd/pull/4673): \[javascript] CPD: Added support for decorator notation - [Wener](https://github.com/wener-tiobe) (@wener-tiobe)
@ -615,10 +626,12 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4301](https://github.com/pmd/pmd/issues/4301): \[core] Remove deprecated property concrete classes
* [#4302](https://github.com/pmd/pmd/issues/4302): \[core] Migrate Property Framework API to Java 8
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
* [#4323](https://github.com/pmd/pmd/issues/4323): \[core] Refactor CPD integration
* [#4353](https://github.com/pmd/pmd/pull/4353): \[core] Micro optimizations for Node API
* [#4365](https://github.com/pmd/pmd/pull/4365): \[core] Improve benchmarking
* [#4397](https://github.com/pmd/pmd/pull/4397): \[core] Refactor CPD
* [#4378](https://github.com/pmd/pmd/issues/4378): \[core] Ruleset loading processes commented rules
* [#4420](https://github.com/pmd/pmd/pull/4420): \[core] Remove PMD.EOL
* [#4425](https://github.com/pmd/pmd/pull/4425): \[core] Replace TextFile::pathId
* [#4454](https://github.com/pmd/pmd/issues/4454): \[core] "Unknown option: '-min'" but is referenced in documentation

View File

@ -61,7 +61,6 @@ public class PMDTask extends Task {
private final List<Path> relativizePathsWith = new ArrayList<>();
private String suppressMarker;
private String rulesetFiles;
private boolean noRuleSetCompatibility;
private String encoding;
private int threads = 1; // same default as in PMDParameters (CLI)
private int minimumPriority = RulePriority.LOW.getPriority(); // inclusive
@ -267,14 +266,6 @@ public class PMDTask extends Task {
return nestedRules;
}
public boolean isNoRuleSetCompatibility() {
return noRuleSetCompatibility;
}
public void setNoRuleSetCompatibility(boolean noRuleSetCompatibility) {
this.noRuleSetCompatibility = noRuleSetCompatibility;
}
public String getCacheLocation() {
return cacheLocation;
}

View File

@ -68,7 +68,6 @@ public class PMDTaskImpl {
configuration.setRuleSets(Arrays.asList(task.getRulesetFiles().split(",")));
}
configuration.setRuleSetFactoryCompatibilityEnabled(!task.isNoRuleSetCompatibility());
if (task.getEncoding() != null) {
configuration.setSourceEncoding(Charset.forName(task.getEncoding()));
}

View File

@ -39,6 +39,6 @@ class DefaultRulesetTest {
}
private RuleSetLoader rulesetLoader() {
return new RuleSetLoader().enableCompatibility(false);
return new RuleSetLoader();
}
}

View File

@ -102,8 +102,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
private String auxClasspath;
private boolean noRuleSetCompatibility;
private Path cacheLocation;
private boolean noCache;
@ -213,12 +211,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
this.auxClasspath = auxClasspath;
}
@Option(names = "--no-ruleset-compatibility",
description = "Disable the ruleset compatibility filter. The filter is active by default and tries automatically 'fix' old ruleset files with old rule names")
public void setNoRuleSetCompatibility(final boolean noRuleSetCompatibility) {
this.noRuleSetCompatibility = noRuleSetCompatibility;
}
@Option(names = "--cache",
description = "Specify the location of the cache file for incremental analysis. "
+ "This should be the full path to the file, including the desired file name (not just the parent directory). "
@ -274,7 +266,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
configuration.addRelativizeRoots(relativizeRootPaths);
}
configuration.setRuleSets(rulesets);
configuration.setRuleSetFactoryCompatibilityEnabled(!this.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(showSuppressed);
configuration.setSuppressMarker(suppressMarker);
configuration.setThreads(threads);

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,9 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
// This class has been taken from 7.0.0-SNAPSHOT
// Before removing RuleSetFactoryCompatibility (#4314)
package net.sourceforge.pmd;
import java.text.MessageFormat;

File diff suppressed because it is too large Load Diff

View File

@ -44,9 +44,6 @@ import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
* These can be file paths or classpath resources.</li>
* <li>Use {@link #setMinimumPriority(RulePriority)} to control the minimum priority a
* rule must have to be included. Defaults to the lowest priority, ie all rules are loaded.</li>
* <li>Use {@link #setRuleSetFactoryCompatibilityEnabled(boolean)} to disable the
* compatibility measures for removed and renamed rules in the rulesets that will
* be loaded.
* </ul>
*
* <h3>Source files</h3>
@ -106,7 +103,6 @@ public class PMDConfiguration extends AbstractConfiguration {
// Rule and source file options
private List<String> ruleSets = new ArrayList<>();
private RulePriority minimumPriority = RulePriority.LOW;
private boolean ruleSetFactoryCompatibilityEnabled = true;
// Reporting options
private String reportFormat;
@ -449,28 +445,6 @@ public class PMDConfiguration extends AbstractConfiguration {
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 RuleSetLoader#enableCompatibility(boolean)
*/
public boolean isRuleSetFactoryCompatibilityEnabled() {
return ruleSetFactoryCompatibilityEnabled;
}
/**
* Sets the rule set factory compatibility feature enabled/disabled.
*
* @param ruleSetFactoryCompatibilityEnabled {@code true} if the feature should be enabled
*
* @see RuleSetLoader#enableCompatibility(boolean)
*/
public void setRuleSetFactoryCompatibilityEnabled(boolean ruleSetFactoryCompatibilityEnabled) {
this.ruleSetFactoryCompatibilityEnabled = ruleSetFactoryCompatibilityEnabled;
}
/**
* Retrieves the currently used analysis cache. Will never be null.
*

View File

@ -80,7 +80,6 @@ final class RuleSetFactory {
private final LanguageRegistry languageRegistry;
private final RulePriority minimumPriority;
private final boolean warnDeprecated;
private final RuleSetFactoryCompatibility compatibilityFilter;
private final MessageReporter reporter;
private final boolean includeDeprecatedRuleReferences;
@ -90,7 +89,6 @@ final class RuleSetFactory {
LanguageRegistry languageRegistry,
RulePriority minimumPriority,
boolean warnDeprecated,
RuleSetFactoryCompatibility compatFilter,
boolean includeDeprecatedRuleReferences,
MessageReporter reporter) {
this.resourceLoader = resourceLoader;
@ -99,7 +97,6 @@ final class RuleSetFactory {
this.warnDeprecated = warnDeprecated;
this.includeDeprecatedRuleReferences = includeDeprecatedRuleReferences;
this.compatibilityFilter = compatFilter;
this.reporter = reporter;
}
@ -374,7 +371,6 @@ final class RuleSetFactory {
// has been reported
continue;
}
excludedRuleName = compatibilityFilter.applyExclude(ref, excludedRuleName, this.warnDeprecated);
if (excludedRuleName != null) {
excludedRulesCheck.put(excludedRuleName, child);
}
@ -441,7 +437,6 @@ final class RuleSetFactory {
private RuleSetReferenceId parseReferenceAndWarn(String ref,
Node xmlPlace,
PmdXmlReporter err) {
ref = compatibilityFilter.applyRef(ref, this.warnDeprecated);
if (ref == null) {
err.at(xmlPlace).warn("Rule reference references a deleted rule, ignoring");
return null; // deleted rule
@ -662,7 +657,6 @@ final class RuleSetFactory {
return new RuleSetLoader().loadResourcesWith(resourceLoader)
.filterAbovePriority(minimumPriority)
.warnDeprecated(warnDeprecated)
.enableCompatibility(compatibilityFilter != null)
.includeDeprecatedRuleReferences(includeDeprecatedRuleReferences);
}

View File

@ -40,7 +40,6 @@ public final class RuleSetLoader {
private ResourceLoader resourceLoader = new ResourceLoader(RuleSetLoader.class.getClassLoader());
private RulePriority minimumPriority = RulePriority.LOW;
private boolean warnDeprecated = true;
private @NonNull RuleSetFactoryCompatibility compatFilter = RuleSetFactoryCompatibility.DEFAULT;
private boolean includeDeprecatedRuleReferences = false;
private @NonNull MessageReporter reporter = MessageReporter.quiet();
@ -101,29 +100,9 @@ public final class RuleSetLoader {
return this;
}
/**
* 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.
*
* @return This instance, modified
*/
public RuleSetLoader enableCompatibility(boolean enable) {
return setCompatibility(enable ? RuleSetFactoryCompatibility.DEFAULT
: RuleSetFactoryCompatibility.EMPTY);
}
// test only
RuleSetLoader setCompatibility(@NonNull RuleSetFactoryCompatibility filter) {
this.compatFilter = filter;
return this;
}
/**
* Follow deprecated rule references. By default this is off,
* and those references will be ignored (with a warning depending
* on {@link #enableCompatibility(boolean)}).
* and those references will be ignored.
*
* @return This instance, modified
*/
@ -146,7 +125,6 @@ public final class RuleSetLoader {
this.languageRegistry,
this.minimumPriority,
this.warnDeprecated,
this.compatFilter,
this.includeDeprecatedRuleReferences,
this.reporter
);
@ -286,7 +264,6 @@ public final class RuleSetLoader {
*/
public static RuleSetLoader fromPmdConfig(PMDConfiguration configuration) {
return new RuleSetLoader().filterAbovePriority(configuration.getMinimumPriority())
.enableCompatibility(configuration.isRuleSetFactoryCompatibilityEnabled())
.withLanguages(configuration.getLanguageRegistry())
.withReporter(configuration.getReporter());
}

View File

@ -12,7 +12,9 @@ This ruleset contains links to rules that are new in PMD v3.4
<rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
<rule ref="rulesets/java/design.xml/NonThreadSafeSingleton"/>
<!-- removed with 5.4.0, renamed to UncommentedEmptyMethodBody
<rule ref="rulesets/java/design.xml/UncommentedEmptyMethod"/>
-->
<rule ref="rulesets/java/design.xml/UncommentedEmptyConstructor"/>
<!-- <rule ref="rulesets/java/controversial.xml/DefaultPackage"/>-->

View File

@ -20,7 +20,9 @@ This ruleset contains links to rules that are new in PMD v3.5
<!-- <rule ref="rulesets/java/junit.xml/UseAssertNullInsteadOfAssertTrue"/>-->
<!-- removed with 5.6.0:
<rule ref="rulesets/java/design.xml/AvoidConstantsInterface"/>
-->
<rule ref="rulesets/java/optimizations.xml/UseArraysAsList"/>
<rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops"/>

View File

@ -1,103 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
class RuleSetFactoryCompatibilityTest {
@Test
void testCorrectOldReference() throws Exception {
final String ruleset = "<?xml version=\"1.0\"?>\n" + "\n" + "<ruleset name=\"Test\"\n"
+ " xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd\">\n"
+ " <description>Test</description>\n" + "\n"
+ " <rule ref=\"rulesets/dummy/notexisting.xml/DummyBasicMockRule\" />\n" + "</ruleset>\n";
RuleSetFactoryCompatibility compat = new RuleSetFactoryCompatibility();
compat.addFilterRuleMoved("dummy", "notexisting", "basic", "DummyBasicMockRule");
RuleSetLoader rulesetLoader = new RuleSetLoader().setCompatibility(compat);
RuleSet createdRuleSet = rulesetLoader.loadFromString("dummy.xml", ruleset);
assertNotNull(createdRuleSet.getRuleByName("DummyBasicMockRule"));
}
@Test
void testCorrectMovedAndRename() {
RuleSetFactoryCompatibility rsfc = new RuleSetFactoryCompatibility();
rsfc.addFilterRuleMoved("dummy", "notexisting", "basic", "OldDummyBasicMockRule");
rsfc.addFilterRuleRenamed("dummy", "basic", "OldDummyBasicMockRule", "NewNameForDummyBasicMockRule");
String out = rsfc.applyRef("rulesets/dummy/notexisting.xml/OldDummyBasicMockRule");
assertEquals("rulesets/dummy/basic.xml/NewNameForDummyBasicMockRule", out);
}
@Test
void testExclusion() {
final String ruleset = "<?xml version=\"1.0\"?>\n" + "\n" + "<ruleset name=\"Test\"\n"
+ " xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd\">\n"
+ " <description>Test</description>\n" + "\n" + " <rule ref=\"rulesets/dummy/basic.xml\">\n"
+ " <exclude name=\"OldNameOfSampleXPathRule\"/>\n" + " </rule>\n" + "</ruleset>\n";
RuleSetFactoryCompatibility compat = new RuleSetFactoryCompatibility();
compat.addFilterRuleRenamed("dummy", "basic", "OldNameOfSampleXPathRule", "SampleXPathRule");
RuleSetLoader rulesetLoader = new RuleSetLoader().setCompatibility(compat);
RuleSet createdRuleSet = rulesetLoader.loadFromString("dummy.xml", ruleset);
assertNotNull(createdRuleSet.getRuleByName("DummyBasicMockRule"));
assertNull(createdRuleSet.getRuleByName("SampleXPathRule"));
}
@Test
void testExclusionRenamedAndMoved() {
RuleSetFactoryCompatibility rsfc = new RuleSetFactoryCompatibility();
rsfc.addFilterRuleMovedAndRenamed("dummy", "oldbasic", "OldDummyBasicMockRule", "basic", "NewNameForDummyBasicMockRule");
String in = "rulesets/dummy/oldbasic.xml";
String out = rsfc.applyRef(in);
assertEquals(in, out);
}
@Test
void testFilter() {
RuleSetFactoryCompatibility rsfc = new RuleSetFactoryCompatibility();
rsfc.addFilterRuleMoved("dummy", "notexisting", "basic", "DummyBasicMockRule");
rsfc.addFilterRuleRemoved("dummy", "basic", "DeletedRule");
rsfc.addFilterRuleRenamed("dummy", "basic", "OldNameOfBasicMockRule", "NewNameOfBasicMockRule");
assertEquals("rulesets/dummy/basic.xml/DummyBasicMockRule",
rsfc.applyRef("rulesets/dummy/notexisting.xml/DummyBasicMockRule"));
assertEquals("rulesets/dummy/basic.xml/NewNameOfBasicMockRule",
rsfc.applyRef("rulesets/dummy/basic.xml/OldNameOfBasicMockRule"));
assertNull(rsfc.applyRef("rulesets/dummy/basic.xml/DeletedRule"));
}
@Test
void testExclusionFilter() {
RuleSetFactoryCompatibility rsfc = new RuleSetFactoryCompatibility();
rsfc.addFilterRuleRenamed("dummy", "basic", "AnotherOldNameOfBasicMockRule", "NewNameOfBasicMockRule");
String out = rsfc.applyExclude("rulesets/dummy/basic.xml", "AnotherOldNameOfBasicMockRule", false);
assertEquals("NewNameOfBasicMockRule", out);
}
}

View File

@ -525,7 +525,7 @@ class RuleSetFactoryTest extends RulesetFactoryTestBase {
@Test
void testReferencePriority() {
RuleSetLoader config = new RuleSetLoader().warnDeprecated(false).enableCompatibility(true);
RuleSetLoader config = new RuleSetLoader().warnDeprecated(false);
RuleSetLoader rulesetLoader = config.filterAbovePriority(RulePriority.LOW);
RuleSet ruleSet = rulesetLoader.loadFromString("ruleset.xml", REF_INTERNAL_TO_INTERNAL_CHAIN);
@ -567,7 +567,7 @@ class RuleSetFactoryTest extends RulesetFactoryTestBase {
@Test
void testOverridePriorityLoadWithMinimum() {
RuleSetLoader rulesetLoader = new RuleSetLoader().filterAbovePriority(RulePriority.MEDIUM_LOW)
.warnDeprecated(true).enableCompatibility(true);
.warnDeprecated(true);
RuleSet ruleset = rulesetLoader.loadFromResource("net/sourceforge/pmd/rulesets/ruleset-minimum-priority.xml");
// only one rule should remain, since we filter out the other rule by minimum priority
assertEquals(1, ruleset.getRules().size(), "Number of Rules");

View File

@ -109,7 +109,7 @@ public class RulesetFactoryTestBase {
try (PmdAnalysis pmd = PmdAnalysis.create(config)) {
return pmd.newRuleSetLoader()
.warnDeprecated(true)
.enableCompatibility(false).loadFromString("dummyRuleset.xml", ruleSetXml);
.loadFromString("dummyRuleset.xml", ruleSetXml);
}
}

View File

@ -13,9 +13,12 @@ import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.RuleSetLoader;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
class RuleSetResolverTest {
@ -33,7 +36,9 @@ class RuleSetResolverTest {
assertFalse(additionalRulesets.isEmpty());
for (String filename : additionalRulesets) {
new RuleSetLoader().warnDeprecated(false).loadFromResource(filename); // will throw if invalid
PMDConfiguration config = new PMDConfiguration();
config.setReporter(new SimpleMessageReporter(LoggerFactory.getLogger(RuleSetResolverTest.class)));
RuleSetLoader.fromPmdConfig(config).warnDeprecated(false).loadFromResource(filename); // will throw if invalid
}
}

View File

@ -20,7 +20,7 @@ class QuickstartRulesetTest {
@Test
void noDeprecations() throws Exception {
RuleSetLoader ruleSetLoader = new RuleSetLoader().enableCompatibility(false);
RuleSetLoader ruleSetLoader = new RuleSetLoader();
String errorOutput = SystemLambda.tapSystemErr(() -> {
RuleSet quickstart = ruleSetLoader.loadFromResource(QUICKSTART_RULESET);
assertFalse(quickstart.getRules().isEmpty());