Rename
This commit is contained in:
@ -16,13 +16,13 @@ import org.junit.contrib.java.lang.system.SystemErrRule;
|
|||||||
|
|
||||||
import net.sourceforge.pmd.RuleSet;
|
import net.sourceforge.pmd.RuleSet;
|
||||||
import net.sourceforge.pmd.RuleSetFactory;
|
import net.sourceforge.pmd.RuleSetFactory;
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
import net.sourceforge.pmd.RuleSetParserConfig;
|
||||||
|
|
||||||
public class DefaultRulesetTest {
|
public class DefaultRulesetTest {
|
||||||
@Rule
|
@Rule
|
||||||
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests();
|
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests();
|
||||||
|
|
||||||
private RuleSetFactory factory = new RuleSetFactoryConfig().enableCompatibility(false).createFactory();
|
private RuleSetFactory factory = new RuleSetParserConfig().enableCompatibility(false).createFactory();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadDefaultRuleset() throws Exception {
|
public void loadDefaultRuleset() throws Exception {
|
||||||
|
@ -21,7 +21,6 @@ import java.util.logging.ConsoleHandler;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
|
||||||
import net.sourceforge.pmd.benchmark.TextTimingReportRenderer;
|
import net.sourceforge.pmd.benchmark.TextTimingReportRenderer;
|
||||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||||
import net.sourceforge.pmd.benchmark.TimedOperation;
|
import net.sourceforge.pmd.benchmark.TimedOperation;
|
||||||
@ -203,7 +202,7 @@ public class PMD {
|
|||||||
public static int doPMD(PMDConfiguration configuration) {
|
public static int doPMD(PMDConfiguration configuration) {
|
||||||
|
|
||||||
// Load the RuleSets
|
// Load the RuleSets
|
||||||
final RuleSetFactory ruleSetFactory = RuleSetFactoryConfig.fromPmdConfig(configuration).createFactory();
|
final RuleSetFactory ruleSetFactory = RuleSetParserConfig.fromPmdConfig(configuration).createFactory();
|
||||||
final RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory);
|
final RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory);
|
||||||
if (ruleSets == null) {
|
if (ruleSets == null) {
|
||||||
return PMDCommandLineInterface.NO_ERRORS_STATUS;
|
return PMDCommandLineInterface.NO_ERRORS_STATUS;
|
||||||
|
@ -44,9 +44,9 @@ import net.sourceforge.pmd.util.ResourceLoader;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* RuleSetFactory is responsible for creating RuleSet instances from XML
|
* RuleSetFactory is responsible for creating RuleSet instances from XML
|
||||||
* content. See {@link RuleSetFactoryConfig} for configuration options and
|
* content. See {@link RuleSetParserConfig} for configuration options and
|
||||||
* their defaults. The constructors of this class are deprecated and their
|
* their defaults. The constructors of this class are deprecated and their
|
||||||
* usages should be replaced by use of {@link RuleSetFactoryConfig#createFactory()}.
|
* usages should be replaced by use of {@link RuleSetParserConfig#createFactory()}.
|
||||||
*/
|
*/
|
||||||
public class RuleSetFactory {
|
public class RuleSetFactory {
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class RuleSetFactory {
|
|||||||
private final Map<RuleSetReferenceId, RuleSet> parsedRulesets = new HashMap<>();
|
private final Map<RuleSetReferenceId, RuleSet> parsedRulesets = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig} to build a new factory
|
* @deprecated Use a {@link RuleSetParserConfig} to build a new factory
|
||||||
*/
|
*/
|
||||||
@Deprecated // to be removed with PMD 7.0.0.
|
@Deprecated // to be removed with PMD 7.0.0.
|
||||||
public RuleSetFactory() {
|
public RuleSetFactory() {
|
||||||
@ -73,7 +73,7 @@ public class RuleSetFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig} to build a new factory
|
* @deprecated Use a {@link RuleSetParserConfig} to build a new factory
|
||||||
*/
|
*/
|
||||||
@Deprecated // to be removed with PMD 7.0.0.
|
@Deprecated // to be removed with PMD 7.0.0.
|
||||||
public RuleSetFactory(final ClassLoader classLoader, final RulePriority minimumPriority,
|
public RuleSetFactory(final ClassLoader classLoader, final RulePriority minimumPriority,
|
||||||
@ -82,7 +82,7 @@ public class RuleSetFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig} to build a new factory
|
* @deprecated Use a {@link RuleSetParserConfig} to build a new factory
|
||||||
*/
|
*/
|
||||||
@Deprecated // to be hidden with PMD 7.0.0.
|
@Deprecated // to be hidden with PMD 7.0.0.
|
||||||
public RuleSetFactory(final ResourceLoader resourceLoader, final RulePriority minimumPriority,
|
public RuleSetFactory(final ResourceLoader resourceLoader, final RulePriority minimumPriority,
|
||||||
@ -121,7 +121,7 @@ public class RuleSetFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RuleSetFactory(RuleSetFactoryConfig config) {
|
RuleSetFactory(RuleSetParserConfig config) {
|
||||||
this(config.resourceLoader, config.minimumPriority, config.warnDeprecated, config.enableCompatibility, config.includeDeprecatedRuleReferences);
|
this(config.resourceLoader, config.minimumPriority, config.warnDeprecated, config.enableCompatibility, config.includeDeprecatedRuleReferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,93 +838,12 @@ public class RuleSetFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RuleSetFactoryConfig toConfig() {
|
public RuleSetParserConfig toConfig() {
|
||||||
return new RuleSetFactoryConfig().loadResourcesWith(resourceLoader)
|
return new RuleSetParserConfig().loadResourcesWith(resourceLoader)
|
||||||
.filterAbovePriority(minimumPriority)
|
.filterAbovePriority(minimumPriority)
|
||||||
.warnDeprecated(warnDeprecated)
|
.warnDeprecated(warnDeprecated)
|
||||||
.enableCompatibility(compatibilityFilter != null);
|
.enableCompatibility(compatibilityFilter != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration of a {@link RuleSetFactory}. This is a fluent builder
|
|
||||||
* pattern. Use this instead of the constructors of RuleSetFactory.
|
|
||||||
*/
|
|
||||||
public static final class RuleSetFactoryConfig {
|
|
||||||
|
|
||||||
ResourceLoader resourceLoader = new ResourceLoader(RuleSetFactoryConfig.class.getClassLoader());
|
|
||||||
RulePriority minimumPriority = RulePriority.LOW;
|
|
||||||
boolean warnDeprecated = true;
|
|
||||||
boolean enableCompatibility = true;
|
|
||||||
boolean includeDeprecatedRuleReferences = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify that the given classloader should be used to resolve
|
|
||||||
* paths to external ruleset references. The default uses PMD's
|
|
||||||
* own classpath.
|
|
||||||
*/
|
|
||||||
public RuleSetFactoryConfig loadResourcesWith(ClassLoader classLoader) {
|
|
||||||
this.resourceLoader = new ResourceLoader(classLoader);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// internal
|
|
||||||
RuleSetFactoryConfig loadResourcesWith(ResourceLoader loader) {
|
|
||||||
this.resourceLoader = loader;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter loaded rules to only those that match or are above
|
|
||||||
* the given priority. The default is {@link RulePriority#LOW},
|
|
||||||
* ie, no filtering occurs.
|
|
||||||
*/
|
|
||||||
public RuleSetFactoryConfig filterAbovePriority(RulePriority minimumPriority) {
|
|
||||||
this.minimumPriority = minimumPriority;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a warning when referencing a deprecated rule.
|
|
||||||
* This is enabled by default.
|
|
||||||
*/
|
|
||||||
public RuleSetFactoryConfig warnDeprecated(boolean warn) {
|
|
||||||
this.warnDeprecated = warn;
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
public RuleSetFactoryConfig enableCompatibility(boolean enable) {
|
|
||||||
this.enableCompatibility = enable;
|
|
||||||
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)}).
|
|
||||||
*/
|
|
||||||
public RuleSetFactoryConfig includeDeprecatedRuleReferences(boolean enable) {
|
|
||||||
this.includeDeprecatedRuleReferences = enable;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RuleSetFactory createFactory() {
|
|
||||||
return new RuleSetFactory(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure a new ruleset factory builder according to the parameters
|
|
||||||
* of the given PMD configuration.
|
|
||||||
*/
|
|
||||||
public static RuleSetFactoryConfig fromPmdConfig(PMDConfiguration configuration) {
|
|
||||||
return new RuleSetFactoryConfig().filterAbovePriority(configuration.getMinimumPriority())
|
|
||||||
.enableCompatibility(configuration.isRuleSetFactoryCompatibilityEnabled());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
|
||||||
import net.sourceforge.pmd.annotation.InternalApi;
|
import net.sourceforge.pmd.annotation.InternalApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +27,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
|||||||
*
|
*
|
||||||
* @see <a href="https://sourceforge.net/p/pmd/bugs/1360/">issue 1360</a>
|
* @see <a href="https://sourceforge.net/p/pmd/bugs/1360/">issue 1360</a>
|
||||||
*
|
*
|
||||||
* @deprecated Use {@link RuleSetFactoryConfig#enableCompatibility(boolean)} to enable this feature.
|
* @deprecated Use {@link RuleSetParserConfig#enableCompatibility(boolean)} to enable this feature.
|
||||||
* This implementation is internal API.
|
* This implementation is internal API.
|
||||||
*/
|
*/
|
||||||
@InternalApi
|
@InternalApi
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.sourceforge.pmd;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.util.ResourceLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration of a {@link RuleSetFactory}. This is a fluent builder
|
||||||
|
* pattern. Use this instead of the constructors of RuleSetFactory.
|
||||||
|
*/
|
||||||
|
public final class RuleSetParserConfig {
|
||||||
|
|
||||||
|
ResourceLoader resourceLoader = new ResourceLoader(RuleSetParserConfig.class.getClassLoader());
|
||||||
|
RulePriority minimumPriority = RulePriority.LOW;
|
||||||
|
boolean warnDeprecated = true;
|
||||||
|
boolean enableCompatibility = true;
|
||||||
|
boolean includeDeprecatedRuleReferences = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new config with the default values.
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify that the given classloader should be used to resolve
|
||||||
|
* paths to external ruleset references. The default uses PMD's
|
||||||
|
* own classpath.
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig loadResourcesWith(ClassLoader classLoader) {
|
||||||
|
this.resourceLoader = new ResourceLoader(classLoader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// internal
|
||||||
|
RuleSetParserConfig loadResourcesWith(ResourceLoader loader) {
|
||||||
|
this.resourceLoader = loader;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter loaded rules to only those that match or are above
|
||||||
|
* the given priority. The default is {@link RulePriority#LOW},
|
||||||
|
* ie, no filtering occurs.
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig filterAbovePriority(RulePriority minimumPriority) {
|
||||||
|
this.minimumPriority = minimumPriority;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a warning when referencing a deprecated rule.
|
||||||
|
* This is enabled by default.
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig warnDeprecated(boolean warn) {
|
||||||
|
this.warnDeprecated = warn;
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig enableCompatibility(boolean enable) {
|
||||||
|
this.enableCompatibility = enable;
|
||||||
|
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)}).
|
||||||
|
*/
|
||||||
|
public RuleSetParserConfig includeDeprecatedRuleReferences(boolean enable) {
|
||||||
|
this.includeDeprecatedRuleReferences = enable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RuleSetFactory createFactory() {
|
||||||
|
return new RuleSetFactory(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure a new ruleset factory builder according to the parameters
|
||||||
|
* of the given PMD configuration.
|
||||||
|
*/
|
||||||
|
public static RuleSetParserConfig fromPmdConfig(PMDConfiguration configuration) {
|
||||||
|
return new RuleSetParserConfig().filterAbovePriority(configuration.getMinimumPriority())
|
||||||
|
.enableCompatibility(configuration.isRuleSetFactoryCompatibilityEnabled());
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ package net.sourceforge.pmd;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
|
||||||
import net.sourceforge.pmd.annotation.InternalApi;
|
import net.sourceforge.pmd.annotation.InternalApi;
|
||||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||||
import net.sourceforge.pmd.benchmark.TimedOperation;
|
import net.sourceforge.pmd.benchmark.TimedOperation;
|
||||||
@ -77,7 +76,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig}
|
* @deprecated Use a {@link RuleSetParserConfig}
|
||||||
*/
|
*/
|
||||||
@InternalApi
|
@InternalApi
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -98,7 +97,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
*
|
*
|
||||||
* @see #createFactory(PMDConfiguration, ClassLoader)
|
* @see #createFactory(PMDConfiguration, ClassLoader)
|
||||||
*
|
*
|
||||||
* @deprecated Use {@link RuleSetFactoryConfig#fromPmdConfig(PMDConfiguration)}
|
* @deprecated Use {@link RuleSetParserConfig#fromPmdConfig(PMDConfiguration)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static RuleSetFactory createFactory(final PMDConfiguration configuration) {
|
public static RuleSetFactory createFactory(final PMDConfiguration configuration) {
|
||||||
@ -111,7 +110,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
*
|
*
|
||||||
* @return A ruleset factory
|
* @return A ruleset factory
|
||||||
*
|
*
|
||||||
* @see RuleSetFactoryConfig
|
* @see RuleSetParserConfig
|
||||||
*/
|
*/
|
||||||
public static RuleSetFactory defaultFactory() {
|
public static RuleSetFactory defaultFactory() {
|
||||||
return new RuleSetFactory();
|
return new RuleSetFactory();
|
||||||
@ -129,7 +128,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
*
|
*
|
||||||
* @see #createFactory(PMDConfiguration)
|
* @see #createFactory(PMDConfiguration)
|
||||||
*
|
*
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig}
|
* @deprecated Use a {@link RuleSetParserConfig}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static RuleSetFactory createFactory(final PMDConfiguration configuration, ClassLoader classLoader) {
|
public static RuleSetFactory createFactory(final PMDConfiguration configuration, ClassLoader classLoader) {
|
||||||
@ -153,7 +152,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
*
|
*
|
||||||
* @see #createFactory(PMDConfiguration)
|
* @see #createFactory(PMDConfiguration)
|
||||||
*
|
*
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig}
|
* @deprecated Use a {@link RuleSetParserConfig}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static RuleSetFactory createFactory(ClassLoader classLoader,
|
public static RuleSetFactory createFactory(ClassLoader classLoader,
|
||||||
@ -177,7 +176,7 @@ public final class RulesetsFactoryUtils {
|
|||||||
*
|
*
|
||||||
* @see #createFactory(PMDConfiguration)
|
* @see #createFactory(PMDConfiguration)
|
||||||
*
|
*
|
||||||
* @deprecated Use a {@link RuleSetFactoryConfig}
|
* @deprecated Use a {@link RuleSetParserConfig}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static RuleSetFactory createFactory(RulePriority minimumPriority,
|
public static RuleSetFactory createFactory(RulePriority minimumPriority,
|
||||||
|
@ -29,7 +29,7 @@ import net.sourceforge.pmd.RuleContext;
|
|||||||
import net.sourceforge.pmd.RulePriority;
|
import net.sourceforge.pmd.RulePriority;
|
||||||
import net.sourceforge.pmd.RuleSet;
|
import net.sourceforge.pmd.RuleSet;
|
||||||
import net.sourceforge.pmd.RuleSetFactory;
|
import net.sourceforge.pmd.RuleSetFactory;
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
import net.sourceforge.pmd.RuleSetParserConfig;
|
||||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||||
import net.sourceforge.pmd.RuleSets;
|
import net.sourceforge.pmd.RuleSets;
|
||||||
import net.sourceforge.pmd.ant.Formatter;
|
import net.sourceforge.pmd.ant.Formatter;
|
||||||
@ -102,9 +102,9 @@ public class PMDTaskImpl {
|
|||||||
setupClassLoader();
|
setupClassLoader();
|
||||||
|
|
||||||
// Setup RuleSetFactory and validate RuleSets
|
// Setup RuleSetFactory and validate RuleSets
|
||||||
RuleSetFactory ruleSetFactory = RuleSetFactoryConfig.fromPmdConfig(configuration)
|
RuleSetFactory ruleSetFactory = RuleSetParserConfig.fromPmdConfig(configuration)
|
||||||
.loadResourcesWith(setupResourceLoader())
|
.loadResourcesWith(setupResourceLoader())
|
||||||
.createFactory();
|
.createFactory();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// This is just used to validate and display rules. Each thread will create its own ruleset
|
// This is just used to validate and display rules. Each thread will create its own ruleset
|
||||||
|
@ -23,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
|
||||||
import net.sourceforge.pmd.junit.JavaUtilLoggingRule;
|
import net.sourceforge.pmd.junit.JavaUtilLoggingRule;
|
||||||
import net.sourceforge.pmd.junit.LocaleRule;
|
import net.sourceforge.pmd.junit.LocaleRule;
|
||||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||||
@ -506,7 +505,7 @@ public class RuleSetFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReferencePriority() throws RuleSetNotFoundException {
|
public void testReferencePriority() throws RuleSetNotFoundException {
|
||||||
RuleSetFactoryConfig config = new RuleSetFactoryConfig().warnDeprecated(false).enableCompatibility(true);
|
RuleSetParserConfig config = new RuleSetParserConfig().warnDeprecated(false).enableCompatibility(true);
|
||||||
|
|
||||||
RuleSetFactory rsf = config.filterAbovePriority(RulePriority.LOW).createFactory();
|
RuleSetFactory rsf = config.filterAbovePriority(RulePriority.LOW).createFactory();
|
||||||
RuleSet ruleSet = rsf.createRuleSet(createRuleSetReferenceId(REF_INTERNAL_TO_INTERNAL_CHAIN));
|
RuleSet ruleSet = rsf.createRuleSet(createRuleSetReferenceId(REF_INTERNAL_TO_INTERNAL_CHAIN));
|
||||||
@ -547,7 +546,7 @@ public class RuleSetFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverridePriorityLoadWithMinimum() throws RuleSetNotFoundException {
|
public void testOverridePriorityLoadWithMinimum() throws RuleSetNotFoundException {
|
||||||
RuleSetFactory rsf = new RuleSetFactoryConfig().filterAbovePriority(RulePriority.MEDIUM_LOW).warnDeprecated(true).enableCompatibility(true).createFactory();
|
RuleSetFactory rsf = new RuleSetParserConfig().filterAbovePriority(RulePriority.MEDIUM_LOW).warnDeprecated(true).enableCompatibility(true).createFactory();
|
||||||
RuleSet ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority.xml");
|
RuleSet ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority.xml");
|
||||||
// only one rule should remain, since we filter out the other rule by minimum priority
|
// only one rule should remain, since we filter out the other rule by minimum priority
|
||||||
assertEquals("Number of Rules", 1, ruleset.getRules().size());
|
assertEquals("Number of Rules", 1, ruleset.getRules().size());
|
||||||
@ -568,13 +567,13 @@ public class RuleSetFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExcludeWithMinimumPriority() throws RuleSetNotFoundException {
|
public void testExcludeWithMinimumPriority() throws RuleSetNotFoundException {
|
||||||
RuleSetFactory rsf = new RuleSetFactoryConfig().filterAbovePriority(RulePriority.HIGH).createFactory();
|
RuleSetFactory rsf = new RuleSetParserConfig().filterAbovePriority(RulePriority.HIGH).createFactory();
|
||||||
RuleSet ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority-exclusion.xml");
|
RuleSet ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority-exclusion.xml");
|
||||||
// no rules should be loaded
|
// no rules should be loaded
|
||||||
assertEquals("Number of Rules", 0, ruleset.getRules().size());
|
assertEquals("Number of Rules", 0, ruleset.getRules().size());
|
||||||
|
|
||||||
// now, load with default minimum priority
|
// now, load with default minimum priority
|
||||||
rsf = new RuleSetFactoryConfig().filterAbovePriority(RulePriority.LOW).createFactory();
|
rsf = new RuleSetParserConfig().filterAbovePriority(RulePriority.LOW).createFactory();
|
||||||
ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority-exclusion.xml");
|
ruleset = rsf.createRuleSet("net/sourceforge/pmd/rulesets/ruleset-minimum-priority-exclusion.xml");
|
||||||
// only one rule, we have excluded one...
|
// only one rule, we have excluded one...
|
||||||
assertEquals("Number of Rules", 1, ruleset.getRules().size());
|
assertEquals("Number of Rules", 1, ruleset.getRules().size());
|
||||||
@ -603,9 +602,9 @@ public class RuleSetFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetPriority() throws RuleSetNotFoundException {
|
public void testSetPriority() throws RuleSetNotFoundException {
|
||||||
RuleSetFactory rsf = new RuleSetFactoryConfig().filterAbovePriority(RulePriority.MEDIUM_HIGH).warnDeprecated(false).createFactory();
|
RuleSetFactory rsf = new RuleSetParserConfig().filterAbovePriority(RulePriority.MEDIUM_HIGH).warnDeprecated(false).createFactory();
|
||||||
assertEquals(0, rsf.createRuleSet(createRuleSetReferenceId(SINGLE_RULE)).size());
|
assertEquals(0, rsf.createRuleSet(createRuleSetReferenceId(SINGLE_RULE)).size());
|
||||||
rsf = new RuleSetFactoryConfig().filterAbovePriority(RulePriority.MEDIUM_LOW).warnDeprecated(false).createFactory();
|
rsf = new RuleSetParserConfig().filterAbovePriority(RulePriority.MEDIUM_LOW).warnDeprecated(false).createFactory();
|
||||||
assertEquals(1, rsf.createRuleSet(createRuleSetReferenceId(SINGLE_RULE)).size());
|
assertEquals(1, rsf.createRuleSet(createRuleSetReferenceId(SINGLE_RULE)).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +779,7 @@ public class RuleSetFactoryTest {
|
|||||||
+ " <description>Ruleset which references a empty ruleset</description>\n" + "\n"
|
+ " <description>Ruleset which references a empty ruleset</description>\n" + "\n"
|
||||||
+ " <rule ref=\"rulesets/dummy/empty-ruleset.xml\" />\n"
|
+ " <rule ref=\"rulesets/dummy/empty-ruleset.xml\" />\n"
|
||||||
+ "</ruleset>\n");
|
+ "</ruleset>\n");
|
||||||
RuleSetFactory ruleSetFactory = new RuleSetFactoryConfig().loadResourcesWith(new ResourceLoader()).filterAbovePriority(RulePriority.LOW).warnDeprecated(true).enableCompatibility(true).createFactory();
|
RuleSetFactory ruleSetFactory = new RuleSetParserConfig().loadResourcesWith(new ResourceLoader()).filterAbovePriority(RulePriority.LOW).warnDeprecated(true).enableCompatibility(true).createFactory();
|
||||||
RuleSet ruleset = ruleSetFactory.createRuleSet(ref);
|
RuleSet ruleset = ruleSetFactory.createRuleSet(ref);
|
||||||
assertEquals(0, ruleset.getRules().size());
|
assertEquals(0, ruleset.getRules().size());
|
||||||
|
|
||||||
@ -1285,7 +1284,7 @@ public class RuleSetFactoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RuleSet loadRuleSetWithDeprecationWarnings(String ruleSetXml) throws RuleSetNotFoundException {
|
private RuleSet loadRuleSetWithDeprecationWarnings(String ruleSetXml) throws RuleSetNotFoundException {
|
||||||
RuleSetFactory rsf = new RuleSetFactoryConfig().warnDeprecated(true).enableCompatibility(false).createFactory();
|
RuleSetFactory rsf = new RuleSetParserConfig().warnDeprecated(true).enableCompatibility(false).createFactory();
|
||||||
return rsf.createRuleSet(createRuleSetReferenceId(ruleSetXml));
|
return rsf.createRuleSet(createRuleSetReferenceId(ruleSetXml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import net.sourceforge.pmd.RuleSet;
|
import net.sourceforge.pmd.RuleSet;
|
||||||
import net.sourceforge.pmd.RuleSetFactory;
|
import net.sourceforge.pmd.RuleSetFactory;
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
import net.sourceforge.pmd.RuleSetParserConfig;
|
||||||
|
|
||||||
public class PMD5RulesetTest {
|
public class PMD5RulesetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadRuleset() throws Exception {
|
public void loadRuleset() throws Exception {
|
||||||
RuleSetFactory ruleSetFactory = new RuleSetFactoryConfig().createFactory();
|
RuleSetFactory ruleSetFactory = new RuleSetParserConfig().createFactory();
|
||||||
RuleSet ruleset = ruleSetFactory.createRuleSet("net/sourceforge/pmd/lang/java/pmd5ruleset.xml");
|
RuleSet ruleset = ruleSetFactory.createRuleSet("net/sourceforge/pmd/lang/java/pmd5ruleset.xml");
|
||||||
Assert.assertNotNull(ruleset);
|
Assert.assertNotNull(ruleset);
|
||||||
Assert.assertNull(ruleset.getRuleByName("GuardLogStatementJavaUtil"));
|
Assert.assertNull(ruleset.getRuleByName("GuardLogStatementJavaUtil"));
|
||||||
|
@ -16,7 +16,7 @@ import org.junit.contrib.java.lang.system.SystemErrRule;
|
|||||||
|
|
||||||
import net.sourceforge.pmd.RuleSet;
|
import net.sourceforge.pmd.RuleSet;
|
||||||
import net.sourceforge.pmd.RuleSetFactory;
|
import net.sourceforge.pmd.RuleSetFactory;
|
||||||
import net.sourceforge.pmd.RuleSetFactory.RuleSetFactoryConfig;
|
import net.sourceforge.pmd.RuleSetParserConfig;
|
||||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||||
|
|
||||||
public class QuickstartRulesetTest {
|
public class QuickstartRulesetTest {
|
||||||
@ -49,7 +49,7 @@ public class QuickstartRulesetTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RuleSetFactory ruleSetFactory = new RuleSetFactoryConfig().enableCompatibility(false).createFactory();
|
RuleSetFactory ruleSetFactory = new RuleSetParserConfig().enableCompatibility(false).createFactory();
|
||||||
RuleSet quickstart = ruleSetFactory.createRuleSet("rulesets/java/quickstart.xml");
|
RuleSet quickstart = ruleSetFactory.createRuleSet("rulesets/java/quickstart.xml");
|
||||||
Assert.assertFalse(quickstart.getRules().isEmpty());
|
Assert.assertFalse(quickstart.getRules().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import net.sourceforge.pmd.Report;
|
|||||||
import net.sourceforge.pmd.Rule;
|
import net.sourceforge.pmd.Rule;
|
||||||
import net.sourceforge.pmd.RuleContext;
|
import net.sourceforge.pmd.RuleContext;
|
||||||
import net.sourceforge.pmd.RuleSet;
|
import net.sourceforge.pmd.RuleSet;
|
||||||
import net.sourceforge.pmd.RuleSetFactory;
|
|
||||||
import net.sourceforge.pmd.RuleSets;
|
import net.sourceforge.pmd.RuleSets;
|
||||||
|
import net.sourceforge.pmd.RulesetsFactoryUtils;
|
||||||
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
|
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
|
||||||
import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public final class ScalaParsingHelper extends BaseParsingHelper<ScalaParsingHelp
|
|||||||
Report report = new Report();
|
Report report = new Report();
|
||||||
ctx.setReport(report);
|
ctx.setReport(report);
|
||||||
ctx.setSourceCodeFile(new File("test.scala"));
|
ctx.setSourceCodeFile(new File("test.scala"));
|
||||||
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
|
RuleSet rules = RulesetsFactoryUtils.defaultFactory().createSingleRuleRuleSet(rule);
|
||||||
try {
|
try {
|
||||||
p.getSourceCodeProcessor().processSourceCode(new StringReader(testSourceCode), new RuleSets(rules), ctx);
|
p.getSourceCodeProcessor().processSourceCode(new StringReader(testSourceCode), new RuleSets(rules), ctx);
|
||||||
} catch (PMDException e) {
|
} catch (PMDException e) {
|
||||||
|
Reference in New Issue
Block a user