Search in sources :

Example 1 with DevServicesLauncherConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem in project quarkus by quarkusio.

the class ConfigEditorProcessor method handleRequests.

@BuildStep
void handleRequests(BuildProducer<DevConsoleRouteBuildItem> devConsoleRouteProducer, Optional<DevServicesLauncherConfigResultBuildItem> devServicesLauncherConfig) {
    CurrentConfig.EDITOR = ConfigEditorProcessor::updateConfig;
    devConsoleRouteProducer.produce(new DevConsoleRouteBuildItem("config/all", "GET", (e) -> {
        e.end(Buffer.buffer(getConfig()));
    }));
}
Also used : Arrays(java.util.Arrays) OptionCompleter(org.aesh.command.completer.OptionCompleter) DevConsolePostHandler(io.quarkus.devconsole.runtime.spi.DevConsolePostHandler) MultiMap(io.vertx.core.MultiMap) RoutingContext(io.vertx.ext.web.RoutingContext) DevConsoleRuntimeTemplateInfoBuildItem(io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem) HasDevServicesSupplier(io.quarkus.vertx.http.runtime.devmode.HasDevServicesSupplier) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Map(java.util.Map) CommandResult(org.aesh.command.CommandResult) CurrentConfig(io.quarkus.dev.config.CurrentConfig) DevConsoleManager(io.quarkus.dev.console.DevConsoleManager) GroupCommandDefinition(org.aesh.command.GroupCommandDefinition) Path(java.nio.file.Path) ConfigDescriptionBuildItem(io.quarkus.deployment.builditem.ConfigDescriptionBuildItem) ConfigDescriptionsManager(io.quarkus.vertx.http.runtime.devmode.ConfigDescriptionsManager) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) ConsoleCommandBuildItem(io.quarkus.deployment.builditem.ConsoleCommandBuildItem) Set(java.util.Set) CommandInvocation(org.aesh.command.invocation.CommandInvocation) Collectors(java.util.stream.Collectors) List(java.util.List) CommandValidatorException(org.aesh.command.validator.CommandValidatorException) Buffer(io.vertx.core.buffer.Buffer) CompleterInvocation(org.aesh.command.completer.CompleterInvocation) Optional(java.util.Optional) DEVELOPMENT(io.quarkus.runtime.LaunchMode.DEVELOPMENT) CommandValidator(org.aesh.command.validator.CommandValidator) CommandDefinition(org.aesh.command.CommandDefinition) Record(io.quarkus.deployment.annotations.Record) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) Command(org.aesh.command.Command) IsDevelopment(io.quarkus.deployment.IsDevelopment) Argument(org.aesh.command.option.Argument) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DevConsoleRouteBuildItem(io.quarkus.devconsole.spi.DevConsoleRouteBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) ConfigDescriptionsRecorder(io.quarkus.vertx.http.runtime.devmode.ConfigDescriptionsRecorder) GroupCommand(org.aesh.command.GroupCommand) Option(org.aesh.command.option.Option) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) ConfigDescription(io.quarkus.vertx.http.runtime.devmode.ConfigDescription) CommandException(org.aesh.command.CommandException) DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) ProfileManager(io.quarkus.runtime.configuration.ProfileManager) Collections(java.util.Collections) DevConsoleRouteBuildItem(io.quarkus.devconsole.spi.DevConsoleRouteBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with DevServicesLauncherConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem in project quarkus by quarkusio.

the class SwaggerUiProcessor method getSwaggerUiFinalDestination.

@BuildStep
public void getSwaggerUiFinalDestination(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, LaunchModeBuildItem launchMode, SwaggerUiConfig swaggerUiConfig, SmallRyeOpenApiConfig openapi, Optional<DevServicesLauncherConfigResultBuildItem> devServicesLauncherConfig, BuildProducer<WebJarBuildItem> webJarBuildProducer) throws Exception {
    if (shouldInclude(launchMode, swaggerUiConfig)) {
        if ("/".equals(swaggerUiConfig.path)) {
            throw new ConfigurationException("quarkus.swagger-ui.path was set to \"/\", this is not allowed as it blocks the application from serving anything else.", Set.of("quarkus.swagger-ui.path"));
        }
        if (openapi.path.equalsIgnoreCase(swaggerUiConfig.path)) {
            throw new ConfigurationException("quarkus.smallrye-openapi.path and quarkus.swagger-ui.path was set to the same value, this is not allowed as the paths needs to be unique [" + openapi.path + "].", Set.of("quarkus.smallrye-openapi.path", "quarkus.swagger-ui.path"));
        }
        if (devServicesLauncherConfig.isPresent()) {
            DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResult = devServicesLauncherConfig.get();
            Map<String, String> devServiceConfig = devServicesLauncherConfigResult.getConfig();
            if (devServiceConfig != null && !devServiceConfig.isEmpty()) {
                // Map client Id from OIDC Dev Services
                if (devServiceConfig.containsKey(OIDC_CLIENT_ID) && !swaggerUiConfig.oauthClientId.isPresent()) {
                    String clientId = devServiceConfig.get(OIDC_CLIENT_ID);
                    swaggerUiConfig.oauthClientId = Optional.of(clientId);
                }
            }
        }
        String openApiPath = nonApplicationRootPathBuildItem.resolvePath(openapi.path);
        String swaggerUiPath = nonApplicationRootPathBuildItem.resolvePath(swaggerUiConfig.path);
        ThemeHref theme = swaggerUiConfig.theme.orElse(ThemeHref.feeling_blue);
        NonApplicationRootPathBuildItem indexRootPathBuildItem = null;
        if (launchMode.getLaunchMode().isDevOrTest()) {
            indexRootPathBuildItem = nonApplicationRootPathBuildItem;
            // In dev mode, default to persist Authorization true
            if (!swaggerUiConfig.persistAuthorization.isPresent()) {
                swaggerUiConfig.persistAuthorization = Optional.of(true);
            }
        }
        byte[] indexHtmlContent = generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig, indexRootPathBuildItem);
        webJarBuildProducer.produce(// 
        WebJarBuildItem.builder().artifactKey(SWAGGER_UI_WEBJAR_ARTIFACT_KEY).root(// 
        SWAGGER_UI_WEBJAR_STATIC_RESOURCES_PATH).filter(new WebJarResourcesFilter() {

            @Override
            public FilterResult apply(String fileName, InputStream file) throws IOException {
                if (!fileName.equals(theme.toString()) && fileName.startsWith("theme-")) {
                    return new FilterResult(null, true);
                }
                if (fileName.endsWith("index.html")) {
                    return new FilterResult(new ByteArrayInputStream(indexHtmlContent), true);
                }
                return new FilterResult(file, false);
            }
        }).build());
    }
}
Also used : ThemeHref(io.smallrye.openapi.ui.ThemeHref) DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) WebJarResourcesFilter(io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter) ConfigurationException(io.quarkus.runtime.configuration.ConfigurationException) ByteArrayInputStream(java.io.ByteArrayInputStream) NonApplicationRootPathBuildItem(io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with DevServicesLauncherConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem 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 DevServicesLauncherConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem in project quarkus by quarkusio.

the class NativeDevServicesHandler method accept.

@Override
public void accept(Object o, BuildResult buildResult) {
    BiConsumer<String, String> propertyConsumer = (BiConsumer<String, String>) o;
    DevServicesLauncherConfigResultBuildItem devServicesProperties = buildResult.consume(DevServicesLauncherConfigResultBuildItem.class);
    for (var entry : devServicesProperties.getConfig().entrySet()) {
        propertyConsumer.accept(entry.getKey(), entry.getValue());
    }
}
Also used : DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) BiConsumer(java.util.function.BiConsumer)

