Merge branch 'pr-2745' into master

[core] Fix a NPE in buildUsageText #2745
This commit is contained in:
Andreas Dangel
2020-08-31 17:55:11 +02:00
3 changed files with 17 additions and 23 deletions

View File

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

View File

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

View File

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