|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
|
* Copyright 2012-2015 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -161,27 +161,63 @@ abstract class AbstractNestedCondition extends SpringBootCondition
|
|
|
|
|
for (Map.Entry<AnnotationMetadata, List<Condition>> entry : this.memberConditions
|
|
|
|
|
.entrySet()) {
|
|
|
|
|
AnnotationMetadata metadata = entry.getKey();
|
|
|
|
|
for (Condition condition : entry.getValue()) {
|
|
|
|
|
outcomes.add(getConditionOutcome(metadata, condition));
|
|
|
|
|
}
|
|
|
|
|
List<Condition> conditions = entry.getValue();
|
|
|
|
|
outcomes.add(new MemberOutcomes(this.context, metadata, conditions)
|
|
|
|
|
.getUltimateOutcome());
|
|
|
|
|
}
|
|
|
|
|
return Collections.unmodifiableList(outcomes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class MemberOutcomes {
|
|
|
|
|
|
|
|
|
|
private final ConditionContext context;
|
|
|
|
|
|
|
|
|
|
private final AnnotationMetadata metadata;
|
|
|
|
|
|
|
|
|
|
private final List<ConditionOutcome> outcomes;
|
|
|
|
|
|
|
|
|
|
MemberOutcomes(ConditionContext context, AnnotationMetadata metadata,
|
|
|
|
|
List<Condition> conditions) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.metadata = metadata;
|
|
|
|
|
this.outcomes = new ArrayList<ConditionOutcome>(conditions.size());
|
|
|
|
|
for (Condition condition : conditions) {
|
|
|
|
|
this.outcomes.add(getConditionOutcome(metadata, condition));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ConditionOutcome getConditionOutcome(AnnotationMetadata metadata,
|
|
|
|
|
Condition condition) {
|
|
|
|
|
String className = ClassUtils.getShortName(metadata.getClassName());
|
|
|
|
|
if (condition instanceof SpringBootCondition) {
|
|
|
|
|
ConditionOutcome outcome = ((SpringBootCondition) condition)
|
|
|
|
|
.getMatchOutcome(this.context, metadata);
|
|
|
|
|
ConditionMessage message = outcome.getConditionMessage()
|
|
|
|
|
.append("on member " + className);
|
|
|
|
|
return new ConditionOutcome(outcome.isMatch(), message);
|
|
|
|
|
return ((SpringBootCondition) condition).getMatchOutcome(this.context,
|
|
|
|
|
metadata);
|
|
|
|
|
}
|
|
|
|
|
return new ConditionOutcome(condition.matches(this.context, metadata),
|
|
|
|
|
(ConditionMessage) null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConditionOutcome getUltimateOutcome() {
|
|
|
|
|
ConditionMessage.Builder message = ConditionMessage
|
|
|
|
|
.forCondition("NestedCondition on "
|
|
|
|
|
+ ClassUtils.getShortName(this.metadata.getClassName()));
|
|
|
|
|
if (this.outcomes.size() == 1) {
|
|
|
|
|
ConditionOutcome outcome = this.outcomes.get(0);
|
|
|
|
|
return new ConditionOutcome(outcome.isMatch(),
|
|
|
|
|
message.because(outcome.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
List<ConditionOutcome> match = new ArrayList<ConditionOutcome>();
|
|
|
|
|
List<ConditionOutcome> nonMatch = new ArrayList<ConditionOutcome>();
|
|
|
|
|
for (ConditionOutcome outcome : this.outcomes) {
|
|
|
|
|
(outcome.isMatch() ? match : nonMatch).add(outcome);
|
|
|
|
|
}
|
|
|
|
|
if (nonMatch.isEmpty()) {
|
|
|
|
|
return ConditionOutcome
|
|
|
|
|
.match(message.found("matching nested conditions").items(match));
|
|
|
|
|
}
|
|
|
|
|
boolean matches = condition.matches(this.context, metadata);
|
|
|
|
|
return new ConditionOutcome(matches,
|
|
|
|
|
ConditionMessage.forCondition("NestedCondition")
|
|
|
|
|
.because("nested on member " + className));
|
|
|
|
|
return ConditionOutcome.noMatch(
|
|
|
|
|
message.found("non-matching nested conditions").items(nonMatch));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|