-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[cli] Add exit code for processing errors #4991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adangel
merged 17 commits into
pmd:master
from
adangel:cli-exit-codes-processing-errors
Jun 27, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
468266d
[cli] CPD: Add new exit code 5: VIOLATIONS_OR_PROCESSING_ERRORS
adangel 0fc23fc
[cli] PMD: Add new exit code 5: VIOLATIONS_OR_PROCESSING_ERRORS
adangel e667bf6
[cli] Add new param "--no-fail-on-processing-error"
adangel d0a913e
[cli] Move failOnViolation to AbstractConfiguration
adangel a63cfb8
[doc] New exit code 5, --no-fail-on-processing-error
adangel 95215ec
Fix checkstyle
adangel ab82f28
Fix integration test
adangel 15cc64f
Fix PMD errors in compat6
adangel facbdd4
[doc] Update last_updated tags
adangel 2d9385f
Merge branch 'master' into cli-exit-codes-processing-errors
adangel 06efd65
[cli] Rename new parameter to be `--no-fail-on-error`
adangel b624b41
[ant] Add new CPD parameter failOnError
adangel 10c78f2
[cpd] Deprecate skipLexicalErrors
adangel 603187e
Update javadoc
adangel 0fe477e
Fixups from PR review
adangel 724b3af
Merge branch 'master' into cli-exit-codes-processing-errors
adangel d285082
Updated doc to mention 7.3.0
adangel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ tags: [userdocs] | |
keywords: [command, line, options, help, formats, renderers] | ||
permalink: pmd_userdocs_cli_reference.html | ||
author: Tom Copeland <[email protected]>, Xavier Le Vourch <[email protected]>, Juan Martín Sotuyo Dodero <[email protected]> | ||
last_updated: June 2024 (7.3.0) | ||
--- | ||
|
||
|
||
|
@@ -19,7 +20,6 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
<th>Default value</th> | ||
<th>Applies to</th> | ||
</tr> | ||
|
||
{% include custom/cli_option_row.html options="--rulesets,-R" | ||
option_arg="refs" | ||
description="Path to a ruleset xml file. The path may reference | ||
|
@@ -55,7 +55,6 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
(\":\" on Linux, \";\" on Windows) is used to separate the entries. | ||
Alternatively, a single `file:` URL | ||
to a text file containing path elements on consecutive lines can be specified. | ||
|
||
<p>See also [Providing the auxiliary classpath](pmd_languages_java.html#providing-the-auxiliary-classpath).</p>" | ||
languages="Java" | ||
%} | ||
|
@@ -80,10 +79,15 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
The valid values are the standard character sets of `java.nio.charset.Charset`." | ||
default="UTF-8" | ||
%} | ||
{% include custom/cli_option_row.html options="--[no-]fail-on-error" | ||
description="Specifies whether PMD exits with non-zero status if recoverable errors occurred. | ||
By default PMD exits with status 5 if recoverable errors occurred (whether there are violations or not). | ||
Disable this option with `--no-fail-on-error` to exit with 0 instead. In any case, a report with the found violations will be written." | ||
%} | ||
{% include custom/cli_option_row.html options="--[no-]fail-on-violation" | ||
description="Specifies whether PMD exits with non-zero status if violations are found. | ||
By default PMD exits with status 4 if violations are found. | ||
Disable this feature with `--no-fail-on-violation` to exit with 0 instead and just output the report." | ||
Disable this feature with `--no-fail-on-violation` to exit with 0 instead. In any case a report with the found violations will be written." | ||
%} | ||
{% include custom/cli_option_row.html options="--file-list" | ||
option_arg="filepath" | ||
|
@@ -98,9 +102,7 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
by extension is disabled and PMD tries to parse all files with | ||
the given language `<lang>`. Parsing errors are ignored and unparsable files | ||
are skipped. | ||
|
||
<p>Use `--use-version` to specify the language version to use, if it is not the default.</p> | ||
|
||
<p>This option allows to use the xml language for files, that don't | ||
use xml as extension. See [example](#analyze-other-xml-formats) below.</p>" | ||
%} | ||
|
@@ -125,7 +127,7 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
{% include custom/cli_option_row.html options="--minimum-priority" | ||
option_arg="priority" | ||
description="Rule priority threshold; rules with lower priority than configured here won't be used. | ||
Valid values (case insensitive): High, Medium_High, Medium, Medium_Low, Low. | ||
Valid values (case-insensitive): High, Medium_High, Medium, Medium_Low, Low. | ||
An integer between 1 (High) and 5 (Low) is also supported. See [Configuring rules](pmd_userdocs_configuring_rules.html) | ||
on how to override priorities in custom rulesets." | ||
default="Low" | ||
|
@@ -141,7 +143,7 @@ The tool comes with a rather extensive help text, simply running with `--help`! | |
description="Enables / disable progress bar indicator of live analysis progress. This ie enabled by default." | ||
%} | ||
{% include custom/cli_option_row.html options="--property,-P" | ||
option_arg="name>=<value" | ||
option_arg="name>=<value" | ||
description="Specifies a property for the report renderer. The option can be specified several times. | ||
<p>Using `--help` will provide a complete list of supported properties for each report format</p>" | ||
%} | ||
|
@@ -208,16 +210,23 @@ Or you can set the environment variable `CLASSPATH` before starting PMD, e.g. | |
|
||
## Exit Status | ||
|
||
Please note that if PMD detects any violations, it will exit with status 4 (since 5.3). | ||
Please note that if PMD detects any violations, it will exit with status 4 (since 5.3) or 5 (since 7.3.0). | ||
This behavior has been introduced to ease PMD integration into scripts or hooks, such as SVN hooks. | ||
|
||
<table> | ||
<tr><td>0</td><td>Everything is fine, no violations found.</td></tr> | ||
<tr><td>0</td><td>Everything is fine, no violations found and no recoverable error occurred.</td></tr> | ||
<tr><td>1</td><td>PMD exited with an exception.</td></tr> | ||
<tr><td>2</td><td>Usage error. Command-line parameters are invalid or missing.</td></tr> | ||
<tr><td>4</td><td>At least one violation has been detected, unless <code>--no-fail-on-violation</code> is set.</td></tr> | ||
<tr><td>4</td><td>At least one violation has been detected, unless <code>--no-fail-on-violation</code> is set.<p>Since PMD 5.3.</p></td></tr> | ||
<tr><td>5</td><td>At least one recoverable error has occurred. There might be additionally zero or more violations detected. | ||
To ignore recoverable errors, use <code>--no-fail-on-error</code>.<p>Since PMD 7.3.0.</p></td></tr> | ||
</table> | ||
|
||
{%include note.html content="If PMD exits with 5, then PMD had either trouble parsing one or more files or a rule failed with an exception. | ||
That means, that either no violations for the entire file or for that rule are reported. These cases can be considered as false-negatives. | ||
In any case, the root cause should be investigated. If it's a problem in PMD itself, please create a bug report. Recoverable errors | ||
are usually part of the generated PMD report." %} | ||
|
||
## Logging | ||
|
||
PMD internally uses [slf4j](https://www.slf4j.org/) and ships with slf4j-simple as the logging implementation. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ tags: [cpd, userdocs] | |
summary: "Learn how to use CPD, the copy-paste detector shipped with PMD." | ||
permalink: pmd_userdocs_cpd.html | ||
author: Tom Copeland <[email protected]> | ||
last_updated: August 2023 (7.0.0) | ||
last_updated: June 2024 (7.3.0) | ||
--- | ||
|
||
## Overview | ||
|
@@ -132,8 +132,8 @@ exactly identical. | |
description="Don't scan subdirectories. By default, subdirectories are considered." | ||
%} | ||
{% include custom/cli_option_row.html options="--skip-lexical-errors" | ||
description="Skip files which can't be tokenized due to invalid characters instead of aborting CPD. | ||
By default, CPD analysis is stopped on the first error." | ||
description="<span class='label label-primary'>Deprecated</span> Skip files which can't be tokenized due to invalid characters instead of aborting CPD. | ||
By default, CPD analysis is stopped on the first error. This is deprecated. Use `--fail-on-error` instead." | ||
%} | ||
{% include custom/cli_option_row.html options="--format,-f" | ||
option_arg="format" | ||
|
@@ -150,6 +150,11 @@ exactly identical. | |
If the root path is mentioned (e.g. \"/\" or \"C:\\\"), then the paths will be rendered | ||
as absolute." | ||
%} | ||
{% include custom/cli_option_row.html options="--[no-]fail-on-error" | ||
description="Specifies whether CPD exits with non-zero status if recoverable errors occurred. | ||
By default CPD exits with status 5 if recoverable errors occurred (whether there are duplications or not). | ||
Disable this option with `--no-fail-on-error` to exit with 0 instead. In any case, a report with the found duplications will be written." | ||
%} | ||
{% include custom/cli_option_row.html options="--[no-]fail-on-violation" | ||
description="Specifies whether CPD exits with non-zero status if violations are found. | ||
By default CPD exits with status 4 if violations are found. | ||
|
@@ -279,16 +284,22 @@ If you specify a source directory but don't want to scan the sub-directories, yo | |
|
||
### Exit status | ||
|
||
Please note that if CPD detects duplicated source code, it will exit with status 4 (since 5.0). | ||
Please note that if CPD detects duplicated source code, it will exit with status 4 (since 5.0) or 5 (since 7.3.0). | ||
This behavior has been introduced to ease CPD integration into scripts or hooks, such as SVN hooks. | ||
|
||
<table> | ||
<tr><td>0</td><td>Everything is fine, no code duplications found.</td></tr> | ||
<tr><td>0</td><td>Everything is fine, no code duplications found and no recoverable errors occurred.</td></tr> | ||
<tr><td>1</td><td>CPD exited with an exception.</td></tr> | ||
<tr><td>2</td><td>Usage error. Command-line parameters are invalid or missing.</td></tr> | ||
<tr><td>4</td><td>At least one code duplication has been detected unless <code>--no-fail-on-violation</code> is set.</td></tr> | ||
<tr><td>4</td><td>At least one code duplication has been detected unless <code>--no-fail-on-violation</code> is set.<p>Since PMD 5.0.</p></td></tr> | ||
<tr><td>5</td><td>At least one recoverable error has occurred. There might be additionally zero or more duplications detected. | ||
To ignore recoverable errors, use <code>--no-fail-on-error</code>.<p>Since PMD 7.3.0.</p></td></tr> | ||
</table> | ||
|
||
{%include note.html content="If PMD exits with 5, then PMD had trouble lexing one or more files. | ||
That means, that no duplications for the entire file are reported. This can be considered as false-negative. | ||
In any case, the root cause should be investigated. If it's a problem in PMD itself, please create a bug report." %} | ||
|
||
## Logging | ||
|
||
PMD internally uses [slf4j](https://www.slf4j.org/) and ships with slf4j-simple as the logging implementation. | ||
|
@@ -390,6 +401,10 @@ Andy Glover wrote an Ant task for CPD; here's how to use it: | |
keep their encoding.<br /> | ||
If not specified, CPD uses the system default encoding." | ||
%} | ||
{% include custom/cli_option_row.html options="failOnError" | ||
description="Whether to fail the build if any errors occurred while processing the files. Since PMD 7.3.0." | ||
default="true" | ||
%} | ||
{% include custom/cli_option_row.html options="format" | ||
description="The format of the report (e.g. `csv`, `text`, `xml`)." | ||
default="text" | ||
|
@@ -424,8 +439,10 @@ Andy Glover wrote an Ant task for CPD; here's how to use it: | |
default="false" | ||
%} | ||
{% include custom/cli_option_row.html options="skipLexicalErrors" | ||
description="Skip files which can't be tokenized due to invalid characters instead of aborting CPD." | ||
default="false" | ||
description="<span class='label label-primary'>Deprecated</span> Skip files which can't be tokenized | ||
due to invalid characters instead of aborting CPD. This parameter is deprecated and | ||
ignored since PMD 7.3.0. It is now by default true. Use `failOnError` instead to fail the build." | ||
default="true" | ||
%} | ||
{% include custom/cli_option_row.html options="skipBlocks" | ||
description="Enables or disabled skipping of blocks like a pre-processor. See also option skipBlocksPattern." | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ author: > | |
David Dixon-Peugh <[email protected]>, | ||
Tom Copeland <[email protected]>, | ||
Xavier Le Vourch <[email protected]> | ||
last_updated: June 2024 (7.3.0) | ||
--- | ||
|
||
## PMD | ||
|
@@ -63,8 +64,8 @@ The examples below won't repeat this taskdef element, as this is always required | |
<td>Yes, unless the ruleset nested element is used</td> | ||
</tr> | ||
<tr> | ||
<td>failonerror</td> | ||
<td>Whether or not to fail the build if any errors occur while processing the files</td> | ||
<td>failOnError</td> | ||
<td>Whether or not to fail the build if any recoverable errors occurred while analyzing files.</td> | ||
<td>No</td> | ||
</tr> | ||
<tr> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.