Merge branch 'pr-2745' into master
[core] Fix a NPE in buildUsageText #2745
This commit is contained in:
@ -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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#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)
|
* [#2750](https://github.com/pmd/pmd/pull/2750): \[dart] \[cpd] Cpd Dart escaped dollar - [Maikel Steneker](https://github.com/maikelsteneker)
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ public final class PMDCommandLineInterface {
|
|||||||
jcommander.parse(args);
|
jcommander.parse(args);
|
||||||
if (arguments.isHelp()) {
|
if (arguments.isHelp()) {
|
||||||
jcommander.usage();
|
jcommander.usage();
|
||||||
System.out.println(buildUsageText(jcommander));
|
System.out.println(buildUsageText());
|
||||||
setStatusCodeOrExit(NO_ERRORS_STATUS);
|
setStatusCodeOrExit(NO_ERRORS_STATUS);
|
||||||
}
|
}
|
||||||
} catch (ParameterException e) {
|
} catch (ParameterException e) {
|
||||||
jcommander.usage();
|
jcommander.usage();
|
||||||
System.out.println(buildUsageText(jcommander));
|
System.out.println(buildUsageText());
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
setStatusCodeOrExit(ERROR_STATUS);
|
setStatusCodeOrExit(ERROR_STATUS);
|
||||||
}
|
}
|
||||||
@ -54,19 +54,6 @@ public final class PMDCommandLineInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String buildUsageText() {
|
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 ? -
|
// TODO: Externalize that to a file available within the classpath ? -
|
||||||
// with a poor's man templating ?
|
// with a poor's man templating ?
|
||||||
String fullText = PMD.EOL + "Mandatory arguments:" + PMD.EOL + "1) A java source code filename or directory"
|
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;
|
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()
|
fullText += "Available report formats and their configuration properties are:" + PMD.EOL + getReports()
|
||||||
+ PMD.EOL + getExamples() + PMD.EOL + PMD.EOL + PMD.EOL;
|
+ PMD.EOL + getExamples() + PMD.EOL + PMD.EOL + PMD.EOL;
|
||||||
|
|
||||||
fullText += usage.toString();
|
|
||||||
return fullText;
|
return fullText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static String buildUsageText(JCommander jcommander) {
|
||||||
|
return buildUsageText();
|
||||||
|
}
|
||||||
|
|
||||||
private static String getExamples() {
|
private static String getExamples() {
|
||||||
return getWindowsExample() + getUnixExample();
|
return getWindowsExample() + getUnixExample();
|
||||||
}
|
}
|
||||||
|
@ -81,4 +81,11 @@ public class PMDCommandLineInterfaceTest {
|
|||||||
PMDCommandLineInterface.setStatusCodeOrExit(0);
|
PMDCommandLineInterface.setStatusCodeOrExit(0);
|
||||||
Assert.assertEquals(System.getProperty(PMDCommandLineInterface.STATUS_CODE_PROPERTY), "0");
|
Assert.assertEquals(System.getProperty(PMDCommandLineInterface.STATUS_CODE_PROPERTY), "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildUsageText() {
|
||||||
|
// no exception..
|
||||||
|
Assert.assertNotNull(PMDCommandLineInterface.buildUsageText());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user