23
23
import java .util .List ;
24
24
import java .util .Map ;
25
25
import java .util .NoSuchElementException ;
26
+ import java .util .Set ;
26
27
import java .util .stream .Stream ;
27
28
import java .util .stream .StreamSupport ;
28
29
51
52
*/
52
53
class ConfigDataEnvironmentContributor implements Iterable <ConfigDataEnvironmentContributor > {
53
54
55
+ private static final Set <ConfigData .Option > EMPTY_LOCATION_OPTIONS = Collections
56
+ .unmodifiableSet (Collections .singleton (ConfigData .Option .IGNORE_IMPORTS ));
57
+
54
58
private final ConfigDataLocation location ;
55
59
56
60
private final ConfigDataResource resource ;
@@ -63,7 +67,7 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
63
67
64
68
private final ConfigDataProperties properties ;
65
69
66
- private final boolean ignoreImports ;
70
+ private final Set < ConfigData . Option > configDataOptions ;
67
71
68
72
private final Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ;
69
73
@@ -79,21 +83,22 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
79
83
* @param configurationPropertySource the configuration property source for the data
80
84
* or {@code null}
81
85
* @param properties the config data properties or {@code null}
82
- * @param ignoreImports if import properties should be ignored
86
+ * @param configDataOptions any config data options that should apply
83
87
* @param children the children of this contributor at each {@link ImportPhase}
84
88
*/
85
89
ConfigDataEnvironmentContributor (Kind kind , ConfigDataLocation location , ConfigDataResource resource ,
86
90
boolean profileSpecific , PropertySource <?> propertySource ,
87
91
ConfigurationPropertySource configurationPropertySource , ConfigDataProperties properties ,
88
- boolean ignoreImports , Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ) {
92
+ Set <ConfigData .Option > configDataOptions ,
93
+ Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ) {
89
94
this .kind = kind ;
90
95
this .location = location ;
91
96
this .resource = resource ;
92
97
this .profileSpecific = profileSpecific ;
93
98
this .properties = properties ;
94
99
this .propertySource = propertySource ;
95
100
this .configurationPropertySource = configurationPropertySource ;
96
- this .ignoreImports = ignoreImports ;
101
+ this .configDataOptions = ( configDataOptions != null ) ? configDataOptions : Collections . emptySet () ;
97
102
this .children = (children != null ) ? children : Collections .emptyMap ();
98
103
}
99
104
@@ -150,6 +155,15 @@ ConfigurationPropertySource getConfigurationPropertySource() {
150
155
return this .configurationPropertySource ;
151
156
}
152
157
158
+ /**
159
+ * Returns {@code true} if this contributor is not ignoring profile properties.
160
+ * @return if the contributor is not ignoring profiles
161
+ * @see ConfigData.Option#IGNORE_PROFILES
162
+ */
163
+ boolean isNotIgnoringProfiles () {
164
+ return !this .configDataOptions .contains (ConfigData .Option .IGNORE_PROFILES );
165
+ }
166
+
153
167
/**
154
168
* Return any imports requested by this contributor.
155
169
* @return the imports
@@ -209,12 +223,12 @@ public Iterator<ConfigDataEnvironmentContributor> iterator() {
209
223
ConfigDataEnvironmentContributor withBoundProperties (Binder binder ) {
210
224
UseLegacyConfigProcessingException .throwIfRequested (binder );
211
225
ConfigDataProperties properties = ConfigDataProperties .get (binder );
212
- if (this .ignoreImports ) {
226
+ if (this .configDataOptions . contains ( ConfigData . Option . IGNORE_IMPORTS ) ) {
213
227
properties = properties .withoutImports ();
214
228
}
215
229
return new ConfigDataEnvironmentContributor (Kind .BOUND_IMPORT , this .location , this .resource ,
216
230
this .profileSpecific , this .propertySource , this .configurationPropertySource , properties ,
217
- this .ignoreImports , null );
231
+ this .configDataOptions , null );
218
232
}
219
233
220
234
/**
@@ -229,7 +243,7 @@ ConfigDataEnvironmentContributor withChildren(ImportPhase importPhase,
229
243
Map <ImportPhase , List <ConfigDataEnvironmentContributor >> updatedChildren = new LinkedHashMap <>(this .children );
230
244
updatedChildren .put (importPhase , children );
231
245
return new ConfigDataEnvironmentContributor (this .kind , this .location , this .resource , this .profileSpecific ,
232
- this .propertySource , this .configurationPropertySource , this .properties , this .ignoreImports ,
246
+ this .propertySource , this .configurationPropertySource , this .properties , this .configDataOptions ,
233
247
updatedChildren );
234
248
}
235
249
@@ -255,7 +269,7 @@ ConfigDataEnvironmentContributor withReplacement(ConfigDataEnvironmentContributo
255
269
updatedChildren .put (importPhase , Collections .unmodifiableList (updatedContributors ));
256
270
});
257
271
return new ConfigDataEnvironmentContributor (this .kind , this .location , this .resource , this .profileSpecific ,
258
- this .propertySource , this .configurationPropertySource , this .properties , this .ignoreImports ,
272
+ this .propertySource , this .configurationPropertySource , this .properties , this .configDataOptions ,
259
273
updatedChildren );
260
274
}
261
275
@@ -267,7 +281,7 @@ ConfigDataEnvironmentContributor withReplacement(ConfigDataEnvironmentContributo
267
281
static ConfigDataEnvironmentContributor of (List <ConfigDataEnvironmentContributor > contributors ) {
268
282
Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children = new LinkedHashMap <>();
269
283
children .put (ImportPhase .BEFORE_PROFILE_ACTIVATION , Collections .unmodifiableList (contributors ));
270
- return new ConfigDataEnvironmentContributor (Kind .ROOT , null , null , false , null , null , null , false , children );
284
+ return new ConfigDataEnvironmentContributor (Kind .ROOT , null , null , false , null , null , null , null , children );
271
285
}
272
286
273
287
/**
@@ -281,7 +295,7 @@ static ConfigDataEnvironmentContributor ofInitialImport(ConfigDataLocation initi
281
295
List <ConfigDataLocation > imports = Collections .singletonList (initialImport );
282
296
ConfigDataProperties properties = new ConfigDataProperties (imports , null );
283
297
return new ConfigDataEnvironmentContributor (Kind .INITIAL_IMPORT , null , null , false , null , null , properties ,
284
- false , null );
298
+ null , null );
285
299
}
286
300
287
301
/**
@@ -293,7 +307,7 @@ static ConfigDataEnvironmentContributor ofInitialImport(ConfigDataLocation initi
293
307
*/
294
308
static ConfigDataEnvironmentContributor ofExisting (PropertySource <?> propertySource ) {
295
309
return new ConfigDataEnvironmentContributor (Kind .EXISTING , null , null , false , propertySource ,
296
- ConfigurationPropertySource .from (propertySource ), null , false , null );
310
+ ConfigurationPropertySource .from (propertySource ), null , null , null );
297
311
}
298
312
299
313
/**
@@ -311,9 +325,8 @@ static ConfigDataEnvironmentContributor ofUnboundImport(ConfigDataLocation locat
311
325
boolean profileSpecific , ConfigData configData , int propertySourceIndex ) {
312
326
PropertySource <?> propertySource = configData .getPropertySources ().get (propertySourceIndex );
313
327
ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource .from (propertySource );
314
- boolean ignoreImports = configData .getOptions ().contains (ConfigData .Option .IGNORE_IMPORTS );
315
328
return new ConfigDataEnvironmentContributor (Kind .UNBOUND_IMPORT , location , resource , profileSpecific ,
316
- propertySource , configurationPropertySource , null , ignoreImports , null );
329
+ propertySource , configurationPropertySource , null , configData . getOptions () , null );
317
330
}
318
331
319
332
/**
@@ -324,7 +337,7 @@ static ConfigDataEnvironmentContributor ofUnboundImport(ConfigDataLocation locat
324
337
*/
325
338
static ConfigDataEnvironmentContributor ofEmptyLocation (ConfigDataLocation location , boolean profileSpecific ) {
326
339
return new ConfigDataEnvironmentContributor (Kind .EMPTY_LOCATION , location , null , profileSpecific , null , null ,
327
- null , true , null );
340
+ null , EMPTY_LOCATION_OPTIONS , null );
328
341
}
329
342
330
343
/**
0 commit comments