Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet {
String root;
Map<String, ModuleDefinition> modules;
Map<String, ApplicationContext> contexts = new HashMap<String, ApplicationContext>();

Map<String, Set<Resource>> inheritedConfigResourcesMap = new HashMap<String, Set<Resource>>();

ApplicationContext rootContext = null;
Set<String> excludes = new HashSet<String>();
Properties configProperties = null;
Expand Down Expand Up @@ -310,24 +314,36 @@ public Map<String, ApplicationContext> getContextMap() {

@Override
public Resource[] getConfigResources(String name) {
Set<Resource> resources = new LinkedHashSet<Resource>();

ModuleDefinition original = null;
ModuleDefinition def = original = modules.get(name);

if (def == null)
ModuleDefinition def = modules.get(name);
if (def == null) {
return new Resource[] {};
}

Set<Resource> resources = new LinkedHashSet<>();

resources.addAll(def.getContextLocations());

while (def != null) {
resources.addAll(def.getInheritableContextLocations());
def = modules.get(def.getParentName());
resources.addAll(collectInheritedResources(def));

resources.addAll(def.getOverrideContextLocations());

return resources.toArray(Resource[]::new);
}

private Set<Resource> collectInheritedResources(final ModuleDefinition def) {
if (def == null) {
return Collections.emptySet();
}

resources.addAll(original.getOverrideContextLocations());
final Set<Resource> cachedResources = inheritedConfigResourcesMap.get(def.getName());
if (cachedResources != null) {
return cachedResources;
}

Comment thread
he1l0world marked this conversation as resolved.
return resources.toArray(new Resource[resources.size()]);
final Set<Resource> inheritableResources = new LinkedHashSet<>(def.getInheritableContextLocations());
inheritableResources.addAll(collectInheritedResources(modules.get(def.getParentName())));
inheritedConfigResourcesMap.put(def.getName(), inheritableResources);
return inheritableResources;
}

@Override
Expand Down
Loading