Skip to content

Improve Inherited Context Lookup in getConfigResources #11048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>> configResourcesMap = new HashMap<String, Set<Resource>>();

ApplicationContext rootContext = null;
Set<String> excludes = new HashSet<String>();
Properties configProperties = null;
Expand Down Expand Up @@ -314,24 +318,35 @@ 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());
if (configResourcesMap.containsKey(def.getName())) {
return configResourcesMap.get(def.getName());
}

return resources.toArray(new Resource[resources.size()]);
final Set<Resource> inheritableResources = new LinkedHashSet<>(def.getInheritableContextLocations());
inheritableResources.addAll(collectInheritedResources(modules.get(def.getParentName())));
configResourcesMap.put(def.getName(), inheritableResources);
return inheritableResources;
}

@Override
Expand Down
Loading