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 02a5804c98..4e15aa0f84 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 @@ -330,6 +330,8 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand if (pmdReporter.numErrors() > 0) { // processing errors are ignored return CliExitCode.ERROR; + } else if (stats.getNumErrors() > 0) { + return CliExitCode.VIOLATIONS_OR_PROCESSING_ERRORS; } else if (stats.getNumViolations() > 0 && configuration.isFailOnViolation()) { return CliExitCode.VIOLATIONS_FOUND; } else { diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java index 85958562fd..275da2b43b 100644 --- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java +++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java @@ -8,6 +8,7 @@ import static net.sourceforge.pmd.cli.internal.CliExitCode.ERROR; import static net.sourceforge.pmd.cli.internal.CliExitCode.OK; import static net.sourceforge.pmd.cli.internal.CliExitCode.USAGE_ERROR; import static net.sourceforge.pmd.cli.internal.CliExitCode.VIOLATIONS_FOUND; +import static net.sourceforge.pmd.cli.internal.CliExitCode.VIOLATIONS_OR_PROCESSING_ERRORS; import static net.sourceforge.pmd.util.CollectionUtil.listOf; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -318,6 +319,16 @@ class PmdCliTest extends BaseCliTest { )); } + @Test + void exitStatusWithProcessingErrors() throws Exception { + runCli(VIOLATIONS_OR_PROCESSING_ERRORS, "--use-version", "dummy-parserThrows", + "-d", srcDir.toString(), "-f", "text", "-R", RULESET_WITH_VIOLATION) + .verify(r -> { + r.checkStdOut(containsString("someSource.dummy\t-\tParseException: Parse exception: ohio")); + r.checkStdErr(containsString("An error occurred while executing PMD.")); + }); + } + @Test void testZipFileAsSource() throws Exception { Path zipArchive = createTemporaryZipArchive("sources.zip"); diff --git a/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml b/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml index 8049a8b63b..4243101b43 100644 --- a/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml +++ b/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml @@ -3,12 +3,12 @@ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> - Ruleset used by test RuleSetFactoryTest + Ruleset used by test net.sourceforge.pmd.cli.PmdCliTest + externalInfoUrl="${pmd.website.baseurl}/rules/test/RuleSetWithViolations.xml#ReportAllRootNodes"> Just for test 3 diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStats.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStats.java index eef7cd7dc5..9ac07837a3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStats.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStats.java @@ -23,10 +23,16 @@ public final class ReportStats { return new ReportStats(0, 0); } + /** + * Count of processing errors. + */ public int getNumErrors() { return numErrors; } + /** + * Count of found rule violations. + */ public int getNumViolations() { return numViolations; }