Remove deprecated ctors of RuleSetFactory

This commit is contained in:
Clément Fournier
2020-12-12 17:38:40 +01:00
parent 134dbed07e
commit 94028a1ce6
7 changed files with 22 additions and 192 deletions

View File

@ -62,58 +62,14 @@ public class RuleSetFactory {
private final Map<RuleSetReferenceId, RuleSet> parsedRulesets = new HashMap<>();
/**
* @deprecated Use a {@link RuleSetLoader} to build a new factory
*/
@Deprecated // to be removed with PMD 7.0.0.
public RuleSetFactory() {
this(new ResourceLoader(), RulePriority.LOW, false, true);
}
/**
* @deprecated Use a {@link RuleSetLoader} to build a new factory
*/
@Deprecated // to be removed with PMD 7.0.0.
public RuleSetFactory(final ClassLoader classLoader, final RulePriority minimumPriority,
final boolean warnDeprecated, final boolean enableCompatibility) {
this(new ResourceLoader(classLoader), minimumPriority, warnDeprecated, enableCompatibility);
}
/**
* @deprecated Use a {@link RuleSetLoader} to build a new factory
*/
@Deprecated // to be hidden with PMD 7.0.0.
public RuleSetFactory(final ResourceLoader resourceLoader, final RulePriority minimumPriority,
final boolean warnDeprecated, final boolean enableCompatibility) {
this(resourceLoader, minimumPriority, warnDeprecated, enableCompatibility, false);
}
RuleSetFactory(final ResourceLoader resourceLoader, final RulePriority minimumPriority,
final boolean warnDeprecated, final boolean enableCompatibility, boolean includeDeprecatedRuleReferences) {
final boolean warnDeprecated, final RuleSetFactoryCompatibility compatFilter, boolean includeDeprecatedRuleReferences) {
this.resourceLoader = resourceLoader;
this.minimumPriority = minimumPriority;
this.warnDeprecated = warnDeprecated;
this.includeDeprecatedRuleReferences = includeDeprecatedRuleReferences;
if (enableCompatibility) {
this.compatibilityFilter = new RuleSetFactoryCompatibility();
} else {
this.compatibilityFilter = null;
}
}
/**
* Constructor copying all configuration from another factory.
*
* @param factory The factory whose configuration to copy.
* @param warnDeprecated Whether deprecation warnings are to be produced by this
* factory
*
* @deprecated Use {@link #toLoader()} to rebuild a factory from a configuration
*/
@Deprecated
public RuleSetFactory(final RuleSetFactory factory, final boolean warnDeprecated) {
this(factory.resourceLoader, factory.minimumPriority, warnDeprecated, factory.compatibilityFilter != null);
this.compatibilityFilter = compatFilter;
}

View File

@ -12,6 +12,8 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.util.CollectionUtil;
@ -30,7 +32,7 @@ public final class RuleSetLoader {
private ResourceLoader resourceLoader = new ResourceLoader(RuleSetLoader.class.getClassLoader());
private RulePriority minimumPriority = RulePriority.LOW;
private boolean warnDeprecated = true;
private boolean enableCompatibility = true;
private @Nullable RuleSetFactoryCompatibility compatFilter;
private boolean includeDeprecatedRuleReferences = false;
/**
@ -81,7 +83,11 @@ public final class RuleSetLoader {
* @return This instance, modified
*/
public RuleSetLoader enableCompatibility(boolean enable) {
this.enableCompatibility = enable;
if (enable) {
this.compatFilter = RuleSetFactoryCompatibility.INSTANCE;
} else {
this.compatFilter = null;
}
return this;
}
@ -110,7 +116,7 @@ public final class RuleSetLoader {
this.resourceLoader,
this.minimumPriority,
this.warnDeprecated,
this.enableCompatibility,
this.compatFilter,
this.includeDeprecatedRuleReferences
);
}

View File

@ -11,7 +11,6 @@ import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.util.ResourceLoader;
/**
* @deprecated Use a {@link RuleSetLoader} instead
@ -79,35 +78,6 @@ public final class RulesetsFactoryUtils {
}
}
/**
* @deprecated Use a {@link RuleSetLoader}
*/
@InternalApi
@Deprecated
public static RuleSetFactory getRulesetFactory(final PMDConfiguration configuration,
final ResourceLoader resourceLoader) {
return new RuleSetFactory(resourceLoader, configuration.getMinimumPriority(), true,
configuration.isRuleSetFactoryCompatibilityEnabled());
}
/**
* Returns a ruleset factory which uses the classloader for PMD
* classes to resolve resource references.
*
* @param configuration PMD configuration, contains info about the
* factory parameters
*
* @return A ruleset factory
*
* @see #createFactory(PMDConfiguration, ClassLoader)
*
* @deprecated Use {@link RuleSetLoader#fromPmdConfig(PMDConfiguration)}
*/
@Deprecated
public static RuleSetFactory createFactory(final PMDConfiguration configuration) {
return createFactory(configuration, RulesetsFactoryUtils.class.getClassLoader());
}
/**
* Returns a ruleset factory with default parameters. It doesn't prune
* rules based on priority, and doesn't warn for deprecations.
@ -116,105 +86,9 @@ public final class RulesetsFactoryUtils {
*
* @see RuleSetLoader
*/
@Deprecated
public static RuleSetFactory defaultFactory() {
return new RuleSetFactory();
}
/**
* Returns a ruleset factory which uses the provided {@link ClassLoader}
* to resolve resource references. It warns for deprecated rule usages.
*
* @param configuration PMD configuration, contains info about the
* factory parameters
* @param classLoader Class loader to load resources
*
* @return A ruleset factory
*
* @see #createFactory(PMDConfiguration)
*
* @deprecated Use a {@link RuleSetLoader}
*/
@Deprecated
public static RuleSetFactory createFactory(final PMDConfiguration configuration, ClassLoader classLoader) {
return createFactory(classLoader,
configuration.getMinimumPriority(),
true,
configuration.isRuleSetFactoryCompatibilityEnabled());
}
/**
* Returns a ruleset factory which uses the provided {@link ClassLoader}
* to resolve resource references.
*
* @param minimumPriority Minimum priority for rules to be included
* @param warnDeprecated If true, print warnings when deprecated rules are included
* @param enableCompatibility If true, rule references to moved rules are mapped to their
* new location if they are known
* @param classLoader Class loader to load resources
*
* @return A ruleset factory
*
* @see #createFactory(PMDConfiguration)
*
* @deprecated Use a {@link RuleSetLoader}
*/
@Deprecated
public static RuleSetFactory createFactory(ClassLoader classLoader,
RulePriority minimumPriority,
boolean warnDeprecated,
boolean enableCompatibility) {
return new RuleSetFactory(new ResourceLoader(classLoader), minimumPriority, warnDeprecated, enableCompatibility);
}
/**
* Returns a ruleset factory which uses the classloader for PMD
* classes to resolve resource references.
*
* @param minimumPriority Minimum priority for rules to be included
* @param warnDeprecated If true, print warnings when deprecated rules are included
* @param enableCompatibility If true, rule references to moved rules are mapped to their
* new location if they are known
*
* @return A ruleset factory
*
* @see #createFactory(PMDConfiguration)
*
* @deprecated Use a {@link RuleSetLoader}
*/
@Deprecated
public static RuleSetFactory createFactory(RulePriority minimumPriority,
boolean warnDeprecated,
boolean enableCompatibility) {
return new RuleSetFactory(new ResourceLoader(), minimumPriority, warnDeprecated, enableCompatibility);
}
/**
* Returns a ruleset factory which uses the classloader for PMD
* classes to resolve resource references.
*
* @param minimumPriority Minimum priority for rules to be included
* @param warnDeprecated If true, print warnings when deprecated rules are included
* @param enableCompatibility If true, rule references to moved rules are mapped to their
* new location if they are known
* @param includeDeprecatedRuleReferences If true, deprecated rule references are retained. Usually, these
* references are ignored, since they indicate renamed/moved rules, and the referenced
* rule is often included in the same ruleset. Enabling this might result in
* duplicated rules.
*
* @return A ruleset factory
*
* @see #createFactory(PMDConfiguration)
* @deprecated Use a {@link RuleSetLoader}
*/
@Deprecated
public static RuleSetFactory createFactory(RulePriority minimumPriority,
boolean warnDeprecated,
boolean enableCompatibility,
boolean includeDeprecatedRuleReferences) {
return new RuleSetFactory(new ResourceLoader(), minimumPriority, warnDeprecated, enableCompatibility,
includeDeprecatedRuleReferences);
return new RuleSetLoader().toFactory();
}
/**

View File

@ -254,12 +254,10 @@ public class RuleSetFactoryTest {
* <p>When loading this ruleset at a whole for generating the documentation, we should still
* include the deprecated rule reference, so that we can create a nice documentation.
*
* @throws Exception
*/
@Test
public void testRuleSetWithDeprecatedRenamedRuleForDoc() throws Exception {
RuleSetFactory rsf = RulesetsFactoryUtils.createFactory(RulePriority.LOW, false, false, true);
RuleSet rs = rsf.createRuleSet(createRuleSetReferenceId("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ruleset name=\"test\">\n"
public void testRuleSetWithDeprecatedRenamedRuleForDoc() {
RuleSet rs = new RuleSetLoader().loadFromResource(createRuleSetReferenceId("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ruleset name=\"test\">\n"
+ " <description>ruleset desc</description>\n"
+ " <rule deprecated=\"true\" ref=\"NewName\" name=\"OldName\"/>"
+ " <rule name=\"NewName\" message=\"m\" class=\"net.sourceforge.pmd.lang.rule.XPathRule\" language=\"dummy\">"

View File

@ -18,7 +18,6 @@ import net.sourceforge.pmd.PMDException;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
@ -142,9 +141,9 @@ public class StageDependencyTest {
private static RuleSets withRules(Rule r, Rule... rs) {
List<RuleSet> rsets = new ArrayList<>();
rsets.add(new RuleSetFactory().createSingleRuleRuleSet(r));
rsets.add(RuleSet.forSingleRule(r));
for (Rule rule : rs) {
rsets.add(new RuleSetFactory().createSingleRuleRuleSet(rule));
rsets.add(RuleSet.forSingleRule(rule));
}
return new RuleSets(rsets);

View File

@ -21,11 +21,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.RulesetsFactoryUtils;
import net.sourceforge.pmd.RuleSetLoader;
import net.sourceforge.pmd.docs.MockedFileWriter.FileEntry;
public class RuleDocGeneratorTest {
@ -59,11 +56,11 @@ public class RuleDocGeneratorTest {
}
@Test
public void testSingleRuleset() throws RuleSetNotFoundException, IOException {
public void testSingleRuleset() throws IOException {
RuleDocGenerator generator = new RuleDocGenerator(writer, root);
RuleSetFactory rsf = RulesetsFactoryUtils.createFactory(RulePriority.LOW, false, false, true);
RuleSet ruleset = rsf.createRuleSet("rulesets/ruledoctest/sample.xml");
RuleSetLoader rsf = new RuleSetLoader();
RuleSet ruleset = rsf.loadFromResource("rulesets/ruledoctest/sample.xml");
generator.generate(Arrays.asList(ruleset),
Arrays.asList(

View File

@ -217,7 +217,7 @@ abstract class BaseParsingHelper<Self : BaseParsingHelper<Self, T>, T : RootNode
ctx.report = report
ctx.sourceCodeFile = File(filename)
ctx.isIgnoreExceptions = false
val rules = RuleSetFactory().createSingleRuleRuleSet(rule)
val rules = RuleSet.forSingleRule(rule)
try {
p.sourceCodeProcessor.processSourceCode(StringReader(code), RuleSets(rules), ctx)
} catch (e: PMDException) {