Search in sources :

Example 1 with NoopAnalysisCache

use of net.sourceforge.pmd.cache.NoopAnalysisCache 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)

Example 2 with NoopAnalysisCache

use of net.sourceforge.pmd.cache.NoopAnalysisCache in project pmd by pmd.

the class PMDCommandLineInterfaceTest method testNoCacheSwitch.

@Test
public void testNoCacheSwitch() {
    PMDParameters params = new PMDParameters();
    String[] args = { "-d", "source_folder", "-f", "ideaj", "-R", "java-empty", "-cache", "/home/user/.pmd/cache", "-no-cache" };
    PMDCommandLineInterface.extractParameters(params, args, "PMD");
    assertTrue(params.isIgnoreIncrementalAnalysis());
    PMDConfiguration config = params.toConfiguration();
    assertTrue(config.isIgnoreIncrementalAnalysis());
    assertTrue(config.getAnalysisCache() instanceof NoopAnalysisCache);
}
Also used : NoopAnalysisCache(net.sourceforge.pmd.cache.NoopAnalysisCache) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration) Test(org.junit.Test)

Example 3 with NoopAnalysisCache

use of net.sourceforge.pmd.cache.NoopAnalysisCache in project pmd by pmd.

the class ConfigurationTest method testAnalysisCache.

@Test
public void testAnalysisCache() throws IOException {
    final PMDConfiguration configuration = new PMDConfiguration();
    assertNotNull("Default cache is null", configuration.getAnalysisCache());
    assertTrue("Default cache is not a noop", configuration.getAnalysisCache() instanceof NoopAnalysisCache);
    configuration.setAnalysisCache(null);
    assertNotNull("Default cache was set to null", configuration.getAnalysisCache());
    final File cacheFile = File.createTempFile("pmd-", ".cache");
    cacheFile.deleteOnExit();
    final FileAnalysisCache analysisCache = new FileAnalysisCache(cacheFile);
    configuration.setAnalysisCache(analysisCache);
    assertSame("Confgured cache not stored", analysisCache, configuration.getAnalysisCache());
}
Also used : FileAnalysisCache(net.sourceforge.pmd.cache.FileAnalysisCache) NoopAnalysisCache(net.sourceforge.pmd.cache.NoopAnalysisCache) File(java.io.File) Test(org.junit.Test)

Example 4 with NoopAnalysisCache

use of net.sourceforge.pmd.cache.NoopAnalysisCache in project pmd by pmd.

the class ConfigurationTest method testIgnoreIncrementalAnalysis.

@Test
public void testIgnoreIncrementalAnalysis() throws IOException {
    final PMDConfiguration configuration = new PMDConfiguration();
    // set dummy cache location
    final File cacheFile = File.createTempFile("pmd-", ".cache");
    cacheFile.deleteOnExit();
    final FileAnalysisCache analysisCache = new FileAnalysisCache(cacheFile);
    configuration.setAnalysisCache(analysisCache);
    assertNotNull("Null cache location accepted", configuration.getAnalysisCache());
    assertFalse("Non null cache location, cache should not be noop", configuration.getAnalysisCache() instanceof NoopAnalysisCache);
    configuration.setIgnoreIncrementalAnalysis(true);
    assertTrue("Ignoring incremental analysis should turn the cache into a noop", configuration.getAnalysisCache() instanceof NoopAnalysisCache);
}
Also used : FileAnalysisCache(net.sourceforge.pmd.cache.FileAnalysisCache) NoopAnalysisCache(net.sourceforge.pmd.cache.NoopAnalysisCache) File(java.io.File) Test(org.junit.Test)

Aggregations

NoopAnalysisCache (net.sourceforge.pmd.cache.NoopAnalysisCache)4 Test (org.junit.Test)3 File (java.io.File)2 FileAnalysisCache (net.sourceforge.pmd.cache.FileAnalysisCache)2 PMDConfiguration (net.sourceforge.pmd.PMDConfiguration)1 MonoThreadProcessor (net.sourceforge.pmd.processor.MonoThreadProcessor)1 MultiThreadProcessor (net.sourceforge.pmd.processor.MultiThreadProcessor)1