2020import java .util .Arrays ;
2121import java .util .Base64 ;
2222import java .util .HashMap ;
23+ import java .util .LinkedHashMap ;
2324import java .util .LinkedHashSet ;
2425import java .util .List ;
2526import java .util .Map ;
@@ -57,9 +58,9 @@ public final class ConfigUtils {
5758
5859 // sourceName (configmap or secret name) ends with : "-dev.yaml" or the like.
5960 private static final BiPredicate <String , String > ENDS_WITH_PROFILE_AND_EXTENSION = (sourceName ,
60- activeProfile ) -> sourceName .endsWith ("-" + activeProfile + ".yml" )
61- || sourceName .endsWith ("-" + activeProfile + ".yaml" )
62- || sourceName .endsWith ("-" + activeProfile + ".properties" );
61+ activeProfile ) -> sourceName .endsWith ("-" + activeProfile + ".yml" )
62+ || sourceName .endsWith ("-" + activeProfile + ".yaml" )
63+ || sourceName .endsWith ("-" + activeProfile + ".properties" );
6364
6465 private static final ApplicationListener <?> NO_OP = (e ) -> {
6566 };
@@ -70,7 +71,7 @@ private ConfigUtils() {
7071 public static String getApplicationName (Environment env , String configName , String configurationTarget ) {
7172 if (!StringUtils .hasLength (configName )) {
7273 LOG .debug (configurationTarget + " name has not been set, taking it from property/env "
73- + SPRING_APPLICATION_NAME + " (default=" + FALLBACK_APPLICATION_NAME + ")" );
74+ + SPRING_APPLICATION_NAME + " (default=" + FALLBACK_APPLICATION_NAME + ")" );
7475 configName = env .getProperty (SPRING_APPLICATION_NAME , FALLBACK_APPLICATION_NAME );
7576 }
7677
@@ -90,7 +91,7 @@ public static String getApplicationName(Environment env, String configName, Stri
9091 * @return prefix to use in normalized sources
9192 */
9293 public static Prefix findPrefix (String explicitPrefix , Boolean useNameAsPrefix , boolean defaultUseNameAsPrefix ,
93- String normalizedName ) {
94+ String normalizedName ) {
9495 // if explicitPrefix is set, it takes priority over useNameAsPrefix
9596 // (either the one from 'spring.cloud.kubernetes.config|secrets' or
9697 // 'spring.cloud.kubernetes.config|secrets.sources')
@@ -140,7 +141,7 @@ public static Prefix findPrefix(String explicitPrefix, Boolean useNameAsPrefix,
140141 * @return useProfileNameAsPrefix to be used in normalized sources
141142 */
142143 public static boolean includeProfileSpecificSources (boolean defaultIncludeProfileSpecificSources ,
143- Boolean includeProfileSpecificSources ) {
144+ Boolean includeProfileSpecificSources ) {
144145 if (includeProfileSpecificSources != null ) {
145146 return includeProfileSpecificSources ;
146147 }
@@ -157,21 +158,6 @@ public static void onException(boolean failFast, Exception e) {
157158 LOG .warn (e .getMessage () + ". Ignoring." , e );
158159 }
159160
160- /*
161- * This method will return a SourceData that has a name in the form :
162- * "configmap.my-configmap.my-configmap-2.namespace" and the "data" from the context
163- * is appended with prefix. So if incoming is "a=b", the result will be : "prefix.a=b"
164- */
165- @ Deprecated (forRemoval = true )
166- public static SourceData withPrefix (String target , PrefixContext context ) {
167- Map <String , Object > withPrefix = CollectionUtils .newHashMap (context .data ().size ());
168- context .data ().forEach ((key , value ) -> withPrefix .put (context .prefix () + "." + key , value ));
169-
170- String propertySourceTokens = String .join (PROPERTY_SOURCE_NAME_SEPARATOR ,
171- context .propertySourceNames ().stream ().sorted ().collect (Collectors .toCollection (LinkedHashSet ::new )));
172- return new SourceData (sourceName (target , propertySourceTokens , context .namespace ()), withPrefix );
173- }
174-
175161 public static String sourceName (String target , String applicationName , String namespace ) {
176162 return target + PROPERTY_SOURCE_NAME_SEPARATOR + applicationName + PROPERTY_SOURCE_NAME_SEPARATOR + namespace ;
177163 }
@@ -185,7 +171,7 @@ public static String sourceName(String target, String applicationName, String na
185171 }
186172
187173 public static MultipleSourcesContainer processNamedData (List <StrippedSourceContainer > strippedSources ,
188- Environment environment , LinkedHashSet <String > sourceNames , String namespace , boolean decode ) {
174+ Environment environment , LinkedHashSet <String > sourceNames , String namespace , boolean decode ) {
189175 return processNamedData (strippedSources , environment , sourceNames , namespace , decode , true );
190176 }
191177
@@ -195,14 +181,13 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
195181 * defined order).
196182 */
197183 public static MultipleSourcesContainer processNamedData (List <StrippedSourceContainer > strippedSources ,
198- Environment environment , LinkedHashSet <String > sourceNames , String namespace , boolean decode ,
199- boolean includeDefaultProfileData ) {
184+ Environment environment , LinkedHashSet <String > sourceNames , String namespace , boolean decode ,
185+ boolean includeDefaultProfileData ) {
200186
201187 Map <String , StrippedSourceContainer > hashByName = strippedSources .stream ()
202188 .collect (Collectors .toMap (StrippedSourceContainer ::name , Function .identity ()));
203189
204- LinkedHashSet <String > foundSourceNames = new LinkedHashSet <>();
205- Map <String , Object > data = new HashMap <>();
190+ LinkedHashMap <String , Map <String , Object >> data = new LinkedHashMap <>();
206191
207192 // This is an ordered stream, and it means that non-profile-based sources will be
208193 // processed before profile-based sources.
@@ -212,7 +197,6 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
212197 StrippedSourceContainer stripped = hashByName .get (sourceName );
213198 if (stripped != null ) {
214199 LOG .debug ("Found source with name : '" + sourceName + "' in namespace: '" + namespace + "'" );
215- foundSourceNames .add (sourceName );
216200 // see if data is a single yaml/properties file and if it needs decoding
217201 Map <String , String > rawData = stripped .data ();
218202 if (decode ) {
@@ -228,7 +212,7 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
228212 */
229213 if (processSource (includeDefaultProfileData , environment , sourceName , rawData )) {
230214 Map <String , Object > processedData = SourceDataEntriesProcessor .processAllEntries (
231- rawData == null ? Map .of () : rawData , environment , includeDefaultProfileData );
215+ rawData == null ? Map .of () : rawData , environment , includeDefaultProfileData );
232216 data .put (sourceName , processedData );
233217 }
234218 }
@@ -237,11 +221,11 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
237221 }
238222 });
239223
240- return new MultipleSourcesContainer (foundSourceNames , data );
224+ return new MultipleSourcesContainer (data );
241225 }
242226
243227 static boolean processSource (boolean includeDefaultProfileData , Environment environment , String sourceName ,
244- Map <String , String > sourceRawData ) {
228+ Map <String , String > sourceRawData ) {
245229 List <String > activeProfiles = Arrays .stream (environment .getActiveProfiles ()).toList ();
246230
247231 boolean emptyActiveProfiles = activeProfiles .isEmpty ();
@@ -252,7 +236,7 @@ static boolean processSource(boolean includeDefaultProfileData, Environment envi
252236 boolean defaultProfilePresent = activeProfiles .contains ("default" );
253237
254238 return includeDefaultProfileData || emptyActiveProfiles || profileBasedSourceName || defaultProfilePresent
255- || rawDataContainsProfileBasedSource (activeProfiles , sourceRawData ).getAsBoolean ();
239+ || rawDataContainsProfileBasedSource (activeProfiles , sourceRawData ).getAsBoolean ();
256240 }
257241
258242 /*
@@ -264,7 +248,7 @@ static boolean processSource(boolean includeDefaultProfileData, Environment envi
264248 * yaml/yml/properties. For example: 'account-k8s.yaml' or the like.
265249 */
266250 static BooleanSupplier rawDataContainsProfileBasedSource (List <String > activeProfiles ,
267- Map <String , String > sourceRawData ) {
251+ Map <String , String > sourceRawData ) {
268252 return () -> Optional .ofNullable (sourceRawData )
269253 .orElse (Map .of ())
270254 .keySet ()
@@ -273,7 +257,7 @@ static BooleanSupplier rawDataContainsProfileBasedSource(List<String> activeProf
273257 .anyMatch (activeProfile -> ENDS_WITH_PROFILE_AND_EXTENSION .test (keyName , activeProfile )));
274258 }
275259
276- static String sourceDataName (String target , LinkedHashSet <String > sourceNames , String namespace ) {
260+ static String sourceDataName (String target , Set <String > sourceNames , String namespace ) {
277261 String sortedNames = sourceNames .stream ().sorted ().collect (Collectors .joining (PROPERTY_SOURCE_NAME_SEPARATOR ));
278262 return sourceName (target , sortedNames , namespace );
279263 }
@@ -285,8 +269,8 @@ static String sourceDataName(String target, LinkedHashSet<String> sourceNames, S
285269 * these names to find any profile-based sources.
286270 */
287271 public static MultipleSourcesContainer processLabeledData (List <StrippedSourceContainer > containers ,
288- Environment environment , Map <String , String > labels , String namespace , Set <String > profiles ,
289- boolean decode ) {
272+ Environment environment , Map <String , String > labels , String namespace , Set <String > profiles ,
273+ boolean decode ) {
290274
291275 // find sources by provided labels
292276 List <StrippedSourceContainer > byLabels = containers .stream ().filter (one -> {
@@ -318,13 +302,11 @@ public static MultipleSourcesContainer processLabeledData(List<StrippedSourceCon
318302 all .addAll (byLabels );
319303 all .addAll (byProfile );
320304
321- LinkedHashSet <String > sourceNames = new LinkedHashSet <>();
322- Map <String , Object > data = new HashMap <>();
305+ LinkedHashMap <String , Map <String , Object >> data = new LinkedHashMap <>();
323306
324307 all .forEach (source -> {
325308 String foundSourceName = source .name ();
326309 LOG .debug ("Loaded source with name : '" + foundSourceName + " in namespace: '" + namespace + "'" );
327- sourceNames .add (foundSourceName );
328310
329311 Map <String , String > rawData = source .data ();
330312 if (decode ) {
@@ -335,7 +317,7 @@ public static MultipleSourcesContainer processLabeledData(List<StrippedSourceCon
335317 data .put (foundSourceName , dataFromOneSource );
336318 });
337319
338- return new MultipleSourcesContainer (sourceNames , data );
320+ return new MultipleSourcesContainer (data );
339321 }
340322
341323 private static Map <String , String > decodeData (Map <String , String > data ) {
@@ -345,7 +327,7 @@ private static Map<String, String> decodeData(Map<String, String> data) {
345327 }
346328
347329 public static <T > void registerSingle (ConfigurableBootstrapContext bootstrapContext , Class <T > cls , T instance ,
348- String name , ApplicationListener <?> listener ) {
330+ String name , ApplicationListener <?> listener ) {
349331 bootstrapContext .registerIfAbsent (cls , BootstrapRegistry .InstanceSupplier .of (instance ));
350332 bootstrapContext .addCloseListener (event -> {
351333
@@ -359,7 +341,7 @@ public static <T> void registerSingle(ConfigurableBootstrapContext bootstrapCont
359341 }
360342
361343 public static <T > void registerSingle (ConfigurableBootstrapContext bootstrapContext , Class <T > cls , T instance ,
362- String name ) {
344+ String name ) {
363345 registerSingle (bootstrapContext , cls , instance , name , NO_OP );
364346 }
365347
0 commit comments