[core] Consolidate internal api in PMDConfiguration
PMDConfiguration#setAnalysisCache PMDConfiguration#getAnalysisCache
This commit is contained in:
@ -316,6 +316,9 @@ package or made (package) private and are _not accessible_ anymore.
|
|||||||
* All constructors are package private now.
|
* All constructors are package private now.
|
||||||
* {%jdoc !!core::lang.ast.LexException %} - the constructor `LexException(boolean, String, int, int, String, char)` is now package private.
|
* {%jdoc !!core::lang.ast.LexException %} - the constructor `LexException(boolean, String, int, int, String, char)` is now package private.
|
||||||
It is only used by JavaCC-generated token managers.
|
It is only used by JavaCC-generated token managers.
|
||||||
|
* {%jdoc !!core::PMDConfiguration %}
|
||||||
|
* Method `setAnalysisCache(AnalysisCache)` is now package private. Use {%jdoc core::PMDConfiguration#setAnalysisCacheLocation(java.lang.String) %} instead.
|
||||||
|
* Method `getAnalysisCache()` is now package private.
|
||||||
* pmd-ant
|
* pmd-ant
|
||||||
* {%jdoc !!ant::ant.Formatter %}
|
* {%jdoc !!ant::ant.Formatter %}
|
||||||
* Method `getRenderer()` has been removed.
|
* Method `getRenderer()` has been removed.
|
||||||
|
@ -21,13 +21,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
|
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
|
||||||
import net.sourceforge.pmd.annotation.InternalApi;
|
|
||||||
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
||||||
import net.sourceforge.pmd.cache.internal.FileAnalysisCache;
|
import net.sourceforge.pmd.cache.internal.FileAnalysisCache;
|
||||||
import net.sourceforge.pmd.cache.internal.NoopAnalysisCache;
|
import net.sourceforge.pmd.cache.internal.NoopAnalysisCache;
|
||||||
import net.sourceforge.pmd.internal.util.ClasspathClassLoader;
|
import net.sourceforge.pmd.internal.util.ClasspathClassLoader;
|
||||||
import net.sourceforge.pmd.lang.Language;
|
import net.sourceforge.pmd.lang.Language;
|
||||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||||
|
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||||
import net.sourceforge.pmd.lang.rule.RuleSetLoader;
|
import net.sourceforge.pmd.lang.rule.RuleSetLoader;
|
||||||
import net.sourceforge.pmd.renderers.Renderer;
|
import net.sourceforge.pmd.renderers.Renderer;
|
||||||
@ -455,8 +455,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
|||||||
*
|
*
|
||||||
* @apiNote This is internal API.
|
* @apiNote This is internal API.
|
||||||
*/
|
*/
|
||||||
@InternalApi
|
AnalysisCache getAnalysisCache() {
|
||||||
public AnalysisCache getAnalysisCache() {
|
|
||||||
// Make sure we are not null
|
// Make sure we are not null
|
||||||
if (analysisCache == null || isIgnoreIncrementalAnalysis() && !(analysisCache instanceof NoopAnalysisCache)) {
|
if (analysisCache == null || isIgnoreIncrementalAnalysis() && !(analysisCache instanceof NoopAnalysisCache)) {
|
||||||
// sets a noop cache
|
// sets a noop cache
|
||||||
@ -476,8 +475,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
|||||||
*
|
*
|
||||||
* @apiNote This is internal API. Use {@link #setAnalysisCacheLocation(String)} to configure a cache.
|
* @apiNote This is internal API. Use {@link #setAnalysisCacheLocation(String)} to configure a cache.
|
||||||
*/
|
*/
|
||||||
@InternalApi
|
void setAnalysisCache(final AnalysisCache cache) {
|
||||||
public void setAnalysisCache(final AnalysisCache cache) {
|
|
||||||
// the doc says it's a noop if incremental analysis was disabled,
|
// the doc says it's a noop if incremental analysis was disabled,
|
||||||
// but it's actually the getter that enforces that
|
// but it's actually the getter that enforces that
|
||||||
this.analysisCache = cache == null ? new NoopAnalysisCache() : cache;
|
this.analysisCache = cache == null ? new NoopAnalysisCache() : cache;
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.sourceforge.pmd;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.annotation.InternalApi;
|
||||||
|
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal API.
|
||||||
|
*
|
||||||
|
* <p>Acts as a bridge between outer parts of PMD and the restricted access
|
||||||
|
* internal API of this package.
|
||||||
|
*
|
||||||
|
* <p><b>None of this is published API, and compatibility can be broken anytime!</b>
|
||||||
|
* Use this only at your own risk.
|
||||||
|
*
|
||||||
|
* @apiNote Internal API
|
||||||
|
*/
|
||||||
|
@InternalApi
|
||||||
|
public final class InternalApiBridgeForTestsOnly {
|
||||||
|
private InternalApiBridgeForTestsOnly() {}
|
||||||
|
|
||||||
|
public static void setAnalysisCache(PMDConfiguration pmdConfiguration, AnalysisCache cache) {
|
||||||
|
pmdConfiguration.setAnalysisCache(cache);
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import net.sourceforge.pmd.FooRule;
|
import net.sourceforge.pmd.FooRule;
|
||||||
|
import net.sourceforge.pmd.InternalApiBridgeForTestsOnly;
|
||||||
import net.sourceforge.pmd.PMDConfiguration;
|
import net.sourceforge.pmd.PMDConfiguration;
|
||||||
import net.sourceforge.pmd.PmdAnalysis;
|
import net.sourceforge.pmd.PmdAnalysis;
|
||||||
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
||||||
@ -71,7 +72,7 @@ class GlobalAnalysisListenerTest {
|
|||||||
|
|
||||||
PMDConfiguration config = newConfig();
|
PMDConfiguration config = newConfig();
|
||||||
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
||||||
config.setAnalysisCache(mockCache);
|
InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache);
|
||||||
|
|
||||||
MyFooRule rule = new MyFooRule();
|
MyFooRule rule = new MyFooRule();
|
||||||
runPmd(config, GlobalAnalysisListener.noop(), rule);
|
runPmd(config, GlobalAnalysisListener.noop(), rule);
|
||||||
@ -86,7 +87,7 @@ class GlobalAnalysisListenerTest {
|
|||||||
|
|
||||||
PMDConfiguration config = newConfig();
|
PMDConfiguration config = newConfig();
|
||||||
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
||||||
config.setAnalysisCache(mockCache);
|
InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache);
|
||||||
|
|
||||||
BrokenRule rule = new BrokenRule(); // the broken rule throws
|
BrokenRule rule = new BrokenRule(); // the broken rule throws
|
||||||
runPmd(config, GlobalAnalysisListener.noop(), rule);
|
runPmd(config, GlobalAnalysisListener.noop(), rule);
|
||||||
@ -102,7 +103,7 @@ class GlobalAnalysisListenerTest {
|
|||||||
|
|
||||||
PMDConfiguration config = newConfig();
|
PMDConfiguration config = newConfig();
|
||||||
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
AnalysisCache mockCache = spy(NoopAnalysisCache.class);
|
||||||
config.setAnalysisCache(mockCache);
|
InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache);
|
||||||
|
|
||||||
BrokenRule rule = new BrokenRule(); // the broken rule throws
|
BrokenRule rule = new BrokenRule(); // the broken rule throws
|
||||||
// now the exception should be propagated
|
// now the exception should be propagated
|
||||||
@ -122,7 +123,7 @@ class GlobalAnalysisListenerTest {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private PMDConfiguration newConfig() {
|
private PMDConfiguration newConfig() {
|
||||||
PMDConfiguration config = new PMDConfiguration();
|
PMDConfiguration config = new PMDConfiguration();
|
||||||
config.setAnalysisCache(new NoopAnalysisCache());
|
config.setAnalysisCacheLocation(null);
|
||||||
config.setIgnoreIncrementalAnalysis(true);
|
config.setIgnoreIncrementalAnalysis(true);
|
||||||
config.setThreads(0); // no multithreading for this test
|
config.setThreads(0); // no multithreading for this test
|
||||||
return config;
|
return config;
|
||||||
|
Reference in New Issue
Block a user