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);
}
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));
}
Aggregations