diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesConfigResultBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesConfigResultBuildItem.java new file mode 100644 index 0000000000000..0d98a21d0c42e --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesConfigResultBuildItem.java @@ -0,0 +1,29 @@ +package io.quarkus.deployment.builditem; + +import io.quarkus.builder.item.MultiBuildItem; + +/** + * Configuration property that is the result of start dev services. + * + * Used to start and configure dev services, any processor starting dev services should produce these items. + * + * Quarkus will make sure the relevant settings are present in both JVM and native modes. + */ +public final class DevServicesConfigResultBuildItem extends MultiBuildItem { + + final String key; + final String value; + + public DevServicesConfigResultBuildItem(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesLauncherConfigResultBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesLauncherConfigResultBuildItem.java new file mode 100644 index 0000000000000..bb8301df169cd --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesLauncherConfigResultBuildItem.java @@ -0,0 +1,21 @@ +package io.quarkus.deployment.builditem; + +import java.util.Map; + +import io.quarkus.builder.item.SimpleBuildItem; + +/** + * Build item that contains the final results of all + */ +public final class DevServicesLauncherConfigResultBuildItem extends SimpleBuildItem { + + final Map config; + + public DevServicesLauncherConfigResultBuildItem(Map config) { + this.config = config; + } + + public Map getConfig() { + return config; + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesNativeConfigResultBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesNativeConfigResultBuildItem.java index 06013effc05b5..94d8f30d12d34 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesNativeConfigResultBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesNativeConfigResultBuildItem.java @@ -3,10 +3,9 @@ import io.quarkus.builder.item.MultiBuildItem; /** - * Configuration property that is the result of start dev services. - * - * Used to start and configure dev services in native mode. + * see {@link DevServicesConfigResultBuildItem} and {@link DevServicesLauncherConfigResultBuildItem} */ +@Deprecated public final class DevServicesNativeConfigResultBuildItem extends MultiBuildItem { final String key; diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/DevServicesConfigBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/DevServicesConfigBuildStep.java new file mode 100644 index 0000000000000..941328c77c235 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/DevServicesConfigBuildStep.java @@ -0,0 +1,53 @@ +package io.quarkus.deployment.steps; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.Produce; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; +import io.quarkus.deployment.builditem.ServiceStartBuildItem; + +class DevServicesConfigBuildStep { + + private static volatile Map oldProperties = Collections.emptyMap(); + + @BuildStep + List deprecated(List items) { + return items.stream().map(s -> new DevServicesConfigResultBuildItem(s.getKey(), s.getValue())) + .collect(Collectors.toList()); + } + + @BuildStep + @Produce(ServiceStartBuildItem.class) + DevServicesLauncherConfigResultBuildItem setup(BuildProducer runtimeConfig, + List devServicesConfigResultBuildItems) { + Map newProperties = new HashMap<>(devServicesConfigResultBuildItems.stream().collect( + Collectors.toMap(DevServicesConfigResultBuildItem::getKey, DevServicesConfigResultBuildItem::getValue))); + Config config = ConfigProvider.getConfig(); + //check if there are existing already started dev services + //if there were no changes to the processors they don't produce config + //so we merge existing config from previous runs + //we also check the current config, as the dev service may have been disabled by explicit config + for (Map.Entry entry : oldProperties.entrySet()) { + if (!newProperties.containsKey(entry.getKey()) && config.getOptionalValue(entry.getKey(), String.class).isEmpty()) { + newProperties.put(entry.getKey(), entry.getValue()); + } + } + for (Map.Entry entry : newProperties.entrySet()) { + runtimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(entry.getKey(), entry.getValue())); + } + oldProperties = newProperties; + return new DevServicesLauncherConfigResultBuildItem(Collections.unmodifiableMap(newProperties)); + } +} diff --git a/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/ClasspathEntryRecordingBuildStep.java b/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/ClasspathEntryRecordingBuildStep.java index b405b08e1bb4f..53a7f0aeacace 100644 --- a/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/ClasspathEntryRecordingBuildStep.java +++ b/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/ClasspathEntryRecordingBuildStep.java @@ -12,7 +12,7 @@ import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Produce; import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.extest.runtime.classpath.ClasspathEntriesRecorder; import io.quarkus.extest.runtime.classpath.RecordedClasspathEntries; @@ -39,7 +39,7 @@ void registerRecordedClasspathEntries(ClasspathEntriesRecorder classpathEntriesR @Produce(FeatureBuildItem.class) // This makes sure we execute this in io.quarkus.test.junit.IntegrationTestUtil.handleDevDb, // so that we can reproduce a problem that happens in the Hibernate ORM extension. - @Produce(DevServicesNativeConfigResultBuildItem.class) + @Produce(DevServicesConfigResultBuildItem.class) void recordDuringAugmentation(TestBuildTimeConfig config) throws IOException { List resourcesToRecord = getResourcesToRecord(config); @@ -54,7 +54,7 @@ void recordDuringAugmentation(TestBuildTimeConfig config) @Record(ExecutionTime.STATIC_INIT) // This makes sure we execute this in io.quarkus.test.junit.IntegrationTestUtil.handleDevDb, // so that we can reproduce a problem that happens in the Hibernate ORM extension. - @Produce(DevServicesNativeConfigResultBuildItem.class) + @Produce(DevServicesConfigResultBuildItem.class) void recordDuringStaticInit(ClasspathEntriesRecorder classpathEntriesRecorder, TestBuildTimeConfig config) throws IOException { List resourcesToRecord = getResourcesToRecord(config); @@ -69,7 +69,7 @@ void recordDuringStaticInit(ClasspathEntriesRecorder classpathEntriesRecorder, T @Record(ExecutionTime.RUNTIME_INIT) // This makes sure we execute this in io.quarkus.test.junit.IntegrationTestUtil.handleDevDb, // so that we can reproduce a problem that happens in the Hibernate ORM extension. - @Produce(DevServicesNativeConfigResultBuildItem.class) + @Produce(DevServicesConfigResultBuildItem.class) void recordDuringRuntimeInit(ClasspathEntriesRecorder classpathEntriesRecorder, TestBuildTimeConfig config) throws IOException { List resourcesToRecord = getResourcesToRecord(config); diff --git a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java index 4f4c970774966..e56c6187136a2 100644 --- a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java +++ b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java @@ -14,10 +14,7 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.runtime.LaunchMode; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.runtime.configuration.ConfigUtils; /** @@ -39,19 +36,13 @@ public class DevServicesApicurioRegistryProcessor { private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); @BuildStep(onlyIfNot = IsNormal.class) - public void startApicurioRegistryDevService( - LaunchModeBuildItem launchMode, - ApicurioRegistryDevServicesBuildTimeConfig apicurioRegistryDevServices, - BuildProducer runTimeConfiguration, - BuildProducer devServicesConfiguration) { + public void startApicurioRegistryDevService(ApicurioRegistryDevServicesBuildTimeConfig apicurioRegistryDevServices, + BuildProducer devServicesConfiguration) { ApicurioRegistryDevServiceCfg configuration = getConfiguration(apicurioRegistryDevServices); if (closeable != null) { - boolean restartRequired = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!restartRequired) { - restartRequired = !configuration.equals(cfg); - } + boolean restartRequired = !configuration.equals(cfg); if (!restartRequired) { return; } @@ -67,9 +58,7 @@ public void startApicurioRegistryDevService( cfg = configuration; closeable = apicurioRegistry.getCloseable(); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem( - REGISTRY_URL_CONFIG, apicurioRegistry.getUrl() + "/apis/registry/v2")); - devServicesConfiguration.produce(new DevServicesNativeConfigResultBuildItem( + devServicesConfiguration.produce(new DevServicesConfigResultBuildItem( REGISTRY_URL_CONFIG, apicurioRegistry.getUrl() + "/apis/registry/v2")); log.infof("Dev Services for Apicurio Registry started. The registry is available at %s", apicurioRegistry.getUrl()); diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index 70ff0fde64a23..e8dd481ca2c6f 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -25,10 +25,8 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.runtime.LaunchMode; @@ -40,8 +38,6 @@ public class DevServicesDatasourceProcessor { static volatile Map cachedProperties; - static volatile List databaseConfig; - static volatile boolean first = true; private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); @@ -52,10 +48,8 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura List devDBProviders, DataSourcesBuildTimeConfig dataSourceBuildTimeConfig, LaunchModeBuildItem launchMode, - BuildProducer runTimeConfigurationDefaultBuildItemBuildProducer, List configurationHandlerBuildItems, - BuildProducer devServicesResultBuildItemBuildProducer, - BuildProducer serviceStartBuildItemBuildProducer) { + BuildProducer devServicesResultBuildItemBuildProducer) { //figure out if we need to shut down and restart existing databases //if not and the DB's have already started we just return if (databases != null) { @@ -80,9 +74,6 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura } } if (!restartRequired) { - for (RunTimeConfigurationDefaultBuildItem i : databaseConfig) { - runTimeConfigurationDefaultBuildItemBuildProducer.produce(i); - } return null; } for (Closeable i : databases) { @@ -94,7 +85,6 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura } databases = null; cachedProperties = null; - databaseConfig = null; } DevServicesDatasourceResultBuildItem.DbResult defaultResult; Map namedResults = new HashMap<>(); @@ -126,10 +116,10 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura devDBProviderMap, dataSourceBuildTimeConfig.defaultDataSource, configHandlersByDbType, propertiesMap, closeableList, launchMode.getLaunchMode()); - List dbConfig = new ArrayList<>(); + List dbConfig = new ArrayList<>(); if (defaultResult != null) { for (Map.Entry i : defaultResult.getConfigProperties().entrySet()) { - dbConfig.add(new RunTimeConfigurationDefaultBuildItem(i.getKey(), i.getValue())); + dbConfig.add(new DevServicesConfigResultBuildItem(i.getKey(), i.getValue())); } } for (Map.Entry entry : dataSourceBuildTimeConfig.namedDataSources.entrySet()) { @@ -140,15 +130,14 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura if (result != null) { namedResults.put(entry.getKey(), result); for (Map.Entry i : result.getConfigProperties().entrySet()) { - dbConfig.add(new RunTimeConfigurationDefaultBuildItem(i.getKey(), i.getValue())); + dbConfig.add(new DevServicesConfigResultBuildItem(i.getKey(), i.getValue())); } } } - for (RunTimeConfigurationDefaultBuildItem i : dbConfig) { - runTimeConfigurationDefaultBuildItemBuildProducer + for (DevServicesConfigResultBuildItem i : dbConfig) { + devServicesResultBuildItemBuildProducer .produce(i); } - databaseConfig = dbConfig; if (first) { first = false; @@ -182,19 +171,6 @@ public void run() { } databases = closeableList; cachedProperties = propertiesMap; - - if (defaultResult != null) { - for (Map.Entry entry : defaultResult.getConfigProperties().entrySet()) { - devServicesResultBuildItemBuildProducer - .produce(new DevServicesNativeConfigResultBuildItem(entry.getKey(), entry.getValue())); - } - } - for (DevServicesDatasourceResultBuildItem.DbResult i : namedResults.values()) { - for (Map.Entry entry : i.getConfigProperties().entrySet()) { - devServicesResultBuildItemBuildProducer - .produce(new DevServicesNativeConfigResultBuildItem(entry.getKey(), entry.getValue())); - } - } return new DevServicesDatasourceResultBuildItem(defaultResult, namedResults); } diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java index d71ac2d21d63e..26f00c4ad31c7 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java @@ -39,11 +39,9 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.devservices.common.ContainerAddress; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.runtime.LaunchMode; @@ -77,17 +75,12 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService( LaunchModeBuildItem launchMode, KafkaBuildTimeConfig kafkaClientBuildTimeConfig, Optional devServicesSharedNetworkBuildItem, - BuildProducer runTimeConfiguration, - BuildProducer devServicePropertiesProducer, - BuildProducer serviceStartBuildItemBuildProducer) { + BuildProducer devServicePropertiesProducer) { KafkaDevServiceCfg configuration = getConfiguration(kafkaClientBuildTimeConfig); if (closeable != null) { - boolean shouldShutdownTheBroker = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!shouldShutdownTheBroker) { - shouldShutdownTheBroker = !configuration.equals(cfg); - } + boolean shouldShutdownTheBroker = !configuration.equals(cfg); if (!shouldShutdownTheBroker) { return null; } @@ -99,7 +92,7 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService( DevServicesKafkaBrokerBuildItem bootstrapServers = null; if (kafkaBroker != null) { closeable = kafkaBroker.getCloseable(); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem( + devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem( KAFKA_BOOTSTRAP_SERVERS, kafkaBroker.getBootstrapServers())); bootstrapServers = new DevServicesKafkaBrokerBuildItem(kafkaBroker.getBootstrapServers()); } @@ -132,9 +125,6 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService( bootstrapServers.getBootstrapServers()); } createTopicPartitions(bootstrapServers.getBootstrapServers(), configuration); - - devServicePropertiesProducer.produce(new DevServicesNativeConfigResultBuildItem("kafka.bootstrap.servers", - bootstrapServers.getBootstrapServers())); } return bootstrapServers; diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index e382a94bbcbea..34af8000cb6bd 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -25,14 +25,10 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.mongodb.runtime.MongodbConfig; -import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.ConfigUtils; public class DevServicesMongoProcessor { @@ -48,11 +44,8 @@ public class DevServicesMongoProcessor { @BuildStep(onlyIfNot = IsNormal.class) public void startMongo(List mongoConnections, MongoClientBuildTimeConfig mongoClientBuildTimeConfig, - LaunchModeBuildItem launchMode, Optional devServicesSharedNetworkBuildItem, - BuildProducer runTimeConfiguration, - BuildProducer serviceStartBuildItemBuildProducer, - BuildProducer devServices) { + BuildProducer devServices) { List connectionNames = new ArrayList<>(mongoConnections.size()); for (MongoConnectionNameBuildItem mongoConnection : mongoConnections) { @@ -73,10 +66,7 @@ public void startMongo(List mongoConnections, //figure out if we need to shut down and restart existing databases //if not and the DB's have already started we just return if (closeables != null) { - boolean restartRequired = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!restartRequired) { - restartRequired = !currentCapturedProperties.equals(capturedProperties); - } + boolean restartRequired = !currentCapturedProperties.equals(capturedProperties); if (!restartRequired) { return; } @@ -101,10 +91,8 @@ public void startMongo(List mongoConnections, currentCloseables.add(startResult.getCloseable()); String connectionStringPropertyName = getConfigPrefix(connectionName) + "connection-string"; String connectionStringPropertyValue = startResult.getUrl(); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem( - connectionStringPropertyName, connectionStringPropertyValue)); devServices.produce( - new DevServicesNativeConfigResultBuildItem(connectionStringPropertyName, connectionStringPropertyValue)); + new DevServicesConfigResultBuildItem(connectionStringPropertyName, connectionStringPropertyValue)); } if (first) { diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java index b7e09b95fecf7..67e911d91a10f 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java @@ -18,7 +18,7 @@ public class KeycloakDevConsoleProcessor { @BuildStep(onlyIf = IsDevelopment.class) @Consume(RuntimeConfigSetupCompleteBuildItem.class) public void setConfigProperties(BuildProducer console, - Optional configProps) { + Optional configProps) { if (configProps.isPresent()) { console.produce( new DevConsoleTemplateInfoBuildItem("devServicesEnabled", config.devservices.enabled)); @@ -40,7 +40,7 @@ public void setConfigProperties(BuildProducer c @BuildStep(onlyIf = IsDevelopment.class) void invokeEndpoint(BuildProducer devConsoleRoute, - Optional configProps) { + Optional configProps) { if (configProps.isPresent()) { @SuppressWarnings("unchecked") Map users = (Map) configProps.get().getProperties().get("oidc.users"); diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfigBuildItem.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesConfigBuildItem.java similarity index 65% rename from extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfigBuildItem.java rename to extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesConfigBuildItem.java index 9d684a38d70f3..371725dc2c76a 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfigBuildItem.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesConfigBuildItem.java @@ -4,11 +4,11 @@ import io.quarkus.builder.item.SimpleBuildItem; -public final class DevServicesConfigBuildItem extends SimpleBuildItem { +public final class KeycloakDevServicesConfigBuildItem extends SimpleBuildItem { private final Map properties; - public DevServicesConfigBuildItem(Map configProperties) { + public KeycloakDevServicesConfigBuildItem(Map configProperties) { this.properties = configProperties; } diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 3a9c1ca59d7c9..27a7f4a3db144 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -37,10 +37,8 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; import io.quarkus.oidc.deployment.OidcBuildStep.IsEnabled; import io.quarkus.oidc.deployment.devservices.OidcDevServicesBuildItem; import io.quarkus.runtime.configuration.ConfigUtils; @@ -81,10 +79,9 @@ public class KeycloakDevServicesProcessor { private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); @BuildStep(onlyIfNot = IsNormal.class, onlyIf = IsEnabled.class) - public DevServicesConfigBuildItem startKeycloakContainer(LaunchModeBuildItem launchMode, + public KeycloakDevServicesConfigBuildItem startKeycloakContainer( Optional devServicesSharedNetworkBuildItem, - BuildProducer runTimeConfiguration, - BuildProducer devServices, + BuildProducer devServices, Optional oidcProviderBuildItem, KeycloakBuildTimeConfig config) { @@ -108,7 +105,7 @@ public DevServicesConfigBuildItem startKeycloakContainer(LaunchModeBuildItem lau } } if (!restartRequired) { - return prepareConfiguration(false, runTimeConfiguration, devServices); + return null; } for (Closeable closeable : closeables) { try { @@ -175,12 +172,11 @@ public void run() { vertxInstance = Vertx.vertx(); } capturedRealmFileLastModifiedDate = getRealmFileLastModifiedDate(capturedDevServicesConfiguration.realmPath); - return prepareConfiguration(!startResult.realmFileExists, runTimeConfiguration, devServices); + return prepareConfiguration(!startResult.realmFileExists, devServices); } - private DevServicesConfigBuildItem prepareConfiguration(boolean createRealm, - BuildProducer runTimeConfiguration, - BuildProducer devServices) { + private KeycloakDevServicesConfigBuildItem prepareConfiguration(boolean createRealm, + BuildProducer devServices) { final String authServerUrl = capturedKeycloakUrl + "/realms/" + capturedDevServicesConfiguration.realmName; String oidcClientId = getOidcClientId(); @@ -191,19 +187,11 @@ private DevServicesConfigBuildItem prepareConfiguration(boolean createRealm, if (createRealm) { createRealm(capturedKeycloakUrl, users, oidcClientId, oidcClientSecret); } - - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(KEYCLOAK_URL_KEY, capturedKeycloakUrl)); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(AUTH_SERVER_URL_CONFIG_KEY, authServerUrl)); - runTimeConfiguration - .produce(new RunTimeConfigurationDefaultBuildItem(APPLICATION_TYPE_CONFIG_KEY, oidcApplicationType)); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(CLIENT_ID_CONFIG_KEY, oidcClientId)); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(CLIENT_SECRET_CONFIG_KEY, oidcClientSecret)); - - devServices.produce(new DevServicesNativeConfigResultBuildItem(KEYCLOAK_URL_KEY, capturedKeycloakUrl)); - devServices.produce(new DevServicesNativeConfigResultBuildItem(AUTH_SERVER_URL_CONFIG_KEY, capturedKeycloakUrl)); - devServices.produce(new DevServicesNativeConfigResultBuildItem(APPLICATION_TYPE_CONFIG_KEY, oidcApplicationType)); - devServices.produce(new DevServicesNativeConfigResultBuildItem(CLIENT_ID_CONFIG_KEY, oidcClientId)); - devServices.produce(new DevServicesNativeConfigResultBuildItem(CLIENT_SECRET_CONFIG_KEY, oidcClientSecret)); + devServices.produce(new DevServicesConfigResultBuildItem(KEYCLOAK_URL_KEY, capturedKeycloakUrl)); + devServices.produce(new DevServicesConfigResultBuildItem(AUTH_SERVER_URL_CONFIG_KEY, authServerUrl)); + devServices.produce(new DevServicesConfigResultBuildItem(APPLICATION_TYPE_CONFIG_KEY, oidcApplicationType)); + devServices.produce(new DevServicesConfigResultBuildItem(CLIENT_ID_CONFIG_KEY, oidcClientId)); + devServices.produce(new DevServicesConfigResultBuildItem(CLIENT_SECRET_CONFIG_KEY, oidcClientSecret)); Map configProperties = new HashMap<>(); configProperties.put(KEYCLOAK_URL_KEY, capturedKeycloakUrl); @@ -213,7 +201,7 @@ private DevServicesConfigBuildItem prepareConfiguration(boolean createRealm, configProperties.put(CLIENT_SECRET_CONFIG_KEY, oidcClientSecret); configProperties.put(OIDC_USERS, users); - return new DevServicesConfigBuildItem(configProperties); + return new KeycloakDevServicesConfigBuildItem(configProperties); } private StartResult startContainer(boolean useSharedContainer) { diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java similarity index 90% rename from extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java rename to extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java index eb2d05dbd0d6d..65757f4ca122a 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java @@ -25,12 +25,9 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.Produce; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.redis.client.deployment.RedisBuildTimeConfig.DevServiceConfiguration; import io.quarkus.redis.client.runtime.RedisClientUtil; @@ -38,8 +35,8 @@ import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.ConfigUtils; -public class DevServicesProcessor { - private static final Logger log = Logger.getLogger(DevServicesProcessor.class); +public class DevServicesRedisProcessor { + private static final Logger log = Logger.getLogger(DevServicesRedisProcessor.class); private static final String REDIS_6_ALPINE = "redis:6-alpine"; private static final int REDIS_EXPOSED_PORT = 6379; private static final String REDIS_SCHEME = "redis://"; @@ -58,12 +55,10 @@ public class DevServicesProcessor { private static volatile Map capturedDevServicesConfiguration; private static volatile boolean first = true; - @Produce(ServiceStartBuildItem.class) @BuildStep(onlyIfNot = IsNormal.class, onlyIf = IsDockerRunningSilent.class) public void startRedisContainers(LaunchModeBuildItem launchMode, Optional devServicesSharedNetworkBuildItem, - BuildProducer runTimeConfiguration, - BuildProducer devConfigProducer, RedisBuildTimeConfig config) { + BuildProducer devConfigProducer, RedisBuildTimeConfig config) { Map currentDevServicesConfiguration = new HashMap<>(config.additionalDevServices); currentDevServicesConfiguration.put(RedisClientUtil.DEFAULT_CLIENT, config.defaultDevService); @@ -71,10 +66,7 @@ public void startRedisContainers(LaunchModeBuildItem launchMode, // figure out if we need to shut down and restart existing redis containers // if not and the redis containers have already started we just return if (closeables != null) { - boolean restartRequired = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!restartRequired) { - restartRequired = !currentDevServicesConfiguration.equals(capturedDevServicesConfiguration); - } + boolean restartRequired = !currentDevServicesConfiguration.equals(capturedDevServicesConfiguration); if (!restartRequired) { return; } @@ -100,8 +92,7 @@ public void startRedisContainers(LaunchModeBuildItem launchMode, } currentCloseables.add(startResult.closeable); String configKey = getConfigPrefix(connectionName) + RedisConfig.HOSTS_CONFIG_NAME; - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(configKey, startResult.url)); - devConfigProducer.produce(new DevServicesNativeConfigResultBuildItem(configKey, startResult.url)); + devConfigProducer.produce(new DevServicesConfigResultBuildItem(configKey, startResult.url)); } closeables = currentCloseables; diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java index 3bd08c9ad33b6..d56e6d4e74e18 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java @@ -17,10 +17,8 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.ConfigUtils; @@ -61,17 +59,12 @@ public class DevServicesAmqpProcessor { public DevServicesAmqpBrokerBuildItem startAmqpDevService( LaunchModeBuildItem launchMode, AmqpBuildTimeConfig amqpClientBuildTimeConfig, - BuildProducer runTimeConfiguration, - BuildProducer devServicePropertiesProducer, - BuildProducer serviceStartBuildItemBuildProducer) { + BuildProducer devServicePropertiesProducer) { AmqpDevServiceCfg configuration = getConfiguration(amqpClientBuildTimeConfig); if (closeable != null) { - boolean shouldShutdownTheBroker = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!shouldShutdownTheBroker) { - shouldShutdownTheBroker = !configuration.equals(cfg); - } + boolean shouldShutdownTheBroker = !configuration.equals(cfg); if (!shouldShutdownTheBroker) { return null; } @@ -83,13 +76,21 @@ public DevServicesAmqpBrokerBuildItem startAmqpDevService( DevServicesAmqpBrokerBuildItem artemis = null; if (broker != null) { closeable = broker.getCloseable(); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(AMQP_HOST_PROP, broker.host)); - runTimeConfiguration - .produce(new RunTimeConfigurationDefaultBuildItem(AMQP_PORT_PROP, Integer.toString(broker.port))); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(AMQP_USER_PROP, broker.user)); - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(AMQP_PASSWORD_PROP, broker.password)); + devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(AMQP_HOST_PROP, broker.host)); + devServicePropertiesProducer + .produce(new DevServicesConfigResultBuildItem(AMQP_PORT_PROP, Integer.toString(broker.port))); + devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(AMQP_USER_PROP, broker.user)); + devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(AMQP_PASSWORD_PROP, broker.password)); artemis = new DevServicesAmqpBrokerBuildItem(broker.host, broker.port, broker.user, broker.password); + + if (broker.isOwner()) { + log.infof( + "Dev Services for AMQP started. Other Quarkus applications in dev mode will find the " + + "broker automatically. For Quarkus applications in production mode, you can connect to" + + " this by starting your application with -Damqp.host=%s -Damqp.port=%d -Damqp.user=%s -Damqp.password=%s", + broker.host, broker.port, broker.user, broker.password); + } } // Configure the watch dog @@ -110,26 +111,6 @@ public DevServicesAmqpBrokerBuildItem startAmqpDevService( ((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread)); } cfg = configuration; - - if (broker != null) { - if (broker.isOwner()) { - log.infof( - "Dev Services for AMQP started. Other Quarkus applications in dev mode will find the " - + "broker automatically. For Quarkus applications in production mode, you can connect to" - + " this by starting your application with -Damqp.host=%s -Damqp.port=%d -Damqp.user=%s -Damqp.password=%s", - broker.host, broker.port, broker.user, broker.password); - devServicePropertiesProducer - .produce(new DevServicesNativeConfigResultBuildItem(AMQP_HOST_PROP, broker.host)); - devServicePropertiesProducer - .produce(new DevServicesNativeConfigResultBuildItem(AMQP_PORT_PROP, - Integer.toString(broker.port))); - devServicePropertiesProducer - .produce(new DevServicesNativeConfigResultBuildItem(AMQP_USER_PROP, broker.user)); - devServicePropertiesProducer - .produce(new DevServicesNativeConfigResultBuildItem(AMQP_PASSWORD_PROP, broker.password)); - } - } - return artemis; } diff --git a/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java b/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java index 349481f299ed2..6a0f58eab31b4 100644 --- a/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java +++ b/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java @@ -17,12 +17,7 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.Produce; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; -import io.quarkus.runtime.LaunchMode; +import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem; import io.quarkus.runtime.configuration.ConfigUtils; import io.quarkus.vault.runtime.VaultVersions; import io.quarkus.vault.runtime.config.DevServicesConfig; @@ -41,21 +36,15 @@ public class DevServicesVaultProcessor { private static volatile boolean first = true; private final IsDockerWorking isDockerWorking = new IsDockerWorking(true); - @Produce(ServiceStartBuildItem.class) @BuildStep(onlyIfNot = IsNormal.class) - public void startVaultContainers(LaunchModeBuildItem launchMode, - BuildProducer runTimeConfiguration, - BuildProducer devConfig, VaultBuildTimeConfig config) { + public void startVaultContainers(BuildProducer devConfig, VaultBuildTimeConfig config) { DevServicesConfig currentDevServicesConfiguration = config.devservices; // figure out if we need to shut down and restart any existing Vault container // if not and the Vault container have already started we just return if (closeables != null) { - boolean restartRequired = launchMode.getLaunchMode() == LaunchMode.TEST; - if (!restartRequired) { - restartRequired = !currentDevServicesConfiguration.equals(capturedDevServicesConfiguration); - } + boolean restartRequired = !currentDevServicesConfiguration.equals(capturedDevServicesConfiguration); if (!restartRequired) { return; } @@ -76,11 +65,6 @@ public void startVaultContainers(LaunchModeBuildItem launchMode, if (startResult == null) { return; } - - runTimeConfiguration.produce(new RunTimeConfigurationDefaultBuildItem(URL_CONFIG_KEY, startResult.url)); - runTimeConfiguration - .produce(new RunTimeConfigurationDefaultBuildItem(CLIENT_TOKEN_CONFIG_KEY, startResult.clientToken)); - Map connectionProperties = new HashMap<>(); connectionProperties.put(URL_CONFIG_KEY, startResult.url); connectionProperties.put(CLIENT_TOKEN_CONFIG_KEY, startResult.clientToken); @@ -118,7 +102,7 @@ public void run() { }); } for (Map.Entry entry : connectionProperties.entrySet()) { - devConfig.produce(new DevServicesNativeConfigResultBuildItem(entry.getKey(), entry.getValue())); + devConfig.produce(new DevServicesConfigResultBuildItem(entry.getKey(), entry.getValue())); } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java index 733aea732f09c..4c7ed2f6b1788 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java @@ -42,7 +42,7 @@ import io.quarkus.bootstrap.model.gradle.QuarkusModel; import io.quarkus.bootstrap.util.PathsUtils; import io.quarkus.bootstrap.utils.BuildToolHelper; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.test.common.ArtifactLauncher; import io.quarkus.test.common.PathTestHelper; @@ -276,7 +276,7 @@ static ArtifactLauncher.InitContext.DevServicesLaunchResult handleDevServices(Ex public void accept(String s, String s2) { propertyMap.put(s, s2); } - }, DevServicesNativeConfigResultBuildItem.class.getName()); + }, DevServicesLauncherConfigResultBuildItem.class.getName()); if (isDockerAppLaunch) { // obtain the ID of the shared network - this needs to be done after the augmentation has been run diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeDevServicesHandler.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeDevServicesHandler.java index 44b58f60efcd7..e863dcc6c8abe 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeDevServicesHandler.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeDevServicesHandler.java @@ -1,19 +1,18 @@ package io.quarkus.test.junit; -import java.util.List; import java.util.function.BiConsumer; import io.quarkus.builder.BuildResult; -import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem; +import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; public class NativeDevServicesHandler implements BiConsumer { @Override public void accept(Object o, BuildResult buildResult) { BiConsumer propertyConsumer = (BiConsumer) o; - List devServicesProperties = buildResult - .consumeMulti(DevServicesNativeConfigResultBuildItem.class); - for (DevServicesNativeConfigResultBuildItem entry : devServicesProperties) { + DevServicesLauncherConfigResultBuildItem devServicesProperties = buildResult + .consume(DevServicesLauncherConfigResultBuildItem.class); + for (var entry : devServicesProperties.getConfig().entrySet()) { propertyConsumer.accept(entry.getKey(), entry.getValue()); }