|
17 | 17 | package org.springframework.boot.context.config; |
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
20 | | -import java.util.Arrays; |
21 | 20 | import java.util.Collection; |
22 | 21 | import java.util.Collections; |
23 | 22 | import java.util.LinkedHashSet; |
@@ -201,22 +200,23 @@ ConfigDataEnvironmentContributors getContributors() { |
201 | 200 |
|
202 | 201 | private List<ConfigDataEnvironmentContributor> getInitialImportContributors(Binder binder) { |
203 | 202 | List<ConfigDataEnvironmentContributor> initialContributors = new ArrayList<>(); |
204 | | - addInitialImportContributors(initialContributors, bindLocations(binder, IMPORT_PROPERTY, EMPTY_LOCATIONS)); |
205 | | - addInitialImportContributors(initialContributors, |
206 | | - bindLocations(binder, ADDITIONAL_LOCATION_PROPERTY, EMPTY_LOCATIONS)); |
207 | | - addInitialImportContributors(initialContributors, |
208 | | - bindLocations(binder, LOCATION_PROPERTY, DEFAULT_SEARCH_LOCATIONS)); |
| 203 | + addInitialImportContributors(initialContributors, binder, IMPORT_PROPERTY, EMPTY_LOCATIONS, false); |
| 204 | + addInitialImportContributors(initialContributors, binder, ADDITIONAL_LOCATION_PROPERTY, EMPTY_LOCATIONS, true); |
| 205 | + addInitialImportContributors(initialContributors, binder, LOCATION_PROPERTY, DEFAULT_SEARCH_LOCATIONS, true); |
209 | 206 | return initialContributors; |
210 | 207 | } |
211 | 208 |
|
212 | | - private ConfigDataLocation[] bindLocations(Binder binder, String propertyName, ConfigDataLocation[] other) { |
213 | | - return binder.bind(propertyName, CONFIG_DATA_LOCATION_ARRAY).orElse(other); |
214 | | - } |
215 | | - |
216 | | - private void addInitialImportContributors(List<ConfigDataEnvironmentContributor> initialContributors, |
217 | | - ConfigDataLocation[] locations) { |
218 | | - addInitialImportContributors(initialContributors, |
219 | | - Arrays.stream(locations).filter(ConfigDataLocation::isNotEmpty).toList()); |
| 209 | + private void addInitialImportContributors(List<ConfigDataEnvironmentContributor> initialContributors, Binder binder, |
| 210 | + String propertyName, ConfigDataLocation[] defaultValue, boolean registerIndividually) { |
| 211 | + ConfigDataLocation[] locations = binder.bind(propertyName, CONFIG_DATA_LOCATION_ARRAY).orElse(defaultValue); |
| 212 | + if (registerIndividually) { |
| 213 | + for (int i = locations.length - 1; i >= 0; i--) { |
| 214 | + addInitialImportContributors(initialContributors, List.of(locations[i])); |
| 215 | + } |
| 216 | + } |
| 217 | + else { |
| 218 | + addInitialImportContributors(initialContributors, List.of(locations)); |
| 219 | + } |
220 | 220 | } |
221 | 221 |
|
222 | 222 | private void addInitialImportContributors(List<ConfigDataEnvironmentContributor> initialContributors, |
|
0 commit comments