@@ -93,7 +93,7 @@ class ConfigDataEnvironment {
9393 locations .add (ConfigDataLocation .of ("optional:file:./config/" ));
9494 locations .add (ConfigDataLocation .of ("optional:file:./config/*/" ));
9595 DEFAULT_SEARCH_LOCATIONS = locations .toArray (new ConfigDataLocation [0 ]);
96- };
96+ }
9797
9898 private static final ConfigDataLocation [] EMPTY_LOCATIONS = new ConfigDataLocation [0 ];
9999
@@ -119,6 +119,8 @@ class ConfigDataEnvironment {
119119
120120 private final Collection <String > additionalProfiles ;
121121
122+ private final ConfigDataEnvironmentUpdateListener environmentUpdateListener ;
123+
122124 private final ConfigDataLoaders loaders ;
123125
124126 private final ConfigDataEnvironmentContributors contributors ;
@@ -130,9 +132,13 @@ class ConfigDataEnvironment {
130132 * @param environment the Spring {@link Environment}.
131133 * @param resourceLoader {@link ResourceLoader} to load resource locations
132134 * @param additionalProfiles any additional profiles to activate
135+ * @param environmentUpdateListener optional
136+ * {@link ConfigDataEnvironmentUpdateListener} that can be used to track
137+ * {@link Environment} updates.
133138 */
134139 ConfigDataEnvironment (DeferredLogFactory logFactory , ConfigurableBootstrapContext bootstrapContext ,
135- ConfigurableEnvironment environment , ResourceLoader resourceLoader , Collection <String > additionalProfiles ) {
140+ ConfigurableEnvironment environment , ResourceLoader resourceLoader , Collection <String > additionalProfiles ,
141+ ConfigDataEnvironmentUpdateListener environmentUpdateListener ) {
136142 Binder binder = Binder .get (environment );
137143 UseLegacyConfigProcessingException .throwIfRequested (binder );
138144 this .logFactory = logFactory ;
@@ -143,6 +149,8 @@ class ConfigDataEnvironment {
143149 this .environment = environment ;
144150 this .resolvers = createConfigDataLocationResolvers (logFactory , bootstrapContext , binder , resourceLoader );
145151 this .additionalProfiles = additionalProfiles ;
152+ this .environmentUpdateListener = (environmentUpdateListener != null ) ? environmentUpdateListener
153+ : ConfigDataEnvironmentUpdateListener .NONE ;
146154 this .loaders = new ConfigDataLoaders (logFactory , bootstrapContext );
147155 this .contributors = createContributors (binder );
148156 }
@@ -301,16 +309,18 @@ private void applyToEnvironment(ConfigDataEnvironmentContributors contributors,
301309 MutablePropertySources propertySources = this .environment .getPropertySources ();
302310 this .logger .trace ("Applying config data environment contributions" );
303311 for (ConfigDataEnvironmentContributor contributor : contributors ) {
304- if ( contributor . getKind () == ConfigDataEnvironmentContributor . Kind . BOUND_IMPORT
305- && contributor .getPropertySource () != null ) {
312+ PropertySource <?> propertySource = contributor . getPropertySource ();
313+ if ( contributor .getKind () == ConfigDataEnvironmentContributor . Kind . BOUND_IMPORT && propertySource != null ) {
306314 if (!contributor .isActive (activationContext )) {
307- this .logger .trace (LogMessage . format ( "Skipping inactive property source '%s'" ,
308- contributor . getPropertySource () .getName ()));
315+ this .logger .trace (
316+ LogMessage . format ( "Skipping inactive property source '%s'" , propertySource .getName ()));
309317 }
310318 else {
311- this .logger .trace (LogMessage .format ("Adding imported property source '%s'" ,
312- contributor .getPropertySource ().getName ()));
313- propertySources .addLast (contributor .getPropertySource ());
319+ this .logger
320+ .trace (LogMessage .format ("Adding imported property source '%s'" , propertySource .getName ()));
321+ propertySources .addLast (propertySource );
322+ this .environmentUpdateListener .onPropertySourceAdded (propertySource , contributor .getLocation (),
323+ contributor .getResource ());
314324 }
315325 }
316326 }
@@ -320,6 +330,7 @@ private void applyToEnvironment(ConfigDataEnvironmentContributors contributors,
320330 this .environment .setDefaultProfiles (StringUtils .toStringArray (profiles .getDefault ()));
321331 this .logger .trace (LogMessage .format ("Setting active profiles: %s" , profiles .getActive ()));
322332 this .environment .setActiveProfiles (StringUtils .toStringArray (profiles .getActive ()));
333+ this .environmentUpdateListener .onSetProfiles (profiles );
323334 }
324335
325336 private void checkForInvalidProperties (ConfigDataEnvironmentContributors contributors ) {
0 commit comments