Java Code Examples for io.quarkus.runtime.configuration.ProfileManager

The following examples show how to use io.quarkus.runtime.configuration.ProfileManager. These examples are extracted from open source projects. 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 Project: apicurio-registry   Source File: RegistryConfigSource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized Map<String, String> getProperties() {
    if (properties == null) {
        properties = new HashMap<>();
        String prefix = System.getenv("REGISTRY_PROPERTIES_PREFIX");
        if (prefix != null) {
            String profile = ProfileManager.getActiveProfile();
            String profilePrefix = "%" + profile + ".";
            Map<String, String> envMap = System.getenv();
            for (Map.Entry<String, String> entry : envMap.entrySet()) {
                String key = entry.getKey();
                if (key.startsWith(prefix)) {
                    String newKey = profilePrefix + key.replace("_", ".").toLowerCase();
                    properties.put(newKey, entry.getValue());
                }
            }
        }
    }
    return properties;
}
 
Example 2
Source Project: quarkus   Source File: SpringCloudConfigClientRecorder.java    License: Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ConfigSourceProvider> create(SpringCloudConfigClientConfig springCloudConfigClientConfig,
        ApplicationConfig applicationConfig) {
    if (!springCloudConfigClientConfig.enabled) {
        log.debug(
                "No attempt will be made to obtain configuration from the Spring Cloud Config Server because the functionality has been disabled via configuration");
        return emptyRuntimeValue();
    }

    if (!applicationConfig.name.isPresent()) {
        log.warn(
                "No attempt will be made to obtain configuration from the Spring Cloud Config Server because the application name has not been set. Consider setting it via 'quarkus.application.name'");
        return emptyRuntimeValue();
    }

    return new RuntimeValue<>(new SpringCloudConfigServerClientConfigSourceProvider(
            springCloudConfigClientConfig, applicationConfig.name.get(), ProfileManager.getActiveProfile()));
}
 
Example 3
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: 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 4
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: 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 5
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: 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 6
Source Project: quarkus   Source File: CRUDResource.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_PLAIN)
@Transactional
@Path("/import")
public Map<String, String> get() {
    boolean isProdMode = ProfileManager.getActiveProfile().equals(LaunchMode.NORMAL.getDefaultProfile());
    Gift gift = em.find(Gift.class, 100000L);
    Map<String, String> map = new HashMap<>();
    // Native tests are run under the 'prod' profile for now. In NORMAL mode, Quarkus doesn't execute the SQL import file
    // by default. That's why we don't expect a non-null gift in the following line in 'prod' mode.
    map.put("jpa", gift != null || isProdMode ? "OK" : "Boooo");
    return map;
}
 
Example 7
Source Project: quarkus   Source File: BuildTimeEnabledProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
void ifBuildProfile(CombinedIndexBuildItem index, BuildProducer<BuildTimeConditionBuildItem> producer) {
    Collection<AnnotationInstance> annotationInstances = index.getIndex().getAnnotations(IF_BUILD_PROFILE);
    for (AnnotationInstance instance : annotationInstances) {
        String profileOnInstance = instance.value().asString();
        boolean enabled = profileOnInstance.equals(ProfileManager.getActiveProfile());
        if (enabled) {
            LOGGER.debug("Enabling " + instance + " since the profile value matches the active profile.");
        } else {
            LOGGER.debug("Disabling " + instance + " since the profile value does not match the active profile.");
        }
        producer.produce(new BuildTimeConditionBuildItem(instance.target(), enabled));
    }
}
 
