Switched to varargs for adding paths and rule sets

This commit is contained in:
Erik C. Thauvin 2023-04-14 10:01:21 -07:00
parent 39abc2e719
commit 870f48e971
2 changed files with 20 additions and 12 deletions

View file

@ -43,12 +43,13 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
/** /**
* The default rule set. * The default rule set.
*/ */
public static final String RULESET_DEFAULT = "rulesets/java/quickstart.xml"; public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName());
private static final String PMD_DIR = "pmd"; private static final String PMD_DIR = "pmd";
/** /**
* The cache location. * The cache location.
*
*/ */
Path cache; Path cache;
/** /**
@ -154,21 +155,21 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
inputPaths.add(project.srcMainDirectory().toPath()); inputPaths.add(project.srcMainDirectory().toPath());
inputPaths.add(project.srcTestDirectory().toPath()); inputPaths.add(project.srcTestDirectory().toPath());
ruleSets.add(RULESET_DEFAULT); ruleSets.add(RULE_SET_DEFAULT);
} }
/** /**
* Adds the path to a source file, or directory containing source files to analyze. * Adds paths to source files, or directories containing source files to analyze.
* *
* @see #inputPaths(Path...) * @see #inputPaths(Path...)
*/ */
public PmdOperation addInputPath(Path inputPath) { public PmdOperation addInputPath(Path... inputPath) {
inputPaths.add(inputPath); inputPaths.addAll(List.of(inputPath));
return this; return this;
} }
/** /**
* Adds a new rule set path. * Adds new rule set paths.
* <p> * <p>
* The built-in rule set paths are: * The built-in rule set paths are:
* <ul> * <ul>
@ -185,8 +186,8 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* *
* @see #ruleSets(String...) * @see #ruleSets(String...)
*/ */
public PmdOperation addRuleSet(String ruleSet) { public PmdOperation addRuleSet(String... ruleSet) {
ruleSets.add(ruleSet); ruleSets.addAll(List.of(ruleSet));
return this; return this;
} }

View file

@ -69,28 +69,35 @@ public class PmdOperationTest {
void testJavaErrorProne() { void testJavaErrorProne() {
var pmd = pmdOperation.ruleSets("category/java/errorprone.xml"); var pmd = pmdOperation.ruleSets("category/java/errorprone.xml");
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("no errors").isGreaterThan(0); .as("many errors").isGreaterThan(0);
}
@Test
void testJavaCodeStyleAndErrorProne() {
var pmd = pmdOperation.addRuleSet("category/java/codestyle.xml", "category/java/errorprone.xml");
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("many errors").isGreaterThan(0);
} }
@Test @Test
void testJavaCodeStyle() { void testJavaCodeStyle() {
var pmd = pmdOperation.ruleSets("category/java/codestyle.xml"); var pmd = pmdOperation.ruleSets("category/java/codestyle.xml");
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("no errors").isGreaterThan(0); .as("many errors").isGreaterThan(0);
} }
@Test @Test
void testJavaDesign() { void testJavaDesign() {
var pmd = pmdOperation.ruleSets("category/java/design.xml"); var pmd = pmdOperation.ruleSets("category/java/design.xml");
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("no errors").isGreaterThan(0); .as("many errors").isGreaterThan(0);
} }
@Test @Test
void testJavaDocumentation() { void testJavaDocumentation() {
var pmd = pmdOperation.ruleSets("category/java/documentation.xml"); var pmd = pmdOperation.ruleSets("category/java/documentation.xml");
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("no errors").isGreaterThan(0); .as("many errors").isGreaterThan(0);
} }
@Test @Test