Skip to content

Commit

Permalink
Merge pull request #43859 from geoand/#43768
Browse files Browse the repository at this point in the history
Ensure that AppCDS works properly with command line applications
  • Loading branch information
geoand authored Oct 15, 2024
2 parents 6c67d81 + 93ec6bb commit 92b0659
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -117,8 +119,9 @@ public static void run(Application application, Class<? extends QuarkusApplicati
try {

application.start(args);
//now we are started, we either run the main application or just wait to exit
if (quarkusApplication != null) {
// now we are started, we either run the main application or just wait to exit
// when we are in AppCDS generation we can't call the bean container, we just want to fall through to the exit
if (quarkusApplication != null && !isAppCDSGeneration()) {
BeanManager beanManager = CDI.current().getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(quarkusApplication, Any.Literal.INSTANCE);
Bean<?> bean = null;
Expand Down Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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;

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +24,7 @@ static class KubernetesConfigFactory implements ConfigurableConfigSourceFactory<
public Iterable<ConfigSource> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +26,7 @@ public class SpringCloudConfigClientConfigSourceFactory
public Iterable<ConfigSource> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ConfigSource> 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();
Expand Down

0 comments on commit 92b0659

Please sign in to comment.