Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ProfileManager #39194

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -175,7 +174,7 @@ void build(List<StaticBytecodeRecorderBuildItem> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -277,11 +275,7 @@ private BuildResult runAugment(boolean firstRun, Set<String> 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())
Expand Down Expand Up @@ -337,7 +331,6 @@ private BuildResult runAugment(boolean firstRun, Set<String> changedResources,
throw new RuntimeException(e);
}
} finally {
ProfileManager.setRuntimeDefaultProfile(null);
Thread.currentThread().setContextClassLoader(old);
QuarkusConfigFactory.setConfig(null);
}
Expand Down
10 changes: 7 additions & 3 deletions core/runtime/src/main/java/io/quarkus/runtime/LaunchMode.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.runtime;

import io.quarkus.runtime.configuration.ProfileManager;

public enum LaunchMode {

/**
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -260,7 +259,7 @@ private EventConsumerInvoker createInvoker(String invokerClassName) {
@SuppressWarnings("unchecked")
private void registerCodecs(Map<Class<?>, Class<?>> codecByClass, List<Class<?>> selectorTypes) {
EventBus eventBus = vertx.eventBus();
boolean isDevMode = ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT;
boolean isDevMode = LaunchMode.current() == LaunchMode.DEVELOPMENT;
for (Map.Entry<Class<?>, Class<?>> codecEntry : codecByClass.entrySet()) {
Class<?> target = codecEntry.getKey();
Class<?> codec = codecEntry.getValue();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,7 +165,7 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class<? extend
additional.put("quarkus.arc.test.disable-application-lifecycle-observers", "true");
}
if (profileInstance.getConfigProfile() != null) {
additional.put(ProfileManager.QUARKUS_TEST_PROFILE_PROP, profileInstance.getConfigProfile());
additional.put(LaunchMode.TEST.getProfileKey(), profileInstance.getConfigProfile());
}
//we just use system properties for now
//it's a lot simpler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.quarkus.bootstrap.logging.InitialConfigurator;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.ProfileManager;

/**
* A (global) JUnit callback that enables/sets up basic logging if logging has not already been set up.
Expand Down Expand Up @@ -132,7 +131,7 @@ public synchronized void beforeAll(ExtensionContext context) {

private static Config buildConfig() {
// make sure to load ConfigSources with the proper LaunchMode in place
ProfileManager.setLaunchMode(LaunchMode.TEST);
LaunchMode.set(LaunchMode.TEST);
// notes:
// - addDiscovered might seem a bit much, but this ensures that yaml files are loaded (if extension is around)
// - LaunchMode.NORMAL instead of TEST avoids failing on missing RuntimeOverrideConfigSource$$GeneratedMapHolder
Expand Down
Loading
Loading