Search in sources :

Example 1 with Produce

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);
}
Also used : EventLoopSupplierBuildItem(io.quarkus.netty.deployment.EventLoopSupplierBuildItem) Consumer(java.util.function.Consumer) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Vertx(io.vertx.core.Vertx) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep) LogRecord(java.util.logging.LogRecord) Record(io.quarkus.deployment.annotations.Record)

Example 2 with Produce

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;
}
Also used : TestConsoleHandler(io.quarkus.deployment.dev.testing.TestConsoleHandler) ConsoleRuntimeConfig(io.quarkus.runtime.console.ConsoleRuntimeConfig) TestListenerBuildItem(io.quarkus.deployment.dev.testing.TestListenerBuildItem) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with Produce

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));
}
Also used : DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) DevServicesConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem) HashMap(java.util.HashMap) Config(org.eclipse.microprofile.config.Config) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) HashMap(java.util.HashMap) Map(java.util.Map) RunTimeConfigurationDefaultBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with Produce

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

Example 5 with Produce

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));
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) MethodCreator(io.quarkus.gizmo.MethodCreator) ClassOutput(io.quarkus.gizmo.ClassOutput) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) ClassCreator(io.quarkus.gizmo.ClassCreator) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem) StartupTask(io.quarkus.runtime.StartupTask) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)12 Produce (io.quarkus.deployment.annotations.Produce)12 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)3 Consume (io.quarkus.deployment.annotations.Consume)3 Record (io.quarkus.deployment.annotations.Record)3 MainBytecodeRecorderBuildItem (io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem)3 Map (java.util.Map)3 Consumer (java.util.function.Consumer)3 Config (org.eclipse.microprofile.config.Config)3 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)2 DevServicesResultBuildItem (io.quarkus.deployment.builditem.DevServicesResultBuildItem)2 DevModeType (io.quarkus.dev.spi.DevModeType)2 ClassCreator (io.quarkus.gizmo.ClassCreator)2 ClassOutput (io.quarkus.gizmo.ClassOutput)2 MethodCreator (io.quarkus.gizmo.MethodCreator)2 StartupContext (io.quarkus.runtime.StartupContext)2 StartupTask (io.quarkus.runtime.StartupTask)2 List (java.util.List)2