-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19075 from stuartwdouglas/devservices-cleanup
Dev services cleanup
- Loading branch information
Showing
17 changed files
with
199 additions
and
189 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...yment/src/main/java/io/quarkus/deployment/builditem/DevServicesConfigResultBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...c/main/java/io/quarkus/deployment/builditem/DevServicesLauncherConfigResultBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> config; | ||
|
||
public DevServicesLauncherConfigResultBuildItem(Map<String, String> config) { | ||
this.config = config; | ||
} | ||
|
||
public Map<String, String> getConfig() { | ||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
core/deployment/src/main/java/io/quarkus/deployment/steps/DevServicesConfigBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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.LiveReloadBuildItem; | ||
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; | ||
import io.quarkus.deployment.builditem.ServiceStartBuildItem; | ||
|
||
class DevServicesConfigBuildStep { | ||
|
||
@BuildStep | ||
List<DevServicesConfigResultBuildItem> deprecated(List<DevServicesNativeConfigResultBuildItem> items) { | ||
return items.stream().map(s -> new DevServicesConfigResultBuildItem(s.getKey(), s.getValue())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@BuildStep | ||
@Produce(ServiceStartBuildItem.class) | ||
DevServicesLauncherConfigResultBuildItem setup(BuildProducer<RunTimeConfigurationDefaultBuildItem> runtimeConfig, | ||
List<DevServicesConfigResultBuildItem> devServicesConfigResultBuildItems, | ||
LiveReloadBuildItem liveReloadBuildItem) { | ||
Map<String, String> newProperties = new HashMap<>(devServicesConfigResultBuildItems.stream().collect( | ||
Collectors.toMap(DevServicesConfigResultBuildItem::getKey, DevServicesConfigResultBuildItem::getValue))); | ||
Config config = ConfigProvider.getConfig(); | ||
PreviousConfig oldProperties = liveReloadBuildItem.getContextObject(PreviousConfig.class); | ||
//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 | ||
if (oldProperties != null) { | ||
for (Map.Entry<String, String> entry : oldProperties.config.entrySet()) { | ||
if (!newProperties.containsKey(entry.getKey()) | ||
&& config.getOptionalValue(entry.getKey(), String.class).isEmpty()) { | ||
newProperties.put(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
} | ||
for (Map.Entry<String, String> entry : newProperties.entrySet()) { | ||
runtimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(entry.getKey(), entry.getValue())); | ||
} | ||
liveReloadBuildItem.setContextObject(PreviousConfig.class, new PreviousConfig(newProperties)); | ||
return new DevServicesLauncherConfigResultBuildItem(Collections.unmodifiableMap(newProperties)); | ||
} | ||
|
||
static class PreviousConfig { | ||
final Map<String, String> config; | ||
|
||
public PreviousConfig(Map<String, String> config) { | ||
this.config = config; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.