use of io.quarkus.deployment.annotations.Produce in project quarkus by quarkusio.
the class VertxCoreProcessor method build.
@BuildStep
@Produce(ServiceStartBuildItem.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
CoreVertxBuildItem build(VertxCoreRecorder recorder, LaunchModeBuildItem launchMode, ShutdownContextBuildItem shutdown, VertxConfiguration config, List<VertxOptionsConsumerBuildItem> vertxOptionsConsumers, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, BuildProducer<EventLoopSupplierBuildItem> eventLoops, ExecutorBuildItem executorBuildItem) {
Collections.sort(vertxOptionsConsumers);
List<Consumer<VertxOptions>> consumers = new ArrayList<>(vertxOptionsConsumers.size());
for (VertxOptionsConsumerBuildItem x : vertxOptionsConsumers) {
consumers.add(x.getConsumer());
}
Supplier<Vertx> vertx = recorder.configureVertx(config, launchMode.getLaunchMode(), shutdown, consumers, executorBuildItem.getExecutorProxy());
syntheticBeans.produce(SyntheticBeanBuildItem.configure(Vertx.class).types(Vertx.class).scope(Singleton.class).unremovable().setRuntimeInit().supplier(vertx).done());
// Event loops are only usable after the core vertx instance is configured
eventLoops.produce(new EventLoopSupplierBuildItem(recorder.mainSupplier(), recorder.bossSupplier()));
if (launchMode.getLaunchMode().isDevOrTest()) {
handleBlockingWarningsInDevOrTestMode();
}
return new CoreVertxBuildItem(vertx);
}
use of io.quarkus.deployment.annotations.Produce in project quarkus by quarkusio.
the class ConsoleProcessor method setupConsole.
/**
* Installs the interactive console for continuous testing (and other usages)
* <p>
* This is only installed for dev and test mode, and runs in the build process rather than
* a recorder to install this as early as possible
*/
@BuildStep(onlyIf = IsDevelopment.class)
@Produce(TestSetupBuildItem.class)
ConsoleInstalledBuildItem setupConsole(TestConfig config, BuildProducer<TestListenerBuildItem> testListenerBuildItemBuildProducer, LaunchModeBuildItem launchModeBuildItem, ConsoleConfig consoleConfig) {
if (consoleInstalled) {
return ConsoleInstalledBuildItem.INSTANCE;
}
consoleInstalled = true;
if (config.console.orElse(consoleConfig.enabled)) {
// this is a bit of a hack, but we can't just inject this normally
// this is a runtime property value, but also a build time property value
// as when running in dev mode they are both basically equivalent
ConsoleRuntimeConfig consoleRuntimeConfig = new ConsoleRuntimeConfig();
consoleRuntimeConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.console.color", Boolean.class);
io.quarkus.runtime.logging.ConsoleConfig loggingConsoleConfig = new io.quarkus.runtime.logging.ConsoleConfig();
loggingConsoleConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.log.console.color", Boolean.class);
ConsoleHelper.installConsole(config, consoleConfig, consoleRuntimeConfig, loggingConsoleConfig, launchModeBuildItem.isTest());
ConsoleStateManager.init(QuarkusConsole.INSTANCE, launchModeBuildItem.getDevModeType().get());
// note that this bit needs to be refactored so it is no longer tied to continuous testing
if (TestSupport.instance().isEmpty() || config.continuousTesting == TestConfig.Mode.DISABLED || config.flatClassPath) {
return ConsoleInstalledBuildItem.INSTANCE;
}
TestConsoleHandler consoleHandler = new TestConsoleHandler(launchModeBuildItem.getDevModeType().get());
consoleHandler.install();
testListenerBuildItemBuildProducer.produce(new TestListenerBuildItem(consoleHandler));
}
return ConsoleInstalledBuildItem.INSTANCE;
}
use of io.quarkus.deployment.annotations.Produce in project quarkus by quarkusio.
the class DevServicesConfigBuildStep method setup.
@BuildStep
@Produce(ServiceStartBuildItem.class)
DevServicesLauncherConfigResultBuildItem setup(BuildProducer<RunTimeConfigurationDefaultBuildItem> runtimeConfig, List<DevServicesConfigResultBuildItem> devServicesConfigResultBuildItems, List<DevServicesResultBuildItem> devServicesResultBuildItems, CuratedApplicationShutdownBuildItem shutdownBuildItem) {
Map<String, String> newProperties = new HashMap<>(devServicesConfigResultBuildItems.stream().collect(Collectors.toMap(DevServicesConfigResultBuildItem::getKey, DevServicesConfigResultBuildItem::getValue)));
for (DevServicesResultBuildItem resultBuildItem : devServicesResultBuildItems) {
newProperties.putAll(resultBuildItem.getConfig());
}
Config config = ConfigProvider.getConfig();
// we also check the current config, as the dev service may have been disabled by explicit config
if (oldConfig != null) {
for (Map.Entry<String, String> entry : oldConfig.entrySet()) {
if (!newProperties.containsKey(entry.getKey()) && config.getOptionalValue(entry.getKey(), String.class).isEmpty()) {
newProperties.put(entry.getKey(), entry.getValue());
}
}
} else {
shutdownBuildItem.addCloseTask(new Runnable() {
@Override
public void run() {
oldConfig = null;
}
}, true);
}
for (Map.Entry<String, String> entry : newProperties.entrySet()) {
runtimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(entry.getKey(), entry.getValue()));
}
oldConfig = newProperties;
return new DevServicesLauncherConfigResultBuildItem(Collections.unmodifiableMap(newProperties));
}
use of io.quarkus.deployment.annotations.Produce 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));
}
use of io.quarkus.deployment.annotations.Produce in project quarkus by quarkusio.
the class BootstrapConfigSetupBuildStep method setupBootstrapConfig.
/**
* Generates a StartupTask that creates a instance of the generated Config class
* It runs before any StartupTask that uses configuration
*/
@BuildStep
@Produce(BootstrapConfigSetupCompleteBuildItem.class)
void setupBootstrapConfig(BuildProducer<GeneratedClassBuildItem> generatedClass, BuildProducer<MainBytecodeRecorderBuildItem> mainBytecodeRecorder) {
ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
try (ClassCreator clazz = ClassCreator.builder().classOutput(classOutput).className(BOOTSTRAP_CONFIG_STARTUP_TASK_CLASS_NAME).interfaces(StartupTask.class).build()) {
try (MethodCreator deploy = clazz.getMethodCreator("deploy", void.class, StartupContext.class)) {
deploy.invokeVirtualMethod(ofMethod(StartupContext.class, "setCurrentBuildStepName", void.class, String.class), deploy.getMethodParam(0), deploy.load("BootstrapConfigSetupBuildStep.setupBootstrapConfig"));
deploy.invokeStaticMethod(C_CREATE_BOOTSTRAP_CONFIG);
deploy.returnValue(null);
}
}
mainBytecodeRecorder.produce(new MainBytecodeRecorderBuildItem(BOOTSTRAP_CONFIG_STARTUP_TASK_CLASS_NAME));
}
Aggregations