1414import java .util .Collections ;
1515import java .util .Enumeration ;
1616import java .util .HashMap ;
17+ import java .util .HashSet ;
1718import java .util .List ;
1819import java .util .Map ;
1920import java .util .Set ;
4546public final class EffectiveConfig {
4647 private final SmallRyeConfig config ;
4748 private final Map <String , String > values ;
49+ private final Map <String , String > quarkusValues ;
4850
4951 private EffectiveConfig (Builder builder ) {
5052 // Effective "ordinals" for the config sources:
@@ -90,6 +92,7 @@ private EffectiveConfig(Builder builder) {
9092 .withInterceptors (ConfigCompatibility .FrontEnd .instance (), ConfigCompatibility .BackEnd .instance ())
9193 .build ();
9294 this .values = generateFullConfigMap (config );
95+ this .quarkusValues = generateQuarkusConfigMap (config );
9396 }
9497
9598 public SmallRyeConfig getConfig () {
@@ -100,23 +103,8 @@ public Map<String, String> getValues() {
100103 return values ;
101104 }
102105
103- public Map <String , String > getOnlyQuarkusValues () {
104- return Expressions .withoutExpansion (new Supplier <Map <String , String >>() {
105- @ Override
106- public Map <String , String > get () {
107- Map <String , String > properties = new HashMap <>();
108- for (String propertyName : config .getPropertyNames ()) {
109- if (propertyName .startsWith ("quarkus." ) || propertyName .startsWith ("platform.quarkus." )) {
110- ConfigValue configValue = config .getConfigValue (propertyName );
111- if (configValue .getValue () != null
112- && !DefaultValuesConfigSource .NAME .equals (configValue .getConfigSourceName ())) {
113- properties .put (propertyName , configValue .getValue ());
114- }
115- }
116- }
117- return unmodifiableMap (properties );
118- }
119- });
106+ public Map <String , String > getQuarkusValues () {
107+ return quarkusValues ;
120108 }
121109
122110 private Map <String , String > asStringMap (Map <String , ?> map ) {
@@ -131,18 +119,48 @@ private Map<String, String> asStringMap(Map<String, ?> map) {
131119
132120 @ VisibleForTesting
133121 static Map <String , String > generateFullConfigMap (SmallRyeConfig config ) {
122+ Set <String > defaultNames = new HashSet <>();
123+ defaultNames .addAll (configClass (PackageConfig .class ).getProperties ().keySet ());
124+ defaultNames .addAll (configClass (NativeConfig .class ).getProperties ().keySet ());
134125 return Expressions .withoutExpansion (new Supplier <Map <String , String >>() {
135126 @ Override
136127 public Map <String , String > get () {
137128 Map <String , String > properties = new HashMap <>();
138129 for (String propertyName : config .getPropertyNames ()) {
139130 ConfigValue configValue = config .getConfigValue (propertyName );
140- if (configValue .getValue () != null ) {
131+ // Remove defaults coming from PackageConfig and NativeConfig, as this Map as passed as
132+ // system properties to Gradle workers and, we loose the ability to determine if it was set by
133+ // the user to evaluate deprecated configuration
134+ if (configValue .getValue () != null && (!defaultNames .contains (configValue .getName ())
135+ || !DefaultValuesConfigSource .NAME .equals (configValue .getConfigSourceName ()))) {
141136 properties .put (propertyName , configValue .getValue ());
142137 }
143138 }
144- configClass (PackageConfig .class ).getProperties ().keySet ().forEach (properties ::remove );
145- configClass (NativeConfig .class ).getProperties ().keySet ().forEach (properties ::remove );
139+ return unmodifiableMap (properties );
140+ }
141+ });
142+ }
143+
144+ static Map <String , String > generateQuarkusConfigMap (SmallRyeConfig config ) {
145+ Set <String > defaultNames = new HashSet <>();
146+ defaultNames .addAll (configClass (PackageConfig .class ).getProperties ().keySet ());
147+ defaultNames .addAll (configClass (NativeConfig .class ).getProperties ().keySet ());
148+ return Expressions .withoutExpansion (new Supplier <Map <String , String >>() {
149+ @ Override
150+ public Map <String , String > get () {
151+ Map <String , String > properties = new HashMap <>();
152+ for (String propertyName : config .getPropertyNames ()) {
153+ if (propertyName .startsWith ("quarkus." ) || propertyName .startsWith ("platform.quarkus." )) {
154+ ConfigValue configValue = config .getConfigValue (propertyName );
155+ // Remove defaults coming from PackageConfig and NativeConfig, as this Map as passed as
156+ // system properties to Gradle workers and, we loose the ability to determine if it was set by
157+ // the user to evaluate deprecated configuration
158+ if (configValue .getValue () != null && (!defaultNames .contains (configValue .getName ())
159+ || !DefaultValuesConfigSource .NAME .equals (configValue .getConfigSourceName ()))) {
160+ properties .put (propertyName , configValue .getValue ());
161+ }
162+ }
163+ }
146164 return unmodifiableMap (properties );
147165 }
148166 });
0 commit comments