From d0cdd834c85aec611b1d170628c88979bf21a9a2 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sat, 1 Apr 2023 13:57:45 +0100 Subject: [PATCH] Deprecate all platform class path features for v1.0.0 Platform class path functionality in the JVM was historically used before JPMS introduced system modules for the standard library. In lieu of that, the platform class path functionality is mostly deprecated, and has been reported to not work nicely in tests. Therefore, I am deprecating this with immediate effect for removal in v1.0.0. --- .../jct/compilers/AbstractJctCompiler.java | 9 +++++++ .../ascopes/jct/compilers/JctCompiler.java | 17 ++++++++++-- .../jct/filemanagers/JctFileManager.java | 4 +++ ...ManagerJvmPlatformClassPathConfigurer.java | 10 +++++-- .../impl/JctFileManagerFactoryImpl.java | 1 + .../jct/utils/SpecialLocationUtils.java | 9 ++++++- .../ascopes/jct/workspaces/Workspace.java | 26 ++++++++++++------- .../compilers/AbstractJctCompilerTest.java | 4 +++ .../unit/filemanagers/JctFileManagerTest.java | 1 + ...gerJvmPlatformClassPathConfigurerTest.java | 1 + .../impl/JctFileManagerFactoryImplTest.java | 1 + .../unit/utils/SpecialLocationsUtilsTest.java | 2 ++ .../tests/unit/workspaces/WorkspaceTest.java | 2 ++ 13 files changed, 73 insertions(+), 14 deletions(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractJctCompiler.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractJctCompiler.java index a89e260b1..c3cd068f7 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractJctCompiler.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractJctCompiler.java @@ -77,7 +77,11 @@ public abstract class AbstractJctCompiler> private boolean fixJvmModulePathMismatch; private boolean inheritClassPath; private boolean inheritModulePath; + + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") private boolean inheritPlatformClassPath; + private boolean inheritSystemModulePath; private LoggingMode fileManagerLoggingMode; private AnnotationProcessorDiscovery annotationProcessorDiscovery; @@ -87,6 +91,7 @@ public abstract class AbstractJctCompiler> * * @param defaultName the printable default name to use for the compiler. */ + @SuppressWarnings("removal") protected AbstractJctCompiler(String defaultName) { name = requireNonNull(defaultName, "name"); annotationProcessors = new ArrayList<>(); @@ -335,12 +340,16 @@ public A inheritModulePath(boolean inheritModulePath) { return myself(); } + @Deprecated(forRemoval = true, since = "0.6.0") @Override + @SuppressWarnings({"removal", "DeprecatedIsStillUsed"}) public boolean isInheritPlatformClassPath() { return inheritPlatformClassPath; } + @Deprecated(forRemoval = true, since = "0.6.0") @Override + @SuppressWarnings({"removal", "DeprecatedIsStillUsed"}) public A inheritPlatformClassPath(boolean inheritPlatformClassPath) { this.inheritPlatformClassPath = inheritPlatformClassPath; return myself(); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompiler.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompiler.java index a1731370e..0c289c0ef 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompiler.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompiler.java @@ -90,9 +90,15 @@ public interface JctCompiler, R extends JctCompilati boolean DEFAULT_INHERIT_MODULE_PATH = true; /** - * Default setting for inclusion of the current platform class path ({@code true}). + * Default setting for inclusion of the current platform class path ({@code false}). + * + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0, and has been changed to default to + * {@code false} as of v0.6.0 */ - boolean DEFAULT_INHERIT_PLATFORM_CLASS_PATH = true; + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") + boolean DEFAULT_INHERIT_PLATFORM_CLASS_PATH = false; /** * Default setting for inclusion of the system module path ({@code true}). @@ -727,7 +733,11 @@ default C target(SourceVersion target) { * {@link #DEFAULT_INHERIT_PLATFORM_CLASS_PATH}. * * @return whether the platform class path is being inherited or not. + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") boolean isInheritPlatformClassPath(); /** @@ -740,7 +750,10 @@ default C target(SourceVersion target) { * * @param inheritPlatformClassPath {@code true} to include it, or {@code false} to exclude it. * @return this compiler object for further call chaining. + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ + @Deprecated(forRemoval = true, since = "0.6.0") C inheritPlatformClassPath(boolean inheritPlatformClassPath); /** diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java index 2d75e9738..7e0fe676a 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java @@ -251,8 +251,12 @@ default ModuleContainerGroup getAnnotationProcessorModulePathGroup() { * * @return the location, or {@code null} if the location is not present in the file manager. * @since 0.1.0 + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ + @Deprecated(forRemoval = true, since = "0.6.0") @Nullable + @SuppressWarnings("DeprecatedIsStillUsed") default PackageContainerGroup getPlatformClassPathGroup() { return getPackageContainerGroup(StandardLocation.PLATFORM_CLASS_PATH); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurer.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurer.java index 509ec0a9c..9c7d261f2 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurer.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurer.java @@ -33,10 +33,14 @@ * * @author Ashley Scopes * @since 0.0.1 (0.0.1-M7) + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ @API(since = "0.0.1", status = Status.STABLE) -public final class JctFileManagerJvmPlatformClassPathConfigurer implements - JctFileManagerConfigurer { +@Deprecated(forRemoval = true, since = "0.6.0") +@SuppressWarnings("DeprecatedIsStillUsed") +public final class JctFileManagerJvmPlatformClassPathConfigurer + implements JctFileManagerConfigurer { private static final Logger LOGGER = LoggerFactory .getLogger(JctFileManagerJvmPlatformClassPathConfigurer.class); @@ -53,6 +57,7 @@ public JctFileManagerJvmPlatformClassPathConfigurer(JctCompiler compiler) } @Override + @SuppressWarnings("removal") public JctFileManager configure(JctFileManager fileManager) { LOGGER.debug("Configuring JVM platform class path"); @@ -69,6 +74,7 @@ public JctFileManager configure(JctFileManager fileManager) { } @Override + @SuppressWarnings("removal") public boolean isEnabled() { return compiler.isInheritPlatformClassPath(); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java index 22c478627..5f4fbe433 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java @@ -74,6 +74,7 @@ public JctFileManager createFileManager(Workspace workspace) { * @return the chain to use. */ @VisibleForTestingOnly + @SuppressWarnings("removal") public JctFileManagerConfigurerChain createConfigurerChain(Workspace workspace) { // The order here is important. Do not adjust it without testing extensively first! return new JctFileManagerConfigurerChain() diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java index eabc81cac..9944367b5 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java @@ -121,11 +121,18 @@ public static List currentModulePathLocations() { * * @return a list across the paths. */ + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") public static List currentPlatformClassPathLocations() { var mxBean = ManagementFactory.getRuntimeMXBean(); if (mxBean.isBootClassPathSupported()) { - LOGGER.trace("Platform (boot) classpath is supported on this JVM, so will be inspected"); + LOGGER.warn( + "Warning: platform (boot) class path locations were found on this JVM, but this " + + "feature is deprecated for removal in v1.0.0 of the java-compiler-testing API. " + + "Consider disabling platform classpath discovery explicitly to prevent tests " + + "having differing behaviour for v1.0.0." + ); return createPaths(mxBean.getBootClassPath()); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java index 7b2f8a619..2dd0d7b43 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java @@ -513,7 +513,11 @@ default void addAnnotationProcessorPathModule(String moduleName, Path path) { * @throws IllegalArgumentException if the path does not exist. * @see #addPackage(Location, Path) * @see #createPlatformClassPathPackage() + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") default void addPlatformClassPathPackage(Path path) { addPackage(StandardLocation.PLATFORM_CLASS_PATH, path); } @@ -756,7 +760,11 @@ default ManagedDirectory createAnnotationProcessorPathModule(String moduleName) * @return the created test directory. * @see #createPackage(Location) * @see #addPlatformClassPathPackage(Path) + * @deprecated The platform class path has been mostly replaced by the use of system modules, so + * should not be used. This will be removed in v1.0.0. */ + @Deprecated(forRemoval = true, since = "0.6.0") + @SuppressWarnings("DeprecatedIsStillUsed") default ManagedDirectory createPlatformClassPathPackage() { return createPackage(StandardLocation.PLATFORM_CLASS_PATH); } @@ -850,7 +858,7 @@ default List getClassOutputModule(String moduleName) { * Get the module path roots for {@link StandardLocation#CLASS_OUTPUT class outputs}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getClassOutputModules() { @@ -884,7 +892,7 @@ default List getSourceOutputModule(String moduleName) { * Get the module path roots for {@link StandardLocation#SOURCE_OUTPUT source outputs}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getSourceOutputModules() { @@ -939,7 +947,7 @@ default List getAnnotationProcessorPathModule(String moduleN * {@link StandardLocation#ANNOTATION_PROCESSOR_MODULE_PATH annotation processor module path}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getAnnotationProcessorPathModules() { @@ -985,7 +993,7 @@ default List getNativeHeaderOutputModule(String moduleName) * {@link StandardLocation#NATIVE_HEADER_OUTPUT native header outputs}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getNativeHeaderOutputModules() { @@ -1008,7 +1016,7 @@ default List getSourcePathModule(String moduleName) { * {@link StandardLocation#MODULE_SOURCE_PATH module source paths}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getSourcePathModules() { @@ -1031,7 +1039,7 @@ default List getUpgradeModulePathModule(String moduleName) { * {@link StandardLocation#UPGRADE_MODULE_PATH upgrade module paths}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getUpgradeModulePathModules() { @@ -1053,7 +1061,7 @@ default List getSystemModulePathModule(String moduleName) { * Get the module path roots for the {@link StandardLocation#SYSTEM_MODULES system modules}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getSystemModulePathModules() { @@ -1075,7 +1083,7 @@ default List getModulePathModule(String moduleName) { * Get the module path roots for the {@link StandardLocation#MODULE_PATH module paths}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getModulePathModules() { @@ -1098,7 +1106,7 @@ default List getPatchModulePathModule(String moduleName) { * {@link StandardLocation#PATCH_MODULE_PATH patch module paths}. * * @return the roots in a map of module names to lists of roots, or an empty map if none were - * found. + * found. * @since 0.1.0 */ default Map> getPatchModulePathModules() { diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/compilers/AbstractJctCompilerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/compilers/AbstractJctCompilerTest.java index ba5c7444c..aa1e442a3 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/compilers/AbstractJctCompilerTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/compilers/AbstractJctCompilerTest.java @@ -285,6 +285,7 @@ void constructorInitialisesInheritModulePathToDefaultValue() { @DisplayName("constructor initialises inheritPlatformClassPath to default value") @Test + @SuppressWarnings("removal") void constructorInitialisesInheritPlatformClassPathToDefaultValue() { // Then assertThatCompilerField("inheritPlatformClassPath") @@ -1292,6 +1293,7 @@ void inheritModulePathReturnsTheCompiler() { @DisplayName(".isInheritPlatformClassPath() returns the expected values") @ValueSource(booleans = {true, false}) @ParameterizedTest(name = "for inheritPlatformClassPath = {0}") + @SuppressWarnings("removal") void isInheritPlatformClassPathReturnsExpectedValue(boolean expected) { // Given setFieldOnCompiler("inheritPlatformClassPath", expected); @@ -1307,6 +1309,7 @@ class InheritPlatformClassPathTests { @DisplayName(".inheritPlatformClassPath(...) sets the expected values") @ValueSource(booleans = {true, false}) @ParameterizedTest(name = "for inheritPlatformClassPath = {0}") + @SuppressWarnings("removal") void inheritPlatformClassPathSetsExpectedValue(boolean expected) { // When compiler.inheritPlatformClassPath(expected); @@ -1317,6 +1320,7 @@ void inheritPlatformClassPathSetsExpectedValue(boolean expected) { @DisplayName(".inheritPlatformClassPath(...) returns the compiler") @Test + @SuppressWarnings("removal") void inheritPlatformClassPathReturnsTheCompiler() { // When var result = compiler.inheritPlatformClassPath(true); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java index 7ecc864a2..119b1f577 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java @@ -152,6 +152,7 @@ void getAnnotationProcessorModulePathGroupMakesTheExpectedCall(ModuleContainerGr @DisplayName(".getPlatformClassPathGroup() makes the expected call") @MethodSource("outputContainerGroupResults") @ParameterizedTest(name = "when internal getter returns {0}") + @SuppressWarnings("removal") void getPlatformClassPathGroupMakesTheExpectedCall(PackageContainerGroup expected) { // Given when(fileManager.getPlatformClassPathGroup()).thenCallRealMethod(); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurerTest.java index 5fe5fbc3c..a2a802ebf 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurerTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/config/JctFileManagerJvmPlatformClassPathConfigurerTest.java @@ -47,6 +47,7 @@ */ @DisplayName("JctFileManagerJvmPlatformClassPathConfigurer tests") @ExtendWith(MockitoExtension.class) +@SuppressWarnings("removal") class JctFileManagerJvmPlatformClassPathConfigurerTest { @Mock diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/impl/JctFileManagerFactoryImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/impl/JctFileManagerFactoryImplTest.java index 2c332ddf8..ff859881a 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/impl/JctFileManagerFactoryImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/impl/JctFileManagerFactoryImplTest.java @@ -119,6 +119,7 @@ void createdFileManagersAreTransformedByTheConfigurerChain() { @DisplayName("The configurer chain uses the expected configurers") @Test + @SuppressWarnings("removal") void createdFileManagersAreReturnedAsTheResultFromTheConfigurerChain() { // When var configurerChain = factory.createConfigurerChain(workspace); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/utils/SpecialLocationsUtilsTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/utils/SpecialLocationsUtilsTest.java index 303a2a034..55ac7c504 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/utils/SpecialLocationsUtilsTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/utils/SpecialLocationsUtilsTest.java @@ -140,6 +140,7 @@ void currentModulePathLocationsReturnsTheClassPathLocationsThatExist() throws IO @DisplayName("currentPlatformClassPathLocations() returns the class path locations that exist") @Test + @SuppressWarnings("removal") void currentPlatformClassPathLocationsReturnsTheClassPathLocationsThatExist() throws IOException { // Given try ( @@ -163,6 +164,7 @@ void currentPlatformClassPathLocationsReturnsTheClassPathLocationsThatExist() th @DisplayName("currentPlatformClassPathLocations() returns empty when boot path not supported") @Test + @SuppressWarnings("removal") void currentPlatformClassPathLocationsReturnsEmptyWhenBootPathNotSupported() { // Given try (var mx = new MockedMxBean<>(ManagementFactory::getRuntimeMXBean, RuntimeMXBean.class)) { diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/workspaces/WorkspaceTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/workspaces/WorkspaceTest.java index 13f55e022..80da4c1d7 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/workspaces/WorkspaceTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/workspaces/WorkspaceTest.java @@ -215,6 +215,7 @@ void addAnnotationProcessorPathModuleCallsAddModule() { @DisplayName(".addPlatformClassPathPackage(Path) calls addPackage(PLATFORM_CLASS_PATH, Path)") @Test + @SuppressWarnings("removal") void addPlatformClassPathPackageCallsAddPackage() { // Given doCallRealMethod().when(workspace).addPlatformClassPathPackage(any()); @@ -470,6 +471,7 @@ void createAnnotationProcessorPathModuleCallsCreateModule() { @DisplayName(".createPlatformClassPathPackage() calls createPackage(PLATFORM_CLASS_PATH)") @Test + @SuppressWarnings("removal") void createPlatformClassPathPackageCallsCreatePackage() { // Given doCallRealMethod().when(workspace).createPlatformClassPathPackage();