private PmdResult run()

in src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java [153:255]


    private PmdResult run() throws MavenReportException {
        setupPmdLogging(request.isShowPmdLog(), request.getLogLevel());

        PMDConfiguration configuration = new PMDConfiguration();
        LanguageVersion languageVersion = null;
        Language language = LanguageRegistry.findLanguageByTerseName(
                request.getLanguage() != null ? request.getLanguage() : "java");
        if (language == null) {
            throw new MavenReportException("Unsupported language: " + request.getLanguage());
        }
        if (request.getLanguageVersion() != null) {
            languageVersion = language.getVersion(request.getLanguageVersion());
            if (languageVersion == null) {
                throw new MavenReportException("Unsupported targetJdk value '" + request.getLanguageVersion() + "'.");
            }
        } else {
            languageVersion = language.getDefaultVersion();
        }
        LOG.debug("Using language " + languageVersion);
        configuration.setDefaultLanguageVersion(languageVersion);

        if (request.getSourceEncoding() != null) {
            configuration.setSourceEncoding(request.getSourceEncoding());
        }

        configuration.prependAuxClasspath(request.getAuxClasspath());

        if (request.getSuppressMarker() != null) {
            configuration.setSuppressMarker(request.getSuppressMarker());
        }
        if (request.getAnalysisCacheLocation() != null) {
            configuration.setAnalysisCacheLocation(request.getAnalysisCacheLocation());
            LOG.debug("Using analysis cache location: " + request.getAnalysisCacheLocation());
        } else {
            configuration.setIgnoreIncrementalAnalysis(true);
        }

        configuration.setRuleSets(request.getRulesets());
        configuration.setMinimumPriority(RulePriority.valueOf(request.getMinimumPriority()));
        if (request.getBenchmarkOutputLocation() != null) {
            configuration.setBenchmark(true);
        }
        List<File> files = request.getFiles();

        Report report = null;

        if (request.getRulesets().isEmpty()) {
            LOG.debug("Skipping PMD execution as no rulesets are defined.");
        } else {
            if (request.getBenchmarkOutputLocation() != null) {
                TimeTracker.startGlobalTracking();
            }

            try {
                report = processFilesWithPMD(configuration, files);
            } finally {
                if (request.getAuxClasspath() != null) {
                    ClassLoader classLoader = configuration.getClassLoader();
                    if (classLoader instanceof Closeable) {
                        Closeable closeable = (Closeable) classLoader;
                        try {
                            closeable.close();
                        } catch (IOException ex) {
                            // ignore
                        }
                    }
                }
                if (request.getBenchmarkOutputLocation() != null) {
                    TimingReport timingReport = TimeTracker.stopGlobalTracking();
                    writeBenchmarkReport(
                            timingReport, request.getBenchmarkOutputLocation(), request.getOutputEncoding());
                }
            }
        }

        if (report != null && !report.getProcessingErrors().isEmpty()) {
            List<Report.ProcessingError> errors = report.getProcessingErrors();
            if (!request.isSkipPmdError()) {
                LOG.error("PMD processing errors:");
                LOG.error(getErrorsAsString(errors, request.isDebugEnabled()));
                throw new MavenReportException("Found " + errors.size() + " PMD processing errors");
            }
            LOG.warn("There are {} PMD processing errors:", errors.size());
            LOG.warn(getErrorsAsString(errors, request.isDebugEnabled()));
        }

        report = removeExcludedViolations(report);
        // always write XML report, as this might be needed by the check mojo
        // we need to output it even if the file list is empty or we have no violations
        // so the "check" goals can check for violations
        writeXmlReport(report);

        // write any other format except for xml and html. xml has just been produced.
        // html format is produced by the maven site formatter. Excluding html here
        // avoids using PMD's own html formatter, which doesn't fit into the maven site
        // considering the html/css styling
        String format = request.getFormat();
        if (!"html".equals(format) && !"xml".equals(format)) {
            writeFormattedReport(report);
        }

        return new PmdResult(new File(request.getTargetDirectory(), "pmd.xml"), request.getOutputEncoding());
    }