From 7bc5810f7a3cc7b7d487e20b4134e329da05ba14 Mon Sep 17 00:00:00 2001 From: Romain PELISSE Date: Wed, 14 Nov 2012 22:05:52 +0100 Subject: [PATCH] pmd: adding changes suggested by Ryan Gustavson --- .../pmd/cli/PMDCommandLineInterface.java | 11 ++++------- .../net/sourceforge/pmd/cli/PMDParameters.java | 16 +++++----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pmd/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java b/pmd/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java index 94818e6baa..85a3713f37 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java +++ b/pmd/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Properties; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.RendererFactory; @@ -104,13 +105,9 @@ public class PMDCommandLineInterface { } private static String supportedVersions() { - String supportedVersion = "Languages and version suported:" + PMD.EOL; - for ( LanguageVersion version : LanguageVersion.values() ) { - supportedVersion += version.getName() + ", "; - } - supportedVersion += PMD.EOL; - supportedVersion += "Note that some language are not supported by PMD - only by CPD" + PMD.EOL; - return supportedVersion; + return "Languages and version suported:" + PMD.EOL + + Language.commaSeparatedTerseNames(Language.findWithRuleSupport()) + PMD.EOL + + "Note that some language are not supported by PMD - only by CPD" + PMD.EOL; } /** diff --git a/pmd/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index 848cf60edf..9ebb73f003 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -4,12 +4,14 @@ import java.util.Properties; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.RulePriority; +import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import com.beust.jcommander.IParameterValidator; import com.beust.jcommander.IStringConverter; import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; +import com.beust.jcommander.validators.PositiveInteger; public class PMDParameters { @@ -31,7 +33,7 @@ public class PMDParameters { @Parameter(names= {"-encoding", "-e"} , description = "specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8)") private String encoding = "UTF-8"; - @Parameter(names = {"-threads", "-t"}, description = "set the number of threads used by PMD", validateWith=PositiveIntegerValidator.class) + @Parameter(names = {"-threads", "-t"}, description = "set the number of threads used by PMD", validateWith=PositiveInteger.class) private Integer threads = 1; @Parameter(names = {"-benchmark", "-b"}, description = "Benchmark mode - output a benchmark report upon completion; default to System.err") @@ -59,10 +61,10 @@ public class PMDParameters { private String reportfile = null; @Parameter(names = {"-version","-v"}, description = "specify version of a language PMD should use") - private String version = "1.7"; + private String version = Language.getDefaultLanguage().getDefaultVersion().getVersion(); @Parameter(names = {"-language", "-l"}, description = "specify version of a language PMD should use") - private String language = "java"; + private String language = Language.getDefaultLanguage().getTerseName(); @Parameter(names = "auxclasspath", description = "specifies the classpath for libraries used by the source code (used by type resolution)\n(alternatively, a 'file://' URL to a text file containing path elements on consecutive lines") private String auxclasspath; @@ -83,14 +85,6 @@ public class PMDParameters { return properties; } } - - class PositiveIntegerValidator implements IParameterValidator { - - public void validate(String name, String value) throws ParameterException { - if ( Integer.valueOf(value) < 0 ) - throw new ParameterException("Parameter " + name + " should be positive (found " + value +")"); - } - } class RulePriorityConverter implements IStringConverter {