[cli] PMD: Add new exit code 5: VIOLATIONS_OR_PROCESSING_ERRORS

This commit is contained in:
Andreas Dangel 2024-05-03 09:23:10 +02:00
parent 468266d58d
commit 0fc23fc9f4
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
4 changed files with 21 additions and 2 deletions

View File

@ -330,6 +330,8 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
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 {

View File

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

View File

@ -3,12 +3,12 @@
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Ruleset used by test RuleSetFactoryTest
Ruleset used by test net.sourceforge.pmd.cli.PmdCliTest
</description>
<rule name="ReportAllRootNodes" language="dummy" since="1.0" message="Violation from ReportAllRootNodes"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/test/TestRuleset3.xml#Ruleset3Rule1">
externalInfoUrl="${pmd.website.baseurl}/rules/test/RuleSetWithViolations.xml#ReportAllRootNodes">
<description>Just for test</description>
<priority>3</priority>
<properties>

View File

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