Search in sources :

Example 1 with MultiThreadProcessor

use of net.sourceforge.pmd.processor.MultiThreadProcessor in project pmd by pmd.

the class PMD method processFiles.

/**
 * Run PMD on a list of files using multiple threads - if more than one is
 * available
 *
 * @param configuration
 *            Configuration
 * @param ruleSetFactory
 *            RuleSetFactory
 * @param files
 *            List of {@link DataSource}s
 * @param ctx
 *            RuleContext
 * @param renderers
 *            List of {@link Renderer}s
 */
public static void processFiles(final PMDConfiguration configuration, final RuleSetFactory ruleSetFactory, final List<DataSource> files, final RuleContext ctx, final List<Renderer> renderers) {
    if (!configuration.isIgnoreIncrementalAnalysis() && configuration.getAnalysisCache() instanceof NoopAnalysisCache && LOG.isLoggable(Level.WARNING)) {
        final String version = PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-" + PMDVersion.VERSION;
        LOG.warning("This analysis could be faster, please consider using Incremental Analysis: " + "https://pmd.github.io/" + version + "/pmd_userdocs_getting_started.html#incremental-analysis");
    }
    sortFiles(configuration, files);
    // Make sure the cache is listening for analysis results
    ctx.getReport().addListener(configuration.getAnalysisCache());
    final RuleSetFactory silentFactoy = new RuleSetFactory(ruleSetFactory, false);
    /*
         * Check if multithreaded support is available. ExecutorService can also
         * be disabled if threadCount is not positive, e.g. using the
         * "-threads 0" command line option.
         */
    if (configuration.getThreads() > 0) {
        new MultiThreadProcessor(configuration).processFiles(silentFactoy, files, ctx, renderers);
    } else {
        new MonoThreadProcessor(configuration).processFiles(silentFactoy, files, ctx, renderers);
    }
    // Persist the analysis cache
    configuration.getAnalysisCache().persist();
}
Also used : NoopAnalysisCache(net.sourceforge.pmd.cache.NoopAnalysisCache) MultiThreadProcessor(net.sourceforge.pmd.processor.MultiThreadProcessor) MonoThreadProcessor(net.sourceforge.pmd.processor.MonoThreadProcessor)

Aggregations

NoopAnalysisCache (net.sourceforge.pmd.cache.NoopAnalysisCache)1 MonoThreadProcessor (net.sourceforge.pmd.processor.MonoThreadProcessor)1 MultiThreadProcessor (net.sourceforge.pmd.processor.MultiThreadProcessor)1