Commit 20bede21 authored by Dave Syer's avatar Dave Syer

Add support for parent hierarchy in AUtoConfigurationReport

parent 47d079d9
...@@ -39,6 +39,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; ...@@ -39,6 +39,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
* *
* @author Greg Turnquist * @author Greg Turnquist
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer
*/ */
@ConfigurationProperties(name = "endpoints.autoconfig", ignoreUnknownFields = false) @ConfigurationProperties(name = "endpoints.autoconfig", ignoreUnknownFields = false)
public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
...@@ -65,6 +66,8 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -65,6 +66,8 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
private MultiValueMap<String, MessageAndCondition> negativeMatches; private MultiValueMap<String, MessageAndCondition> negativeMatches;
private Report parent;
public Report(AutoConfigurationReport report) { public Report(AutoConfigurationReport report) {
this.positiveMatches = new LinkedMultiValueMap<String, MessageAndCondition>(); this.positiveMatches = new LinkedMultiValueMap<String, MessageAndCondition>();
this.negativeMatches = new LinkedMultiValueMap<String, MessageAndCondition>(); this.negativeMatches = new LinkedMultiValueMap<String, MessageAndCondition>();
...@@ -74,7 +77,9 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -74,7 +77,9 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
: this.negativeMatches, entry.getKey(), entry.getValue()); : this.negativeMatches, entry.getKey(), entry.getValue());
} }
if (report.getParent() != null) {
this.parent = new Report(report.getParent());
}
} }
private void dunno(MultiValueMap<String, MessageAndCondition> map, String source, private void dunno(MultiValueMap<String, MessageAndCondition> map, String source,
...@@ -93,6 +98,10 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -93,6 +98,10 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
return this.negativeMatches; return this.negativeMatches;
} }
public Report getParent() {
return this.parent;
}
} }
/** /**
......
...@@ -24,6 +24,7 @@ import java.util.Map; ...@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
...@@ -42,6 +43,8 @@ public class AutoConfigurationReport { ...@@ -42,6 +43,8 @@ public class AutoConfigurationReport {
private final SortedMap<String, ConditionAndOutcomes> outcomes = new TreeMap<String, ConditionAndOutcomes>(); private final SortedMap<String, ConditionAndOutcomes> outcomes = new TreeMap<String, ConditionAndOutcomes>();
private AutoConfigurationReport parent;
/** /**
* Private constructor. * Private constructor.
* @see #get(ConfigurableListableBeanFactory) * @see #get(ConfigurableListableBeanFactory)
...@@ -70,6 +73,15 @@ public class AutoConfigurationReport { ...@@ -70,6 +73,15 @@ public class AutoConfigurationReport {
return Collections.unmodifiableMap(this.outcomes); return Collections.unmodifiableMap(this.outcomes);
} }
/**
* The parent report (from a parent BeanFactory if there is one).
*
* @return the parent report (or null if there isn't one)
*/
public AutoConfigurationReport getParent() {
return this.parent;
}
/** /**
* Obtain a {@link AutoConfigurationReport} for the specified bean factory. * Obtain a {@link AutoConfigurationReport} for the specified bean factory.
* @param beanFactory the bean factory * @param beanFactory the bean factory
...@@ -77,14 +89,24 @@ public class AutoConfigurationReport { ...@@ -77,14 +89,24 @@ public class AutoConfigurationReport {
*/ */
public static AutoConfigurationReport get(ConfigurableListableBeanFactory beanFactory) { public static AutoConfigurationReport get(ConfigurableListableBeanFactory beanFactory) {
synchronized (beanFactory) { synchronized (beanFactory) {
AutoConfigurationReport report;
try { try {
return beanFactory.getBean(BEAN_NAME, AutoConfigurationReport.class); report = beanFactory.getBean(BEAN_NAME, AutoConfigurationReport.class);
} }
catch (NoSuchBeanDefinitionException ex) { catch (NoSuchBeanDefinitionException ex) {
AutoConfigurationReport report = new AutoConfigurationReport(); report = new AutoConfigurationReport();
beanFactory.registerSingleton(BEAN_NAME, report); beanFactory.registerSingleton(BEAN_NAME, report);
return report;
} }
locateParent(beanFactory.getParentBeanFactory(), report);
return report;
}
}
private static void locateParent(BeanFactory beanFactory,
AutoConfigurationReport report) {
if (beanFactory != null && report.parent == null
&& beanFactory.containsBean(BEAN_NAME)) {
report.parent = beanFactory.getBean(BEAN_NAME, AutoConfigurationReport.class);
} }
} }
......
...@@ -24,6 +24,7 @@ import org.junit.Test; ...@@ -24,6 +24,7 @@ import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcome; import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcome;
import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcomes; import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcomes;
...@@ -84,6 +85,17 @@ public class AutoConfigurationReportTests { ...@@ -84,6 +85,17 @@ public class AutoConfigurationReportTests {
sameInstance(AutoConfigurationReport.get(this.beanFactory))); sameInstance(AutoConfigurationReport.get(this.beanFactory)));
} }
@Test
public void parent() throws Exception {
this.beanFactory.setParentBeanFactory(new DefaultListableBeanFactory());
AutoConfigurationReport.get((ConfigurableListableBeanFactory) this.beanFactory
.getParentBeanFactory());
assertThat(this.report,
sameInstance(AutoConfigurationReport.get(this.beanFactory)));
assertThat(this.report, not(nullValue()));
assertThat(this.report.getParent(), not(nullValue()));
}
@Test @Test
public void recordConditionEvaluations() throws Exception { public void recordConditionEvaluations() throws Exception {
this.report.recordConditionEvaluation("a", this.condition1, this.outcome1); this.report.recordConditionEvaluation("a", this.condition1, this.outcome1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment