diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 58e00a9029..3d8af2c21e 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -316,6 +316,9 @@ package or made (package) private and are _not accessible_ anymore. * All constructors are package private now. * {%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. + * {%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 * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index b11df3bd2c..8e86465158 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -21,13 +21,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; 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.FileAnalysisCache; import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.lang.Language; 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.RuleSetLoader; import net.sourceforge.pmd.renderers.Renderer; @@ -455,8 +455,7 @@ public class PMDConfiguration extends AbstractConfiguration { * * @apiNote This is internal API. */ - @InternalApi - public AnalysisCache getAnalysisCache() { + AnalysisCache getAnalysisCache() { // Make sure we are not null if (analysisCache == null || isIgnoreIncrementalAnalysis() && !(analysisCache instanceof NoopAnalysisCache)) { // 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. */ - @InternalApi - public void setAnalysisCache(final AnalysisCache cache) { + void setAnalysisCache(final AnalysisCache cache) { // the doc says it's a noop if incremental analysis was disabled, // but it's actually the getter that enforces that this.analysisCache = cache == null ? new NoopAnalysisCache() : cache; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java b/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java new file mode 100644 index 0000000000..f12d571d01 --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java @@ -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. + * + *
Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *
None of this is published API, and compatibility can be broken anytime! + * 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); + } +} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java index 2f95e79331..1b07770bec 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import net.sourceforge.pmd.FooRule; +import net.sourceforge.pmd.InternalApiBridgeForTestsOnly; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.cache.internal.AnalysisCache; @@ -71,7 +72,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); MyFooRule rule = new MyFooRule(); runPmd(config, GlobalAnalysisListener.noop(), rule); @@ -86,7 +87,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); BrokenRule rule = new BrokenRule(); // the broken rule throws runPmd(config, GlobalAnalysisListener.noop(), rule); @@ -102,7 +103,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); BrokenRule rule = new BrokenRule(); // the broken rule throws // now the exception should be propagated @@ -122,7 +123,7 @@ class GlobalAnalysisListenerTest { @NonNull private PMDConfiguration newConfig() { PMDConfiguration config = new PMDConfiguration(); - config.setAnalysisCache(new NoopAnalysisCache()); + config.setAnalysisCacheLocation(null); config.setIgnoreIncrementalAnalysis(true); config.setThreads(0); // no multithreading for this test return config;