From df14ea9c95311041b5cc009a1a562d6e308a1a2f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 13 Jul 2015 19:50:40 +0200 Subject: [PATCH] #1379 PMD CLI: Cannot specify multiple properties --- .../net/sourceforge/pmd/cli/PMDParameters.java | 13 ++++++++++--- .../pmd/cli/PMDCommandLineInterfaceTest.java | 16 +++++++++++++++- src/site/markdown/overview/changelog.md | 1 + 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index abc2e83a94..d523eb11d0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cli; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; import net.sourceforge.pmd.PMDConfiguration; @@ -60,8 +62,9 @@ public class PMDParameters { @Parameter(names = { "-minimumpriority", "-min" }, description = "Rule priority threshold; rules with lower priority than configured here won't be used. Default is '5' which is the lowest priority.", converter = RulePriorityConverter.class) private RulePriority minimumPriority = RulePriority.LOW; - @Parameter(names = { "-property", "-P" }, description = "{name}={value}: Define a property for the report format.", converter = PropertyConverter.class) - private Properties properties = new Properties(); + @Parameter(names = { "-property", "-P" }, description = "{name}={value}: Define a property for the report format.", + converter = PropertyConverter.class) + private List properties = new ArrayList(); @Parameter(names = { "-reportfile", "-r" }, description = "Sends report output to a file; default to System.out.") private String reportfile = null; @@ -186,7 +189,11 @@ public class PMDParameters { } public Properties getProperties() { - return properties; + Properties result = new Properties(); + for (Properties p : properties) { + result.putAll(p); + } + return result; } public String getReportfile() { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java index 8979b9faad..6ba8e18eb3 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java @@ -35,7 +35,21 @@ public class PMDCommandLineInterfaceTest { Assert.assertEquals("output_folder", params.getProperties().getProperty("outputDir")); } - + + @Test + public void testMultipleProperties() { + PMDParameters params = new PMDParameters(); + String[] args = { "-d", "source_folder", "-f", "ideaj", "-P", "sourcePath=/home/user/source/", + "-P", "fileName=Foo.java", + "-P", "classAndMethodName=Foo.method", + "-R", "java-empty" }; + PMDCommandLineInterface.extractParameters(params, args, "PMD"); + + Assert.assertEquals("/home/user/source/", params.getProperties().getProperty("sourcePath")); + Assert.assertEquals("Foo.java", params.getProperties().getProperty("fileName")); + Assert.assertEquals("Foo.method", params.getProperties().getProperty("classAndMethodName")); + } + @Test public void testSetStatusCodeOrExit_DoExit() { exit.expectSystemExitWithStatus(0); diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 91054be8aa..7132a84fc4 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -21,5 +21,6 @@ * [#1372](https://sourceforge.net/p/pmd/bugs/1372/): False Negative for CloseResource rule. * [#1375](https://sourceforge.net/p/pmd/bugs/1375/): CloseResource not detected properly * [#1376](https://sourceforge.net/p/pmd/bugs/1376/): CompareObjectsWithEquals fails for type annotated method parameter +* [#1379](https://sourceforge.net/p/pmd/bugs/1379/): PMD CLI: Cannot specify multiple properties **API Changes:**