|
22 | 22 | import java.io.InputStream; |
23 | 23 | import java.net.URL; |
24 | 24 | import java.util.ArrayList; |
| 25 | +import java.util.Collections; |
25 | 26 | import java.util.EmptyStackException; |
26 | 27 | import java.util.HashMap; |
27 | 28 | import java.util.HashSet; |
@@ -61,6 +62,9 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { |
61 | 62 | String root; |
62 | 63 | Map<String, ModuleDefinition> modules; |
63 | 64 | Map<String, ApplicationContext> contexts = new HashMap<String, ApplicationContext>(); |
| 65 | + |
| 66 | + Map<String, Set<Resource>> inheritedConfigResourcesMap = new HashMap<String, Set<Resource>>(); |
| 67 | + |
64 | 68 | ApplicationContext rootContext = null; |
65 | 69 | Set<String> excludes = new HashSet<String>(); |
66 | 70 | Properties configProperties = null; |
@@ -310,24 +314,36 @@ public Map<String, ApplicationContext> getContextMap() { |
310 | 314 |
|
311 | 315 | @Override |
312 | 316 | public Resource[] getConfigResources(String name) { |
313 | | - Set<Resource> resources = new LinkedHashSet<Resource>(); |
314 | | - |
315 | | - ModuleDefinition original = null; |
316 | | - ModuleDefinition def = original = modules.get(name); |
317 | | - |
318 | | - if (def == null) |
| 317 | + ModuleDefinition def = modules.get(name); |
| 318 | + if (def == null) { |
319 | 319 | return new Resource[] {}; |
| 320 | + } |
| 321 | + |
| 322 | + Set<Resource> resources = new LinkedHashSet<>(); |
320 | 323 |
|
321 | 324 | resources.addAll(def.getContextLocations()); |
322 | 325 |
|
323 | | - while (def != null) { |
324 | | - resources.addAll(def.getInheritableContextLocations()); |
325 | | - def = modules.get(def.getParentName()); |
| 326 | + resources.addAll(collectInheritedResources(def)); |
| 327 | + |
| 328 | + resources.addAll(def.getOverrideContextLocations()); |
| 329 | + |
| 330 | + return resources.toArray(Resource[]::new); |
| 331 | + } |
| 332 | + |
| 333 | + private Set<Resource> collectInheritedResources(final ModuleDefinition def) { |
| 334 | + if (def == null) { |
| 335 | + return Collections.emptySet(); |
326 | 336 | } |
327 | 337 |
|
328 | | - resources.addAll(original.getOverrideContextLocations()); |
| 338 | + final Set<Resource> cachedResources = inheritedConfigResourcesMap.get(def.getName()); |
| 339 | + if (cachedResources != null) { |
| 340 | + return cachedResources; |
| 341 | + } |
329 | 342 |
|
330 | | - return resources.toArray(new Resource[resources.size()]); |
| 343 | + final Set<Resource> inheritableResources = new LinkedHashSet<>(def.getInheritableContextLocations()); |
| 344 | + inheritableResources.addAll(collectInheritedResources(modules.get(def.getParentName()))); |
| 345 | + inheritedConfigResourcesMap.put(def.getName(), inheritableResources); |
| 346 | + return inheritableResources; |
331 | 347 | } |
332 | 348 |
|
333 | 349 | @Override |
|
0 commit comments