diff --git a/pmd-cli/pom.xml b/pmd-cli/pom.xml index 9ccf08f90a..d8edbdc297 100644 --- a/pmd-cli/pom.xml +++ b/pmd-cli/pom.xml @@ -21,7 +21,6 @@ - org.codehaus.mojo exec-maven-plugin diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java index fec55153fa..59370bed38 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java @@ -1,15 +1,22 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli; import net.sourceforge.pmd.cli.commands.internal.PmdRootCommand; + import picocli.CommandLine; -public class PmdCli { +public final class PmdCli { + + private PmdCli() { } public static void main(String[] args) { new CommandLine(new PmdRootCommand()).setCaseInsensitiveEnumValuesAllowed(true) - .execute("designer", "--version"); -// .execute("run", "--use-version", "scala-2.11", "--use-version", "apex", "--use-version", -// "ecmascript-latest", "-P", "foo=bar", "-R", "foo,bar", "-R", "baz", "-d", -// "src/main/java", "-f", "xml"); + .execute("designer", "-v"); + // .execute("run", "--use-version", "scala-2.11", "--use-version", "apex", "--use-version", + // "ecmascript-latest", "-P", "foo=bar", "-R", "foo,bar", "-R", "baz", "-d", + // "src/main/java", "-f", "xml"); } } diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractAnalysisPmdSubcommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractAnalysisPmdSubcommand.java index f79268af5e..2b413d1e9c 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractAnalysisPmdSubcommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractAnalysisPmdSubcommand.java @@ -1,3 +1,7 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import java.net.URI; @@ -23,7 +27,7 @@ public abstract class AbstractAnalysisPmdSubcommand extends AbstractPmdSubcomman arity = "1..*") protected List inputPaths; - @Option(names = { "--file-list" }, + @Option(names = "--file-list", description = "Path to a file containing a list of files to analyze, one path per line. " + "One of --dir, --file-list or --uri must be provided.") @@ -34,7 +38,7 @@ public abstract class AbstractAnalysisPmdSubcommand extends AbstractPmdSubcomman + "One of --dir, --file-list or --uri must be provided.") protected URI uri; - @Option(names = { "--fail-on-violation" }, + @Option(names = "--fail-on-violation", description = "By default PMD exits with status 4 if violations are found. " + "Disable this option with '--fail-on-violation false' to exit with 0 instead and just write the report.", defaultValue = "true", arity = "1") diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractPmdSubcommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractPmdSubcommand.java index 9cdf45315a..9adb9a040b 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractPmdSubcommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/AbstractPmdSubcommand.java @@ -1,3 +1,7 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import java.util.concurrent.Callable; @@ -6,6 +10,7 @@ import org.slf4j.event.Level; import net.sourceforge.pmd.cli.internal.ExecutionResult; import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration; + import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Option; import picocli.CommandLine.ParameterException; diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java index a9e7bb4c56..667f66a5d8 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java @@ -1,3 +1,7 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import java.io.BufferedWriter; @@ -16,6 +20,7 @@ import net.sourceforge.pmd.cpd.CPDConfiguration; import net.sourceforge.pmd.cpd.Language; import net.sourceforge.pmd.cpd.LanguageFactory; import net.sourceforge.pmd.cpd.Tokenizer; + import picocli.CommandLine.Command; import picocli.CommandLine.ITypeConverter; import picocli.CommandLine.Option; @@ -139,8 +144,8 @@ public class CpdCommand extends AbstractAnalysisPmdSubcommand { } } catch (IOException | RuntimeException e) { // TODO -// LOG.debug(e.toString(), e); -// LOG.error(CliMessages.errorDetectedMessage(1, CPDCommandLineInterface.PROGRAM_NAME)); + //LOG.debug(e.toString(), e); + //LOG.error(CliMessages.errorDetectedMessage(1, CPDCommandLineInterface.PROGRAM_NAME)); return ExecutionResult.ERROR; } diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/DesignerCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/DesignerCommand.java index d8c66b75a2..68aabc4b37 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/DesignerCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/DesignerCommand.java @@ -1,9 +1,14 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import net.sourceforge.pmd.cli.internal.ExecutionResult; import net.sourceforge.pmd.util.fxdesigner.DesignerStarter; import net.sourceforge.pmd.util.fxdesigner.DesignerStarter.ExitStatus; import net.sourceforge.pmd.util.fxdesigner.DesignerVersion; + import picocli.CommandLine.Command; import picocli.CommandLine.IVersionProvider; import picocli.CommandLine.Option; @@ -33,4 +38,4 @@ class DesignerVersionProvider implements IVersionProvider { return new String[] { "PMD Rule Designer " + DesignerVersion.getCurrentVersion() }; } -} \ No newline at end of file +} diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java index 535d64c6eb..2e7b312ec9 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java @@ -1,3 +1,7 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import java.io.IOException; @@ -32,6 +36,7 @@ import net.sourceforge.pmd.reporting.ReportStats; import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.log.MessageReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; + import picocli.CommandLine.Command; import picocli.CommandLine.ITypeConverter; import picocli.CommandLine.Option; @@ -85,7 +90,7 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.rulesets = rulesets; } - @Option(names = { "--ignore-list" }, + @Option(names = "--ignore-list", description = "Path to a file containing a list of files to exclude from the analysis, one path per line. " + "This option can be combined with --dir and --file-list.") public void setIgnoreListPath(final Path ignoreListPath) { @@ -106,24 +111,24 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.benchmark = benchmark; } - @Option(names = { "--short-names" }, description = "Prints shortened filenames in the report.") + @Option(names = "--short-names", description = "Prints shortened filenames in the report.") public void setShortnames(final boolean shortnames) { this.shortnames = shortnames; } - @Option(names = { "--show-suppressed" }, description = "Report should show suppressed rule violations.") + @Option(names = "--show-suppressed", description = "Report should show suppressed rule violations.") public void setShowSuppressed(final boolean showSuppressed) { this.showSuppressed = showSuppressed; } - @Option(names = { "--suppress-marker" }, + @Option(names = "--suppress-marker", description = "Specifies the string that marks a line which PMD should ignore.", defaultValue = "NOPMD") public void setSuppressMarker(final String suppressMarker) { this.suppressMarker = suppressMarker; } - @Option(names = { "--minimum-priority" }, + @Option(names = "--minimum-priority", description = "Rule priority threshold; rules with lower priority than configured here won't be used.%n" + "Valid values (case insensitive): ${COMPLETION-CANDIDATES}", defaultValue = "Low") @@ -145,24 +150,24 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.reportFile = reportFile; } - @Option(names = { "--use-version" }, defaultValue = "java-latest", + @Option(names = "--use-version", defaultValue = "java-latest", description = "Sepcify the language and version PMD should use.%nValid values: ${COMPLETION-CANDIDATES}%n", completionCandidates = PmdLanguageVersionCandidates.class, converter = PmdLanguageVersionConverter.class) public void setLanguageVersion(final List languageVersion) { // Make sure we only set 1 version per language languageVersion.stream().collect(Collectors.groupingBy(LanguageVersion::getLanguage)) - .forEach((l, list) -> { - if (list.size() > 1) { - throw new ParameterException(spec.commandLine(), "Can only set one version per language, " - + "but for language " + l.getName() + " multiple versions were provided " - + list.stream().map(PmdCommand::normalizeName).collect(Collectors.joining("', '", "'", "'"))); - } - }); + .forEach((l, list) -> { + if (list.size() > 1) { + throw new ParameterException(spec.commandLine(), "Can only set one version per language, " + + "but for language " + l.getName() + " multiple versions were provided " + + list.stream().map(PmdCommand::normalizeName).collect(Collectors.joining("', '", "'", "'"))); + } + }); this.languageVersion = languageVersion; } - @Option(names = { "--force-language" }, + @Option(names = "--force-language", description = "Force a language to be used for all input files, irrespective of file names. " + "When using this option, the automatic language selection by extension is disabled, and PMD " + "tries to parse all input files with the given language's parser. " @@ -172,7 +177,7 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.forceLanguage = forceLanguage; } - @Option(names = { "--aux-classpath" }, + @Option(names = "--aux-classpath", description = "Specifies the classpath for libraries used by the source code. " + "This is used to resolve types in Java source files. The platform specific path delimiter " + "(\":\" on Linux, \";\" on Windows) is used to separate the entries. " @@ -182,13 +187,13 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.auxClasspath = auxClasspath; } - @Option(names = { "--no-ruleset-compatibility" }, + @Option(names = "--no-ruleset-compatibility", description = "Disable the ruleset compatibility filter. The filter is active by default and tries automatically 'fix' old ruleset files with old rule names") public void setNoRuleSetCompatibility(final boolean noRuleSetCompatibility) { this.noRuleSetCompatibility = noRuleSetCompatibility; } - @Option(names = { "--cache" }, + @Option(names = "--cache", description = "Specify the location of the cache file for incremental analysis. " + "This should be the full path to the file, including the desired file name (not just the parent directory). " + "If the file doesn't exist, it will be created on the first run. The file will be overwritten on each run " @@ -197,7 +202,7 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.cacheLocation = cacheLocation; } - @Option(names = { "--no-cache" }, description = "Explicitly disable incremental analysis. The '-cache' option is ignored if this switch is present in the command line.") + @Option(names = "--no-cache", description = "Explicitly disable incremental analysis. The '-cache' option is ignored if this switch is present in the command line.") public void setNoCache(final boolean noCache) { this.noCache = noCache; } diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java index aabf9f16a6..18c7c53c12 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java @@ -1,6 +1,11 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.commands.internal; import net.sourceforge.pmd.PMDVersion; + import picocli.CommandLine.Command; import picocli.CommandLine.IVersionProvider; @@ -8,7 +13,7 @@ import picocli.CommandLine.IVersionProvider; versionProvider = PMDVersionProvider.class, exitCodeListHeading = "Exit Codes:%n", exitCodeList = { "0:Succesful analysis, no violations found", "1:An unexpected error occurred during execution", - "2:Usage error, please refer to the command help", "4:Successful analysis, at least 1 violation found" }, + "2:Usage error, please refer to the command help", "4:Successful analysis, at least 1 violation found" }, subcommands = { PmdCommand.class, CpdCommand.class, DesignerCommand.class }) public class PmdRootCommand { @@ -20,4 +25,4 @@ class PMDVersionProvider implements IVersionProvider { public String[] getVersion() throws Exception { return new String[] { "PMD " + PMDVersion.VERSION }; } -} \ No newline at end of file +} diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ExecutionResult.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ExecutionResult.java index f0880b8ace..3c813c9bdb 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ExecutionResult.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ExecutionResult.java @@ -1,3 +1,7 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.cli.internal; // TODO : Unify with PMD.StatusCode / CPD.StatusCode