Java Code Examples for io.quarkus.runtime.configuration.ProfileManager#setLaunchMode()

The following examples show how to use io.quarkus.runtime.configuration.ProfileManager#setLaunchMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfileManagerTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 2
Source File: ProfileManagerTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 3
Source File: ProfileManagerTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 4
Source File: ProfileManagerTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void testCustomRuntimeProfile(LaunchMode launchMode) {
    ProfileManager.setLaunchMode(launchMode);
    String customProfile = "foo";
    ProfileManager.setRuntimeDefaultProfile(customProfile);
    Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile());
}
 
Example 5
Source File: ProfileManagerTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void testDefaultProfile(LaunchMode launchMode) {
    ProfileManager.setLaunchMode(launchMode);
    Assertions.assertEquals(launchMode.getDefaultProfile(), ProfileManager.getActiveProfile());
}
 
Example 6
Source File: AugmentActionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * Runs a custom augmentation action, such as generating config.
 *
 * @param chainBuild A consumer that customises the build to select the output targets
 * @param executionBuild A consumer that can see the initial build execution
 * @return The build result
 */
public BuildResult runCustomAction(Consumer<BuildChainBuilder> chainBuild, Consumer<BuildExecutionBuilder> executionBuild) {
    ProfileManager.setLaunchMode(launchMode);
    QuarkusClassLoader classLoader = curatedApplication.getAugmentClassLoader();

    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);

        final BuildChainBuilder chainBuilder = BuildChain.builder();
        chainBuilder.setClassLoader(classLoader);

        ExtensionLoader.loadStepsFrom(classLoader).accept(chainBuilder);
        chainBuilder.loadProviders(classLoader);

        for (Consumer<BuildChainBuilder> c : chainCustomizers) {
            c.accept(chainBuilder);
        }
        chainBuilder
                .addInitial(ShutdownContextBuildItem.class)
                .addInitial(LaunchModeBuildItem.class)
                .addInitial(LiveReloadBuildItem.class)
                .addInitial(RawCommandLineArgumentsBuildItem.class)
                .addFinal(ConfigDescriptionBuildItem.class);
        chainBuild.accept(chainBuilder);

        BuildChain chain = chainBuilder
                .build();
        BuildExecutionBuilder execBuilder = chain.createExecutionBuilder("main")
                .produce(new LaunchModeBuildItem(launchMode))
                .produce(new ShutdownContextBuildItem())
                .produce(new RawCommandLineArgumentsBuildItem())
                .produce(new LiveReloadBuildItem());
        executionBuild.accept(execBuilder);
        return execBuilder
                .execute();
    } catch (Exception e) {
        throw new RuntimeException("Failed to run task", e);
    } finally {
        try {
            ConfigProviderResolver.instance().releaseConfig(ConfigProviderResolver.instance().getConfig(classLoader));
        } catch (Exception ignore) {

        }
        Thread.currentThread().setContextClassLoader(old);
    }
}