#1379 PMD CLI: Cannot specify multiple properties

This commit is contained in:
Andreas Dangel
2015-07-13 19:50:40 +02:00
parent 617ca01a68
commit df14ea9c95
3 changed files with 26 additions and 4 deletions

View File

@ -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> properties = new ArrayList<Properties>();
@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() {

View File

@ -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);

View File

@ -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:**