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