From 870f48e9718f5aa966d575846a48c0b909bb2c3d Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 14 Apr 2023 10:01:21 -0700 Subject: [PATCH] Switched to varargs for adding paths and rule sets --- .../java/rife/bld/extension/PmdOperation.java | 17 +++++++++-------- .../rife/bld/extension/PmdOperationTest.java | 15 +++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/rife/bld/extension/PmdOperation.java b/src/main/java/rife/bld/extension/PmdOperation.java index a9499dc..a8ea894 100644 --- a/src/main/java/rife/bld/extension/PmdOperation.java +++ b/src/main/java/rife/bld/extension/PmdOperation.java @@ -43,12 +43,13 @@ public class PmdOperation extends AbstractOperation { /** * 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 String PMD_DIR = "pmd"; /** * The cache location. + * */ Path cache; /** @@ -154,21 +155,21 @@ public class PmdOperation extends AbstractOperation { inputPaths.add(project.srcMainDirectory().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...) */ - public PmdOperation addInputPath(Path inputPath) { - inputPaths.add(inputPath); + public PmdOperation addInputPath(Path... inputPath) { + inputPaths.addAll(List.of(inputPath)); return this; } /** - * Adds a new rule set path. + * Adds new rule set paths. *

* The built-in rule set paths are: *

    @@ -185,8 +186,8 @@ public class PmdOperation extends AbstractOperation { * * @see #ruleSets(String...) */ - public PmdOperation addRuleSet(String ruleSet) { - ruleSets.add(ruleSet); + public PmdOperation addRuleSet(String... ruleSet) { + ruleSets.addAll(List.of(ruleSet)); return this; } diff --git a/src/test/java/rife/bld/extension/PmdOperationTest.java b/src/test/java/rife/bld/extension/PmdOperationTest.java index 683b5c0..1dea825 100644 --- a/src/test/java/rife/bld/extension/PmdOperationTest.java +++ b/src/test/java/rife/bld/extension/PmdOperationTest.java @@ -69,28 +69,35 @@ public class PmdOperationTest { void testJavaErrorProne() { var pmd = pmdOperation.ruleSets("category/java/errorprone.xml"); 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 void testJavaCodeStyle() { var pmd = pmdOperation.ruleSets("category/java/codestyle.xml"); assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) - .as("no errors").isGreaterThan(0); + .as("many errors").isGreaterThan(0); } @Test void testJavaDesign() { var pmd = pmdOperation.ruleSets("category/java/design.xml"); assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) - .as("no errors").isGreaterThan(0); + .as("many errors").isGreaterThan(0); } @Test void testJavaDocumentation() { var pmd = pmdOperation.ruleSets("category/java/documentation.xml"); assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))) - .as("no errors").isGreaterThan(0); + .as("many errors").isGreaterThan(0); } @Test