From 4c2550a8377905d6c3c9086a3970cdbbe9a58384 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 5 Mar 2024 16:18:00 +0000 Subject: [PATCH] Remove ProfileManager --- .../deployment/steps/MainClassBuildStep.java | 3 +- .../runner/bootstrap/AugmentActionImpl.java | 9 +- .../java/io/quarkus/runtime/LaunchMode.java | 10 +- .../runtime/configuration/ProfileManager.java | 48 -------- .../QuarkusConfigBuilderCustomizer.java | 2 +- .../runtime/devmode/GrpcServerReloader.java | 3 +- .../VertxEventBusConsumerRecorder.java | 3 +- .../quarkus/it/main/ProfileManagerITCase.java | 8 -- .../it/main/ProfileManagerTestCase.java | 115 ------------------ .../java/io/quarkus/maven/it/BuildIT.java | 3 +- .../io/quarkus/test/QuarkusDevModeTest.java | 3 +- .../java/io/quarkus/test/QuarkusUnitTest.java | 3 +- .../AbstractJvmQuarkusTestExtension.java | 4 +- .../test/junit/BasicLoggingEnabler.java | 3 +- .../test/junit/IntegrationTestUtil.java | 7 +- .../test/junit/QuarkusTestExtension.java | 3 +- 16 files changed, 22 insertions(+), 205 deletions(-) delete mode 100644 integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerITCase.java delete mode 100644 integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerTestCase.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java index e32a0ab978922..9274c1ced43df 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java @@ -88,7 +88,6 @@ import io.quarkus.runtime.annotations.QuarkusMain; import io.quarkus.runtime.appcds.AppCDSUtil; import io.quarkus.runtime.configuration.ConfigUtils; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.runtime.util.StepTiming; public class MainClassBuildStep { @@ -175,7 +174,7 @@ void build(List staticInitTasks, //set the launch mode ResultHandle lm = mv .readStaticField(FieldDescriptor.of(LaunchMode.class, launchMode.getLaunchMode().name(), LaunchMode.class)); - mv.invokeStaticMethod(ofMethod(ProfileManager.class, "setLaunchMode", void.class, LaunchMode.class), + mv.invokeStaticMethod(ofMethod(LaunchMode.class, "set", void.class, LaunchMode.class), lm); mv.invokeStaticMethod(CONFIGURE_STEP_TIME_ENABLED); diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java index 8997cf9b9589b..ebe88aa820873 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java @@ -12,7 +12,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -51,7 +50,6 @@ import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem; import io.quarkus.dev.spi.DevModeType; import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.runtime.configuration.QuarkusConfigFactory; /** @@ -277,11 +275,7 @@ private BuildResult runAugment(boolean firstRun, Set changedResources, try { QuarkusClassLoader classLoader = curatedApplication.getAugmentClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); - ProfileManager.setLaunchMode(launchMode); - ProfileManager.setRuntimeDefaultProfile( - Optional.ofNullable(quarkusBootstrap.getBuildSystemProperties()) - .map(properties -> properties.getProperty(ProfileManager.QUARKUS_PROFILE_PROP)) - .orElse(null)); + LaunchMode.set(launchMode); QuarkusAugmentor.Builder builder = QuarkusAugmentor.builder() .setRoot(quarkusBootstrap.getApplicationRoot()) @@ -337,7 +331,6 @@ private BuildResult runAugment(boolean firstRun, Set changedResources, throw new RuntimeException(e); } } finally { - ProfileManager.setRuntimeDefaultProfile(null); Thread.currentThread().setContextClassLoader(old); QuarkusConfigFactory.setConfig(null); } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java b/core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java index ad109bd8b4020..c5d4a908a1566 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java @@ -1,7 +1,5 @@ package io.quarkus.runtime; -import io.quarkus.runtime.configuration.ProfileManager; - public enum LaunchMode { /** @@ -45,11 +43,17 @@ public String getProfileKey() { return profileKey; } + private static volatile LaunchMode launchMode = LaunchMode.NORMAL; + + public static void set(LaunchMode mode) { + launchMode = mode; + } + /** * * @return The current launch mode */ public static LaunchMode current() { - return ProfileManager.getLaunchMode(); + return launchMode; } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java index c1a58d7963778..68dc7a87696ce 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java @@ -18,14 +18,7 @@ * */ public class ProfileManager { - - public static final String QUARKUS_PROFILE_ENV = "QUARKUS_PROFILE"; - public static final String QUARKUS_PROFILE_PROP = "quarkus.profile"; - public static final String QUARKUS_TEST_PROFILE_PROP = "quarkus.test.profile"; - private static final String BACKWARD_COMPATIBLE_QUARKUS_PROFILE_PROP = "quarkus-profile"; - private static volatile LaunchMode launchMode = LaunchMode.NORMAL; - private static volatile String runtimeDefaultProfile; public static void setLaunchMode(LaunchMode mode) { launchMode = mode; @@ -35,47 +28,6 @@ public static LaunchMode getLaunchMode() { return launchMode; } - public static void setRuntimeDefaultProfile(final String profile) { - runtimeDefaultProfile = profile; - } - //NOTE: changes made here must be replicated in BootstrapProfile - /** - * @deprecated This method is not suited to multiple profiles, because it returns a single string. Please use - * {@link ConfigUtils#getProfiles()} instead, which returns a List of profiles. - */ - @Deprecated - public static String getActiveProfile() { - if (launchMode == LaunchMode.TEST) { - String profile = System.getProperty(QUARKUS_TEST_PROFILE_PROP); - if (profile != null) { - return profile; - } - return launchMode.getDefaultProfile(); - } - - String profile = System.getProperty(QUARKUS_PROFILE_PROP); - if (profile != null) { - return profile; - } - - profile = System.getProperty(BACKWARD_COMPATIBLE_QUARKUS_PROFILE_PROP); - if (profile != null) { - return profile; - } - - profile = System.getenv(QUARKUS_PROFILE_ENV); - if (profile != null) { - return profile; - } - - profile = runtimeDefaultProfile; - if (profile != null) { - return profile; - } - - return launchMode.getDefaultProfile(); - } - } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigBuilderCustomizer.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigBuilderCustomizer.java index 6d9e82852aa30..367798494a0f8 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigBuilderCustomizer.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigBuilderCustomizer.java @@ -25,7 +25,7 @@ public class QuarkusConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer { @Override public void configBuilder(final SmallRyeConfigBuilder builder) { - LaunchMode launchMode = ProfileManager.getLaunchMode(); + LaunchMode launchMode = LaunchMode.current(); builder.withDefaultValue(launchMode.getProfileKey(), launchMode.getDefaultProfile()); builder.withInterceptorFactories(new ConfigSourceInterceptorFactory() { diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/devmode/GrpcServerReloader.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/devmode/GrpcServerReloader.java index 4ca468c5000b4..986dc193a614c 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/devmode/GrpcServerReloader.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/devmode/GrpcServerReloader.java @@ -13,7 +13,6 @@ import io.quarkus.grpc.stubs.ServerCalls; import io.quarkus.grpc.stubs.StreamCollector; import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.configuration.ProfileManager; import io.vertx.grpc.VertxServer; public class GrpcServerReloader { @@ -29,7 +28,7 @@ public static void init(VertxServer grpcServer) { } public static StreamCollector devModeCollector() { - if (ProfileManager.getLaunchMode() != LaunchMode.DEVELOPMENT) { + if (LaunchMode.current() != LaunchMode.DEVELOPMENT) { throw new IllegalStateException("Attempted to initialize development mode StreamCollector in non-development mode"); } return new DevModeStreamsCollector(); diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxEventBusConsumerRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxEventBusConsumerRecorder.java index 6c8e6633064a4..0eaff963ff578 100644 --- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxEventBusConsumerRecorder.java +++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxEventBusConsumerRecorder.java @@ -28,7 +28,6 @@ import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.ShutdownContext; import io.quarkus.runtime.annotations.Recorder; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.vertx.ConsumeEvent; import io.quarkus.vertx.LocalEventBusCodec; import io.quarkus.virtual.threads.VirtualThreadsRecorder; @@ -260,7 +259,7 @@ private EventConsumerInvoker createInvoker(String invokerClassName) { @SuppressWarnings("unchecked") private void registerCodecs(Map, Class> codecByClass, List> selectorTypes) { EventBus eventBus = vertx.eventBus(); - boolean isDevMode = ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT; + boolean isDevMode = LaunchMode.current() == LaunchMode.DEVELOPMENT; for (Map.Entry, Class> codecEntry : codecByClass.entrySet()) { Class target = codecEntry.getKey(); Class codec = codecEntry.getValue(); diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerITCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerITCase.java deleted file mode 100644 index f40491e7b5234..0000000000000 --- a/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerITCase.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.quarkus.it.main; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class ProfileManagerITCase extends ProfileManagerTestCase { - -} diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerTestCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerTestCase.java deleted file mode 100644 index 8bcf86c206b21..0000000000000 --- a/integration-tests/main/src/test/java/io/quarkus/it/main/ProfileManagerTestCase.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.quarkus.it.main; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.configuration.ProfileManager; -import io.quarkus.test.junit.QuarkusTest; - -@QuarkusTest -public class ProfileManagerTestCase { - - private static final String BACKWARD_COMPATIBLE_QUARKUS_PROFILE_PROP = "quarkus-profile"; - - @BeforeEach - public void beforeEach() { - resetProfileManagerState(); - } - - @AfterEach - public void afterEach() { - resetProfileManagerState(); - } - - private void resetProfileManagerState() { - ProfileManager.setLaunchMode(LaunchMode.TEST); // Tests should be run in LaunchMode.TEST by default - ProfileManager.setRuntimeDefaultProfile(null); - System.clearProperty(ProfileManager.QUARKUS_PROFILE_PROP); - System.clearProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP); - System.clearProperty(BACKWARD_COMPATIBLE_QUARKUS_PROFILE_PROP); - Assertions.assertNull(System.getenv(ProfileManager.QUARKUS_PROFILE_ENV)); - } - - @Test - public void testDefaultTestProfile() { - Assertions.assertEquals(LaunchMode.TEST.getDefaultProfile(), ProfileManager.getActiveProfile()); - } - - @Test - public void testCustomTestProfile() { - String customProfile = "foo"; - System.setProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP, customProfile); - Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile()); - } - - @Test - public void testCustomNormalProfile() { - testCustomProfile(LaunchMode.NORMAL); - } - - @Test - public void testCustomDevProfile() { - testCustomProfile(LaunchMode.DEVELOPMENT); - } - - private void testCustomProfile(LaunchMode launchMode) { - ProfileManager.setLaunchMode(launchMode); - ProfileManager.setRuntimeDefaultProfile("foo"); - String customProfile = "bar"; - System.setProperty(ProfileManager.QUARKUS_PROFILE_PROP, customProfile); - Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile()); - } - - @Test - public void testBackwardCompatibleCustomNormalProfile() { - testBackwardCompatibleCustomProfile(LaunchMode.NORMAL); - } - - @Test - public void testBackwardCompatibleCustomDevProfile() { - testBackwardCompatibleCustomProfile(LaunchMode.DEVELOPMENT); - } - - private void testBackwardCompatibleCustomProfile(LaunchMode launchMode) { - ProfileManager.setLaunchMode(launchMode); - ProfileManager.setRuntimeDefaultProfile("foo"); - String customProfile = "bar"; - System.setProperty(BACKWARD_COMPATIBLE_QUARKUS_PROFILE_PROP, customProfile); - Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile()); - } - - @Test - public void testCustomRuntimeNormalProfile() { - testCustomRuntimeProfile(LaunchMode.NORMAL); - } - - @Test - public void testCustomRuntimeDevProfile() { - testCustomRuntimeProfile(LaunchMode.DEVELOPMENT); - } - - private void testCustomRuntimeProfile(LaunchMode launchMode) { - ProfileManager.setLaunchMode(launchMode); - String customProfile = "foo"; - ProfileManager.setRuntimeDefaultProfile(customProfile); - Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile()); - } - - @Test - public void testDefaultNormalProfile() { - testDefaultProfile(LaunchMode.NORMAL); - } - - @Test - public void testDefaultDevProfile() { - testDefaultProfile(LaunchMode.DEVELOPMENT); - } - - private void testDefaultProfile(LaunchMode launchMode) { - ProfileManager.setLaunchMode(launchMode); - Assertions.assertEquals(launchMode.getDefaultProfile(), ProfileManager.getActiveProfile()); - } -} diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java index d2afe705aa134..b084a502e6b69 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java @@ -22,7 +22,6 @@ import io.quarkus.maven.it.verifier.MavenProcessInvocationResult; import io.quarkus.maven.it.verifier.RunningInvoker; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.test.devmode.util.DevModeClient; @DisableForNative @@ -122,7 +121,7 @@ void testModuleWithBuildProfileInProperty() throws MavenInvocationException, Int @Test void testModuleWithOverriddenBuildProfile() throws MavenInvocationException, InterruptedException, IOException { testDir = initProject("projects/build-mode-quarkus-profile-override"); - build(String.format("-D%s=foo", ProfileManager.QUARKUS_PROFILE_PROP)); + build(String.format("-D%s=foo", "quarkus.profile")); launch(); } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java index d12b7e583b734..cb2dd82bcd2a7 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java @@ -50,7 +50,6 @@ import io.quarkus.maven.dependency.GACT; import io.quarkus.paths.PathList; import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.test.common.GroovyClassValue; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.PropertyTestUtil; @@ -232,7 +231,7 @@ public void beforeAll(ExtensionContext context) throws Exception { TestConfigUtil.cleanUp(); GroovyClassValue.disable(); //set the right launch mode in the outer CL, used by the HTTP host config source - ProfileManager.setLaunchMode(LaunchMode.DEVELOPMENT); + LaunchMode.set(LaunchMode.DEVELOPMENT); originalRootLoggerHandlers = rootLogger.getHandlers(); rootLogger.addHandler(inMemoryLogHandler); } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java index 39cfc3e9aa36d..f8b0fffd80577 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java @@ -69,7 +69,6 @@ import io.quarkus.runner.bootstrap.AugmentActionImpl; import io.quarkus.runner.bootstrap.StartupActionImpl; import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.runtime.logging.JBossVersion; import io.quarkus.test.common.GroovyClassValue; import io.quarkus.test.common.PathTestHelper; @@ -511,7 +510,7 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception { TestConfigUtil.cleanUp(); GroovyClassValue.disable(); //set the right launch mode in the outer CL, used by the HTTP host config source - ProfileManager.setLaunchMode(LaunchMode.TEST); + LaunchMode.set(LaunchMode.TEST); if (beforeAllCustomizer != null) { beforeAllCustomizer.run(); } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java index 5623be978f8ef..cdf2ac07b42f8 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java @@ -36,7 +36,7 @@ import io.quarkus.bootstrap.workspace.WorkspaceModule; import io.quarkus.deployment.dev.testing.CurrentTestApplication; import io.quarkus.paths.PathList; -import io.quarkus.runtime.configuration.ProfileManager; +import io.quarkus.runtime.LaunchMode; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.common.RestorableSystemProperties; @@ -165,7 +165,7 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class getSysPropsToRestore() { Map sysPropRestore = new HashMap<>(); - sysPropRestore.put(ProfileManager.QUARKUS_TEST_PROFILE_PROP, - System.getProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP)); + sysPropRestore.put(LaunchMode.DEVELOPMENT.getProfileKey(), System.getProperty(LaunchMode.TEST.getProfileKey())); return sysPropRestore; } @@ -143,7 +142,7 @@ static TestProfileAndProperties determineTestProfileAndProperties(Class i : properties.entrySet()) { diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index fdb41b5c4effa..f2707e915346b 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -89,7 +89,6 @@ import io.quarkus.runtime.ApplicationLifecycleManager; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.DurationConverter; -import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.runtime.logging.JBossVersion; import io.quarkus.runtime.test.TestHttpEndpointProvider; import io.quarkus.test.TestMethodInvoker; @@ -652,7 +651,7 @@ public void beforeAll(ExtensionContext context) throws Exception { GroovyClassValue.disable(); currentTestClassStack.push(requiredTestClass); //set the right launch mode in the outer CL, used by the HTTP host config source - ProfileManager.setLaunchMode(LaunchMode.TEST); + LaunchMode.set(LaunchMode.TEST); if (isNativeOrIntegrationTest(requiredTestClass)) { return; }