diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 34c6d6924b..ef6801164a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -190,10 +190,11 @@ are deprecated as internal API. * [#2729](https://github.com/pmd/pmd/pull/2729): Cleanup: use print instead of printf if no format exists - [XenoAmess](https://github.com/XenoAmess) * [#2730](https://github.com/pmd/pmd/pull/2730): Cleanup: StringBuilder issues - [XenoAmess](https://github.com/XenoAmess) * [#2731](https://github.com/pmd/pmd/pull/2731): Cleanup: avoid compiling Patterns repeatedly - [XenoAmess](https://github.com/XenoAmess) -* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess) -* [#2733](https://github.com/pmd/pmd/pull/2733): Cleanup: Collection::addAll issues - [XenoAmess](https://github.com/XenoAmess) +* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess) +* [#2733](https://github.com/pmd/pmd/pull/2733): Cleanup: Collection::addAll issues - [XenoAmess](https://github.com/XenoAmess) * [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess) * [#2744](https://github.com/pmd/pmd/pull/2744): Cleanup: fix typos - [XenoAmess](https://github.com/XenoAmess) +* [#2745](https://github.com/pmd/pmd/pull/2745): \[core] Fix a NPE in buildUsageText - [XenoAmess](https://github.com/XenoAmess) * [#2749](https://github.com/pmd/pmd/pull/2749): \[dart] \[cpd] Improvements for Dart interpolated strings - [Maikel Steneker](https://github.com/maikelsteneker) * [#2750](https://github.com/pmd/pmd/pull/2750): \[dart] \[cpd] Cpd Dart escaped dollar - [Maikel Steneker](https://github.com/maikelsteneker) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java index 8642562b11..04daf8b5dc 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java @@ -41,12 +41,12 @@ public final class PMDCommandLineInterface { jcommander.parse(args); if (arguments.isHelp()) { jcommander.usage(); - System.out.println(buildUsageText(jcommander)); + System.out.println(buildUsageText()); setStatusCodeOrExit(NO_ERRORS_STATUS); } } catch (ParameterException e) { jcommander.usage(); - System.out.println(buildUsageText(jcommander)); + System.out.println(buildUsageText()); System.err.println(e.getMessage()); setStatusCodeOrExit(ERROR_STATUS); } @@ -54,19 +54,6 @@ public final class PMDCommandLineInterface { } public static String buildUsageText() { - return buildUsageText(null); - } - - public static String buildUsageText(JCommander jcommander) { - StringBuilder usage = new StringBuilder(); - - StringBuilder allCommandsDescription = null; - if (jcommander != null && jcommander.getCommands() != null) { - for (String command : jcommander.getCommands().keySet()) { - allCommandsDescription.append(jcommander.getCommandDescription(command)).append(PMD.EOL); - } - } - // TODO: Externalize that to a file available within the classpath ? - // with a poor's man templating ? String fullText = PMD.EOL + "Mandatory arguments:" + PMD.EOL + "1) A java source code filename or directory" @@ -77,18 +64,17 @@ public final class PMDCommandLineInterface { fullText += supportedVersions() + PMD.EOL; - if (allCommandsDescription != null) { - fullText += "Optional arguments that may be put before or after the mandatory arguments: " + PMD.EOL - + allCommandsDescription + PMD.EOL; - } - fullText += "Available report formats and their configuration properties are:" + PMD.EOL + getReports() + PMD.EOL + getExamples() + PMD.EOL + PMD.EOL + PMD.EOL; - fullText += usage.toString(); return fullText; } + @Deprecated + public static String buildUsageText(JCommander jcommander) { + return buildUsageText(); + } + private static String getExamples() { return getWindowsExample() + getUnixExample(); } 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 ef775a2f7a..432e96d623 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 @@ -81,4 +81,11 @@ public class PMDCommandLineInterfaceTest { PMDCommandLineInterface.setStatusCodeOrExit(0); Assert.assertEquals(System.getProperty(PMDCommandLineInterface.STATUS_CODE_PROPERTY), "0"); } + + @Test + public void testBuildUsageText() { + // no exception.. + Assert.assertNotNull(PMDCommandLineInterface.buildUsageText()); + } + }