Search in sources :

Example 1 with ConsoleRuntimeConfig

use of io.quarkus.runtime.console.ConsoleRuntimeConfig 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 2 with ConsoleRuntimeConfig

use of io.quarkus.runtime.console.ConsoleRuntimeConfig in project quarkus by quarkusio.

the class ConsoleHelper method installConsole.

public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig, ConsoleRuntimeConfig consoleRuntimeConfig, io.quarkus.runtime.logging.ConsoleConfig logConfig, boolean test) {
    if (QuarkusConsole.installed) {
        return;
    }
    boolean colorEnabled = ColorSupport.isColorEnabled(consoleRuntimeConfig, logConfig);
    QuarkusConsole.installed = true;
    // if there is no color we need a basic console
    // note that we never enable input for tests
    // surefire communicates of stdin, so this can mess with it
    boolean inputSupport = !test && !config.disableConsoleInput.orElse(consoleConfig.disableInput);
    if (!inputSupport) {
        // note that in this case we don't hold onto anything from this class loader
        // which is important for the test suite
        QuarkusConsole.INSTANCE = new BasicConsole(colorEnabled, false, QuarkusConsole.ORIGINAL_OUT, System.console());
        return;
    }
    try {
        new TerminalConnection(new Consumer<Connection>() {

            @Override
            public void accept(Connection connection) {
                if (connection.supportsAnsi() && !config.basicConsole.orElse(consoleConfig.basic)) {
                    QuarkusConsole.INSTANCE = new AeshConsole(connection);
                } else {
                    LinkedBlockingDeque<Integer> queue = new LinkedBlockingDeque<>();
                    if (inputSupport) {
                        connection.openNonBlocking();
                    }
                    connection.setStdinHandler(new Consumer<int[]>() {

                        @Override
                        public void accept(int[] ints) {
                            QuarkusConsole.StateChangeInputStream redirectIn = QuarkusConsole.REDIRECT_IN;
                            for (int i : ints) {
                                if (redirectIn != null && !redirectIn.acceptInput(i)) {
                                    queue.add(i);
                                }
                            }
                        }
                    });
                    connection.setSignalHandler(event -> {
                        switch(event) {
                            case INT:
                                // todo: why does async exit not work here
                                // Quarkus.asyncExit();
                                // end(conn);
                                new Thread(new Runnable() {

                                    @Override
                                    public void run() {
                                        System.exit(0);
                                    }
                                }).start();
                                break;
                        }
                    });
                    connection.setCloseHandler(new Consumer<Void>() {

                        @Override
                        public void accept(Void unused) {
                            queue.add(-1);
                        }
                    });
                    QuarkusConsole.INSTANCE = new BasicConsole(colorEnabled, inputSupport, connection::write, new Supplier<Integer>() {

                        @Override
                        public Integer get() {
                            try {
                                return queue.takeFirst();
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    });
                }
            }
        });
    } catch (IOException e) {
        QuarkusConsole.INSTANCE = new BasicConsole(colorEnabled, false, QuarkusConsole.ORIGINAL_OUT, System.console());
    }
    QuarkusConsole.installRedirects();
}
Also used : Consumer(java.util.function.Consumer) Connection(org.aesh.terminal.Connection) BasicConsole(io.quarkus.dev.console.BasicConsole) QuarkusConsole(io.quarkus.dev.console.QuarkusConsole) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) IOException(java.io.IOException) TestConfig(io.quarkus.deployment.dev.testing.TestConfig) TerminalConnection(org.aesh.readline.tty.terminal.TerminalConnection) Supplier(java.util.function.Supplier) ColorSupport(io.quarkus.runtime.util.ColorSupport) ConsoleRuntimeConfig(io.quarkus.runtime.console.ConsoleRuntimeConfig) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) QuarkusConsole(io.quarkus.dev.console.QuarkusConsole) Connection(org.aesh.terminal.Connection) TerminalConnection(org.aesh.readline.tty.terminal.TerminalConnection) IOException(java.io.IOException) BasicConsole(io.quarkus.dev.console.BasicConsole) TerminalConnection(org.aesh.readline.tty.terminal.TerminalConnection) Consumer(java.util.function.Consumer)

Example 3 with ConsoleRuntimeConfig

use of io.quarkus.runtime.console.ConsoleRuntimeConfig in project quarkus by quarkusio.

