in src/main/java/org/apache/maven/plugins/pmd/AbstractPmdViolationCheckMojo.java [123:173]
protected void executeCheck(
final String filename, final String analyzerName, final String failureName, final int failurePriority)
throws MojoFailureException, MojoExecutionException {
if (aggregate && !project.isExecutionRoot()) {
return;
}
if (!isAggregator() && "pom".equalsIgnoreCase(project.getPackaging())) {
return;
}
excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
final File outputFile = new File(targetDirectory, filename);
if (outputFile.exists()) {
try {
final ViolationDetails<D> violations = getViolations(outputFile, failurePriority);
final List<D> failures = violations.getFailureDetails();
final List<D> warnings = violations.getWarningDetails();
if (verbose) {
printErrors(failures, warnings);
}
final int failureCount = failures.size();
final int warningCount = warnings.size();
final String message = getMessage(failureCount, warningCount, analyzerName, failureName, outputFile);
if (failureCount > getMaxAllowedViolations() && isFailOnViolation()) {
throw new MojoFailureException(message);
}
if (!message.isEmpty()) {
this.getLog().warn(message);
}
if (failureCount > 0 && isFailOnViolation() && failureCount <= getMaxAllowedViolations()) {
this.getLog()
.info("The build has not failed because " + getMaxAllowedViolations()
+ " violations are allowed (maxAllowedViolations).");
}
} catch (final IOException | XmlPullParserException e) {
throw new MojoExecutionException(
"Unable to read " + analyzerName + " results XML: " + outputFile.getAbsolutePath(), e);
}
} else {
throw new MojoFailureException("Unable to perform check, " + "unable to find " + outputFile);
}
}