Skip to content
Closed
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 @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,14 +65,37 @@ public ConditionsReportEndpoint(ConfigurableApplicationContext context) {
@ReadOperation
public ConditionsDescriptor conditions() {
Map<String, ContextConditionsDescriptor> contextConditionEvaluations = new HashMap<>();
ConfigurableApplicationContext target = this.context;
while (target != null) {
contextConditionEvaluations.put(target.getId(), new ContextConditionsDescriptor(target));
target = getConfigurableParent(target);
List<ConfigurableApplicationContext> allContexts = collectAllContexts(this.context);
for (ConfigurableApplicationContext ctx : allContexts) {
String ctxId = ctx.getId();
if (ctxId != null) {
contextConditionEvaluations.put(ctxId, new ContextConditionsDescriptor(ctx));
}
}
return new ConditionsDescriptor(contextConditionEvaluations);
}

List<ConfigurableApplicationContext> collectAllContexts(ConfigurableApplicationContext rootContext) {
List<ConfigurableApplicationContext> contexts = new ArrayList<>();
Set<String> seenIds = new HashSet<>();
ConfigurableApplicationContext current = rootContext;

while (current != null && current.getId() != null && seenIds.add(current.getId())) {
contexts.add(current);
current = getConfigurableParent(current);
}

Map<String, ConfigurableApplicationContext> found = rootContext
.getBeansOfType(ConfigurableApplicationContext.class, false, false);
for (ConfigurableApplicationContext ctx : found.values()) {
String ctxId = ctx.getId();
if (ctxId != null && seenIds.add(ctxId)) {
contexts.add(ctx);
}
}
return contexts;
}

private @Nullable ConfigurableApplicationContext getConfigurableParent(ConfigurableApplicationContext context) {
ApplicationContext parent = context.getParent();
if (parent instanceof ConfigurableApplicationContext configurableParent) {
Expand Down