the class LoggingResourceProcessor method setupLoggingRuntimeInit.

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
LoggingSetupBuildItem setupLoggingRuntimeInit(LoggingSetupRecorder recorder, LogConfig log, LogBuildTimeConfig buildLog, Optional<WebSocketLogHandlerBuildItem> logStreamHandlerBuildItem, List<LogHandlerBuildItem> handlerBuildItems, List<NamedLogHandlersBuildItem> namedHandlerBuildItems, List<LogConsoleFormatBuildItem> consoleFormatItems, Optional<ConsoleFormatterBannerBuildItem> possibleBannerBuildItem, List<LogStreamBuildItem> logStreamBuildItems, LaunchModeBuildItem launchModeBuildItem, List<LogCleanupFilterBuildItem> logCleanupFilters) {
    if (!launchModeBuildItem.isAuxiliaryApplication() || launchModeBuildItem.getAuxiliaryDevModeType().orElse(null) == DevModeType.TEST_ONLY) {
        final List<RuntimeValue<Optional<Handler>>> handlers = handlerBuildItems.stream().map(LogHandlerBuildItem::getHandlerValue).collect(Collectors.toList());
        final List<RuntimeValue<Map<String, Handler>>> namedHandlers = namedHandlerBuildItems.stream().map(NamedLogHandlersBuildItem::getNamedHandlersMap).collect(Collectors.toList());
        ConsoleFormatterBannerBuildItem bannerBuildItem = null;
        RuntimeValue<Optional<Supplier<String>>> possibleSupplier = null;
        if (possibleBannerBuildItem.isPresent()) {
            bannerBuildItem = possibleBannerBuildItem.get();
        }
        if (bannerBuildItem != null) {
            possibleSupplier = bannerBuildItem.getBannerSupplier();
        }
        // Dev UI Log Stream
        RuntimeValue<Optional<Handler>> devUiLogHandler = null;
        if (logStreamHandlerBuildItem.isPresent()) {
            devUiLogHandler = logStreamHandlerBuildItem.get().getHandlerValue();
        }
        boolean alwaysEnableLogStream = false;
        if (!logStreamBuildItems.isEmpty()) {
            alwaysEnableLogStream = true;
        }
        recorder.initializeLogging(log, buildLog, alwaysEnableLogStream, devUiLogHandler, handlers, namedHandlers, consoleFormatItems.stream().map(LogConsoleFormatBuildItem::getFormatterValue).collect(Collectors.toList()), possibleSupplier, launchModeBuildItem.getLaunchMode());
        LogConfig logConfig = new LogConfig();
        ConfigInstantiator.handleObject(logConfig);
        for (LogCleanupFilterBuildItem i : logCleanupFilters) {
            CleanupFilterConfig value = new CleanupFilterConfig();
            LogCleanupFilterElement filterElement = i.getFilterElement();
            value.ifStartsWith = filterElement.getMessageStarts();
            value.targetLevel = filterElement.getTargetLevel() == null ? org.jboss.logmanager.Level.DEBUG : filterElement.getTargetLevel();
            logConfig.filters.put(filterElement.getLoggerName(), value);
        }
        ConsoleRuntimeConfig crc = new ConsoleRuntimeConfig();
        ConfigInstantiator.handleObject(crc);
        LoggingSetupRecorder.initializeBuildTimeLogging(logConfig, buildLog, crc, launchModeBuildItem.getLaunchMode());
        ((QuarkusClassLoader) Thread.currentThread().getContextClassLoader()).addCloseTask(new Runnable() {

            @Override
            public void run() {
                InitialConfigurator.DELAYED_HANDLER.buildTimeComplete();
            }
        });
    }
    return new LoggingSetupBuildItem();
}
Also used : LogConsoleFormatBuildItem(io.quarkus.deployment.builditem.LogConsoleFormatBuildItem) Optional(java.util.Optional) Handler(java.util.logging.Handler) ConsoleRuntimeConfig(io.quarkus.runtime.console.ConsoleRuntimeConfig) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) ConsoleFormatterBannerBuildItem(io.quarkus.deployment.builditem.ConsoleFormatterBannerBuildItem) RuntimeValue(io.quarkus.runtime.RuntimeValue) CleanupFilterConfig(io.quarkus.runtime.logging.CleanupFilterConfig) LogCleanupFilterElement(io.quarkus.runtime.logging.LogCleanupFilterElement) LogConfig(io.quarkus.runtime.logging.LogConfig) BuildStep(io.quarkus.deployment.annotations.BuildStep) LogRecord(java.util.logging.LogRecord) Record(io.quarkus.deployment.annotations.Record)

Example 4 with ConsoleRuntimeConfig

use of io.quarkus.runtime.console.ConsoleRuntimeConfig in project quarkus by quarkusio.

the class LoggingSetupRecorder method handleFailedStart.

public static void handleFailedStart(RuntimeValue<Optional<Supplier<String>>> banner) {
    LogConfig config = new LogConfig();
    ConfigInstantiator.handleObject(config);
    LogBuildTimeConfig buildConfig = new LogBuildTimeConfig();
    ConfigInstantiator.handleObject(buildConfig);
    ConsoleRuntimeConfig consoleRuntimeConfig = new ConsoleRuntimeConfig();
    ConfigInstantiator.handleObject(consoleRuntimeConfig);
    new LoggingSetupRecorder(new RuntimeValue<>(consoleRuntimeConfig)).initializeLogging(config, buildConfig, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), banner, LaunchMode.DEVELOPMENT);
}
Also used : ConsoleRuntimeConfig(io.quarkus.runtime.console.ConsoleRuntimeConfig) RuntimeValue(io.quarkus.runtime.RuntimeValue)

Aggregations

ConsoleRuntimeConfig (io.quarkus.runtime.console.ConsoleRuntimeConfig)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)2 RuntimeValue (io.quarkus.runtime.RuntimeValue)2 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)1 Produce (io.quarkus.deployment.annotations.Produce)1 Record (io.quarkus.deployment.annotations.Record)1 ConsoleFormatterBannerBuildItem (io.quarkus.deployment.builditem.ConsoleFormatterBannerBuildItem)1 LogConsoleFormatBuildItem (io.quarkus.deployment.builditem.LogConsoleFormatBuildItem)1 TestConfig (io.quarkus.deployment.dev.testing.TestConfig)1 TestConsoleHandler (io.quarkus.deployment.dev.testing.TestConsoleHandler)1 TestListenerBuildItem (io.quarkus.deployment.dev.testing.TestListenerBuildItem)1 BasicConsole (io.quarkus.dev.console.BasicConsole)1 QuarkusConsole (io.quarkus.dev.console.QuarkusConsole)1 CleanupFilterConfig (io.quarkus.runtime.logging.CleanupFilterConfig)1 LogCleanupFilterElement (io.quarkus.runtime.logging.LogCleanupFilterElement)1 LogConfig (io.quarkus.runtime.logging.LogConfig)1 ColorSupport (io.quarkus.runtime.util.ColorSupport)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1