From 93ec6bb8eebc7c531b037db062ce31cf3a44b750 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 14 Oct 2024 16:51:22 +0300 Subject: [PATCH] Ensure that AppCDS works properly with command line applications Fixes: #43768 --- .../quarkus/runtime/ApplicationLifecycleManager.java | 11 +++++++++-- .../io/quarkus/arc/runtime/appcds/AppCDSRecorder.java | 5 ++--- .../runtime/KubernetesConfigSourceFactoryBuilder.java | 4 ++-- .../SpringCloudConfigClientConfigSourceFactory.java | 4 ++-- ...pringCloudConfigClientConfigSourceFactoryTest.java | 6 +++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java index 33d17d3d78fe3..75bf5410976c3 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java @@ -89,6 +89,8 @@ private ApplicationLifecycleManager() { private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); private static final boolean IS_MAC = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac"); + public static final String QUARKUS_APPCDS_GENERATE_PROP = "quarkus.appcds.generate"; + public static void run(Application application, String... args) { run(application, null, null, args); } @@ -117,8 +119,9 @@ public static void run(Application application, Class> beans = beanManager.getBeans(quarkusApplication, Any.Literal.INSTANCE); Bean bean = null; @@ -479,4 +482,8 @@ private static void handleSignal(final String signal, final SignalHandler handle // Do nothing } } + + public static boolean isAppCDSGeneration() { + return Boolean.parseBoolean(System.getProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP, "false")); + } } diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/appcds/AppCDSRecorder.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/appcds/AppCDSRecorder.java index 1f5e5a37b5b83..3dd1a4c6ac8e8 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/appcds/AppCDSRecorder.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/appcds/AppCDSRecorder.java @@ -1,5 +1,6 @@ package io.quarkus.arc.runtime.appcds; +import io.quarkus.runtime.ApplicationLifecycleManager; import io.quarkus.runtime.PreventFurtherStepsException; import io.quarkus.runtime.annotations.Recorder; import io.quarkus.runtime.init.InitializationTaskRecorder; @@ -7,10 +8,8 @@ @Recorder public class AppCDSRecorder { - public static final String QUARKUS_APPCDS_GENERATE_PROP = "quarkus.appcds.generate"; - public void controlGenerationAndExit() { - if (Boolean.parseBoolean(System.getProperty(QUARKUS_APPCDS_GENERATE_PROP, "false"))) { + if (ApplicationLifecycleManager.isAppCDSGeneration()) { InitializationTaskRecorder.preventFurtherRecorderSteps(5, "Unable to properly shutdown Quarkus application when creating AppCDS", PreventFurtherStepsException::new); diff --git a/extensions/kubernetes-config/runtime/src/main/java/io/quarkus/kubernetes/config/runtime/KubernetesConfigSourceFactoryBuilder.java b/extensions/kubernetes-config/runtime/src/main/java/io/quarkus/kubernetes/config/runtime/KubernetesConfigSourceFactoryBuilder.java index 89f09125ea611..ceceb155e7e3e 100644 --- a/extensions/kubernetes-config/runtime/src/main/java/io/quarkus/kubernetes/config/runtime/KubernetesConfigSourceFactoryBuilder.java +++ b/extensions/kubernetes-config/runtime/src/main/java/io/quarkus/kubernetes/config/runtime/KubernetesConfigSourceFactoryBuilder.java @@ -5,9 +5,9 @@ import org.eclipse.microprofile.config.spi.ConfigSource; import io.fabric8.kubernetes.client.KubernetesClient; -import io.quarkus.arc.runtime.appcds.AppCDSRecorder; import io.quarkus.kubernetes.client.runtime.KubernetesClientBuildConfig; import io.quarkus.kubernetes.client.runtime.KubernetesClientUtils; +import io.quarkus.runtime.ApplicationLifecycleManager; import io.quarkus.runtime.configuration.ConfigBuilder; import io.smallrye.config.ConfigSourceContext; import io.smallrye.config.ConfigSourceFactory.ConfigurableConfigSourceFactory; @@ -24,7 +24,7 @@ static class KubernetesConfigFactory implements ConfigurableConfigSourceFactory< public Iterable getConfigSources(final ConfigSourceContext context, final KubernetesClientBuildConfig config) { boolean inAppCDsGeneration = Boolean - .parseBoolean(System.getProperty(AppCDSRecorder.QUARKUS_APPCDS_GENERATE_PROP, "false")); + .parseBoolean(System.getProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP, "false")); if (inAppCDsGeneration) { return Collections.emptyList(); } diff --git a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java index c79bdee3c251e..509dddfed30ad 100644 --- a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java +++ b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java @@ -11,7 +11,7 @@ import org.eclipse.microprofile.config.spi.ConfigSource; import org.jboss.logging.Logger; -import io.quarkus.arc.runtime.appcds.AppCDSRecorder; +import io.quarkus.runtime.ApplicationLifecycleManager; import io.quarkus.runtime.util.StringUtil; import io.quarkus.spring.cloud.config.client.runtime.Response.PropertySource; import io.smallrye.config.ConfigSourceContext; @@ -26,7 +26,7 @@ public class SpringCloudConfigClientConfigSourceFactory public Iterable getConfigSources(final ConfigSourceContext context, final SpringCloudConfigClientConfig config) { boolean inAppCDsGeneration = Boolean - .parseBoolean(System.getProperty(AppCDSRecorder.QUARKUS_APPCDS_GENERATE_PROP, "false")); + .parseBoolean(System.getProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP, "false")); if (inAppCDsGeneration) { return Collections.emptyList(); } diff --git a/extensions/spring-cloud-config-client/runtime/src/test/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactoryTest.java b/extensions/spring-cloud-config-client/runtime/src/test/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactoryTest.java index cc29d9fcbf427..384bf24e3c777 100644 --- a/extensions/spring-cloud-config-client/runtime/src/test/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactoryTest.java +++ b/extensions/spring-cloud-config-client/runtime/src/test/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactoryTest.java @@ -22,7 +22,7 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; -import io.quarkus.arc.runtime.appcds.AppCDSRecorder; +import io.quarkus.runtime.ApplicationLifecycleManager; import io.smallrye.config.ConfigSourceContext; class SpringCloudConfigClientConfigSourceFactoryTest { @@ -80,13 +80,13 @@ void testInAppCDsGeneration() { final SpringCloudConfigClientConfig config = configForTesting(true, "foo", MOCK_SERVER_PORT, true); final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory(); - System.setProperty(AppCDSRecorder.QUARKUS_APPCDS_GENERATE_PROP, "true"); + System.setProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP, "true"); // Act final Iterable configSourceIterable = factory.getConfigSources(context, config); // Clear property, because not necessary any more - System.clearProperty(AppCDSRecorder.QUARKUS_APPCDS_GENERATE_PROP); + System.clearProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP); // Assert assertThat(configSourceIterable).isEmpty();