Aggregations

DevServicesLauncherConfigResultBuildItem (io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)3 IOException (java.io.IOException)2 Map (java.util.Map)2 IsDevelopment (io.quarkus.deployment.IsDevelopment)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 Produce (io.quarkus.deployment.annotations.Produce)1 Record (io.quarkus.deployment.annotations.Record)1 ConfigDescriptionBuildItem (io.quarkus.deployment.builditem.ConfigDescriptionBuildItem)1 ConsoleCommandBuildItem (io.quarkus.deployment.builditem.ConsoleCommandBuildItem)1 DevServicesConfigResultBuildItem (io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem)1 DevServicesResultBuildItem (io.quarkus.deployment.builditem.DevServicesResultBuildItem)1 RunTimeConfigurationDefaultBuildItem (io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem)1 CurateOutcomeBuildItem (io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem)1 CurrentConfig (io.quarkus.dev.config.CurrentConfig)1 DevConsoleManager (io.quarkus.dev.console.DevConsoleManager)1 DevConsolePostHandler (io.quarkus.devconsole.runtime.spi.DevConsolePostHandler)1 DevConsoleRouteBuildItem (io.quarkus.devconsole.spi.DevConsoleRouteBuildItem)1 DevConsoleRuntimeTemplateInfoBuildItem (io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem)1