Skip to content

Commit

Permalink
[MPMD-279] Improve documentation of maxAllowedViolations
Browse files Browse the repository at this point in the history
Submitted by: Jeffrey Bennett
  • Loading branch information
adangel committed Apr 6, 2019
1 parent 119218c commit a9c5840
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public abstract class AbstractPmdViolationCheckMojo<D>

/**
* Whether to fail the build if the validation check fails.
* The properties {@code failurePriority} and {@code maxAllowedViolations} control
* under which conditions exactly the build should be failed.
*/
@Parameter( property = "pmd.failOnViolation", defaultValue = "true", required = true )
protected boolean failOnViolation;
Expand Down Expand Up @@ -88,7 +90,12 @@ public abstract class AbstractPmdViolationCheckMojo<D>
private String excludeFromFailureFile;

/**
* The maximum number of violations allowed before execution fails.
* The maximum number of failures allowed before execution fails.
* Used in conjunction with {@code failOnViolation=true} and utilizes {@code failurePriority}.
* This value has no meaning if {@code failOnViolation=false}.
* If the number of failures is greater than this number, the build will be failed.
* If the number of failures is less than or equal to this value,
* then the build will not be failed.
*
* @since 3.10.0
*/
Expand Down Expand Up @@ -157,6 +164,12 @@ protected void executeCheck( final String filename, final String tagName, final
}

this.getLog().info( message );

if ( failureCount > 0 && isFailOnViolation() && failureCount <= getMaxAllowedViolations() )
{
this.getLog().info( "The build is not failed, since " + getMaxAllowedViolations()
+ " violations are allowed (maxAllowedViolations)." );
}
}
catch ( final IOException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ public PmdViolationCheckMojo()
}

/**
* What priority level to fail the build on. Failures at or above this level will stop the build. Anything below
* will be warnings and will be displayed in the build output if verbose=true. Note: Minimum Priority = 5 Maximum
* Priority = 0
* What priority level to fail the build on.
* PMD violations are assigned a priority from 1 (most severe) to 5 (least severe) according the
* the rule's priority.
* Violations at or less than this priority level are considered failures and will fail
* the build if {@code failOnViolation=true} and the count exceeds {@code maxAllowedViolations}.
* The other violations will be regarded as warnings and will be displayed in the build output
* if {@code verbose=true}.
* Setting a value of 5 will treat all violations as failures, which may cause the build to fail.
* Setting a value of 1 will treat all violations as warnings.
* Only values from 1 to 5 are valid.
*/
@Parameter( property = "pmd.failurePriority", defaultValue = "5", required = true )
private int failurePriority;
Expand Down
31 changes: 31 additions & 0 deletions src/site/fml/faq.fml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,36 @@ under the License.
</p>
</answer>
</faq>
<faq id="violations failures warnings">
<question>
What's the difference between violations, failures and warnings and when is a build failing?
</question>
<answer>
<p>
PMD reports violations. These violations originate from rules - the rules, that are enabled in the
configured ruleset (see property <a href="pmd-mojo.html#rulesets">rulesets</a>). Each rule has a assigned
priority (1 - high, 2 - medium-high, 3 - medium, 4 - medium-low, 5 - low). This priority is also used
for the violation.
</p>
<p>
Violations with a high enough priority can fail the build when using the <a href="check-mojo.html">check</a> goal.
These violations are called "failures". The exact priority, when to fail the build, is configured via the property
<a href="check-mojo.html#failurePriority">failurePriority</a>.
</p>
<p>
Violations, that have a priority too low to fail the build, are called "warnings". These warnings appear
in the report and are displayed in the build output, if the property <a href="check-mojo.html#verbose">verbose</a>
is enabled.
</p>
<p>
With the property <a href="check-mojo.html#failOnViolation">failOnViolation</a> the build failure
can be entirely disabled. This is most useful at command line with <code>-Dpmd.failOnViolation=false</code>.
</p>
<p>
With the property <a href="check-mojo.html#maxAllowedViolations">maxAllowedViolations</a> one can configure
how many failures are allowed, before the build is failed.
</p>
</answer>
</faq>
</part>
</faqs>

0 comments on commit a9c5840

Please sign in to comment.