Example 8
Source Project: quarkus   Source File: BuildTimeEnabledProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
void unlessBuildProfile(CombinedIndexBuildItem index, BuildProducer<BuildTimeConditionBuildItem> producer) {
    Collection<AnnotationInstance> annotationInstances = index.getIndex().getAnnotations(UNLESS_BUILD_PROFILE);
    for (AnnotationInstance instance : annotationInstances) {
        String profileOnInstance = instance.value().asString();
        boolean enabled = !profileOnInstance.equals(ProfileManager.getActiveProfile());
        if (enabled) {
            LOGGER.debug("Enabling " + instance + " since the profile value does not match the active profile.");
        } else {
            LOGGER.debug("Disabling " + instance + " since the profile value matches the active profile.");
        }
        producer.produce(new BuildTimeConditionBuildItem(instance.target(), enabled));
    }
}
 
Example 9
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultTestProfile() {
    Assertions.assertEquals(LaunchMode.TEST.getDefaultProfile(), ProfileManager.getActiveProfile());
}
 
Example 10
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testCustomTestProfile() {
    String customProfile = "foo";
    System.setProperty(ProfileManager.QUARKUS_TEST_PROFILE_PROP, customProfile);
    Assertions.assertEquals(customProfile, ProfileManager.getActiveProfile());
}
 
Example 11
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: 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 12
Source Project: quarkus   Source File: ProfileManagerTestCase.java    License: 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 13
Source Project: quarkus   Source File: GrpcServerRecorder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void start(Promise<Void> startPromise) throws Exception {
    VertxServerBuilder builder = VertxServerBuilder
            .forAddress(getVertx(), configuration.host, configuration.port);

    AtomicBoolean usePlainText = new AtomicBoolean();
    builder.useSsl(new Handler<HttpServerOptions>() { // NOSONAR
        @Override
        public void handle(HttpServerOptions options) {
            try {
                usePlainText.set(applySslOptions(configuration, options));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });

    if (configuration.maxInboundMessageSize.isPresent()) {
        builder.maxInboundMessageSize(configuration.maxInboundMessageSize.getAsInt());
    }
    Optional<Duration> handshakeTimeout = configuration.handshakeTimeout;
    if (handshakeTimeout.isPresent()) {
        builder.handshakeTimeout(handshakeTimeout.get().toMillis(), TimeUnit.MILLISECONDS);
    }

    applyTransportSecurityConfig(configuration, builder);

    if (grpcContainer.getServices().isUnsatisfied()) {
        LOGGER.warn(
                "Unable to find bean exposing the `BindableService` interface - not starting the gRPC server");
        return;
    }

    boolean reflectionServiceEnabled = configuration.enableReflectionService
            || ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT;
    List<ServerServiceDefinition> definitions = gatherServices(grpcContainer.getServices());
    for (ServerServiceDefinition definition : definitions) {
        builder.addService(definition);
    }

    if (reflectionServiceEnabled) {
        LOGGER.info("Registering gRPC reflection service");
        builder.addService(new ReflectionService(definitions));
    }

    for (ServerInterceptor serverInterceptor : grpcContainer.getSortedInterceptors()) {
        builder.intercept(serverInterceptor);
    }

    LOGGER.debugf("Starting gRPC Server on %s:%d  [SSL enabled: %s]...",
            configuration.host, configuration.port, !usePlainText.get());

    VertxServer server = builder.build();
    grpcServer = server.start(new Handler<AsyncResult<Void>>() { // NOSONAR
        @Override
        public void handle(AsyncResult<Void> ar) {
            if (ar.failed()) {
                LOGGER.error("Unable to start the gRPC server", ar.cause());
                startPromise.fail(ar.cause());
            } else {
                startPromise.complete();
                grpcVerticleCount.incrementAndGet();
            }
        }
    });
}
 
Example 14
Source Project: quarkus   Source File: AugmentActionImpl.java    License: 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);
    }
}
 
Example 15
Source Project: hibernate-demos   Source File: ClientResource.java    License: Apache License 2.0 4 votes vote down vote up
@Transactional(TxType.NEVER)
void reindexOnStart(@Observes StartupEvent event) throws InterruptedException {
	if ( "dev".equals( ProfileManager.getActiveProfile() ) ) {
		reindex();
	}
}