Search in sources :

Example 1 with RunTimeConfigurationSourceValueBuildItem

use of io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem in project kogito-apps by kiegroup.

the class InmemoryPostgreSQLProcessor method startService.

@BuildStep
@Record(RUNTIME_INIT)
ServiceStartBuildItem startService(InmemoryPostgreSQLRecorder recorder, BuildProducer<RunTimeConfigurationSourceValueBuildItem> configSourceValueBuildItem) throws IOException {
    RuntimeValue<Integer> port = recorder.startPostgres();
    configSourceValueBuildItem.produce(new RunTimeConfigurationSourceValueBuildItem(recorder.configSources(port)));
    return new ServiceStartBuildItem(FEATURE);
}
Also used : ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) RunTimeConfigurationSourceValueBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Example 2 with RunTimeConfigurationSourceValueBuildItem

use of io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem in project quarkus by quarkusio.

the class RuntimeConfigSetupBuildStep method setupRuntimeConfig.

/**
 * Generates a StartupTask that sets up the final runtime configuration and thus runs before any StartupTask that uses
 * runtime configuration.
 * If there are recorders that produce a ConfigSourceProvider, these objects are used to set up the final runtime
 * configuration
 */
@BuildStep
@Consume(BootstrapConfigSetupCompleteBuildItem.class)
@Produce(RuntimeConfigSetupCompleteBuildItem.class)
void setupRuntimeConfig(List<RunTimeConfigurationSourceValueBuildItem> runTimeConfigurationSourceValues, BuildProducer<GeneratedClassBuildItem> generatedClass, BuildProducer<MainBytecodeRecorderBuildItem> mainBytecodeRecorder) {
    ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
    try (ClassCreator clazz = ClassCreator.builder().classOutput(classOutput).className(RUNTIME_CONFIG_STARTUP_TASK_CLASS_NAME).interfaces(StartupTask.class).build()) {
        try (MethodCreator method = clazz.getMethodCreator("deploy", void.class, StartupContext.class)) {
            method.invokeVirtualMethod(ofMethod(StartupContext.class, "setCurrentBuildStepName", void.class, String.class), method.getMethodParam(0), method.load("RuntimeConfigSetupBuildStep.setupRuntimeConfig"));
            ResultHandle config = method.readStaticField(C_INSTANCE);
            if (runTimeConfigurationSourceValues.isEmpty()) {
                method.invokeVirtualMethod(RunTimeConfigurationGenerator.C_READ_CONFIG, config, method.invokeStaticMethod(ofMethod(Collections.class, "emptyList", List.class)));
            } else {
                ResultHandle startupContext = method.getMethodParam(0);
                ResultHandle configSourcesProvidersList = method.newInstance(ofConstructor(ArrayList.class, int.class), method.load(runTimeConfigurationSourceValues.size()));
                for (RunTimeConfigurationSourceValueBuildItem runTimeConfigurationSourceValue : runTimeConfigurationSourceValues) {
                    RuntimeValue<ConfigSourceProvider> runtimeValue = runTimeConfigurationSourceValue.getConfigSourcesValue();
                    if (runtimeValue instanceof BytecodeRecorderImpl.ReturnedProxy) {
                        String proxyId = ((BytecodeRecorderImpl.ReturnedProxy) runtimeValue).__returned$proxy$key();
                        ResultHandle value = method.invokeVirtualMethod(ofMethod(StartupContext.class, "getValue", Object.class, String.class), startupContext, method.load(proxyId));
                        ResultHandle configSourceProvider = method.invokeVirtualMethod(ofMethod(RuntimeValue.class, "getValue", Object.class), method.checkCast(value, RuntimeValue.class));
                        method.invokeVirtualMethod(MethodDescriptor.ofMethod(ArrayList.class, "add", boolean.class, Object.class), configSourcesProvidersList, method.checkCast(configSourceProvider, ConfigSourceProvider.class));
                    } else {
                        log.warn("RuntimeValue " + runtimeValue + " was not produced by a recorder and it will thus be ignored");
                    }
                }
                method.invokeVirtualMethod(RunTimeConfigurationGenerator.C_READ_CONFIG, config, configSourcesProvidersList);
            }
            method.returnValue(null);
        }
    }
    mainBytecodeRecorder.produce(new MainBytecodeRecorderBuildItem(RUNTIME_CONFIG_STARTUP_TASK_CLASS_NAME));
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) ArrayList(java.util.ArrayList) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) ClassCreator(io.quarkus.gizmo.ClassCreator) StartupTask(io.quarkus.runtime.StartupTask) ConfigSourceProvider(org.eclipse.microprofile.config.spi.ConfigSourceProvider) MethodCreator(io.quarkus.gizmo.MethodCreator) ClassOutput(io.quarkus.gizmo.ClassOutput) ResultHandle(io.quarkus.gizmo.ResultHandle) RuntimeValue(io.quarkus.runtime.RuntimeValue) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem) RunTimeConfigurationSourceValueBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem) Consume(io.quarkus.deployment.annotations.Consume) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)2 RunTimeConfigurationSourceValueBuildItem (io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem)2 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)1 Consume (io.quarkus.deployment.annotations.Consume)1 Produce (io.quarkus.deployment.annotations.Produce)1 Record (io.quarkus.deployment.annotations.Record)1 MainBytecodeRecorderBuildItem (io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem)1 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)1 ClassCreator (io.quarkus.gizmo.ClassCreator)1 ClassOutput (io.quarkus.gizmo.ClassOutput)1 MethodCreator (io.quarkus.gizmo.MethodCreator)1 ResultHandle (io.quarkus.gizmo.ResultHandle)1 RuntimeValue (io.quarkus.runtime.RuntimeValue)1 StartupContext (io.quarkus.runtime.StartupContext)1 StartupTask (io.quarkus.runtime.StartupTask)1 ArrayList (java.util.ArrayList)1 ConfigSourceProvider (org.eclipse.microprofile.config.spi.ConfigSourceProvider)1