protected void executeCheck()

in src/main/java/org/apache/maven/plugins/pmd/AbstractPmdViolationCheckMojo.java [122:173]


    protected void executeCheck(
            final String filename, final String tagName, final String key, 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()) {
            getLog().info("PMD version: " + AbstractPmdReport.getPmdVersion());

            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, key, outputFile);

                getLog().debug("PMD failureCount: " + failureCount + ", warningCount: " + warningCount);

                if (failureCount > getMaxAllowedViolations() && isFailOnViolation()) {
                    throw new MojoFailureException(message);
                }

                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 | XmlPullParserException e) {
                throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
            }
        } else {
            throw new MojoFailureException("Unable to perform check, " + "unable to find " + outputFile);
        }
    }