List excluded auto-config classes in the auto-config report and endpoint

Prior to this commit, the auto-configuration report (both in its logged
form and the actuator endpoint) listed the positive and negative matches
but did not list the classes, if any, that the user had excluded.

This commit updates the logged report and the actuator endpoint to
expose a list of the excluded class names configured via the exclude
attribute on @EnableAutoConfiguration.

Closes gh-2085
This commit is contained in:
Andy Wilkinson
2015-03-30 15:05:42 +01:00
parent 075b5c1b18
commit 8850286937
7 changed files with 177 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 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.
@@ -42,6 +42,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
* @author Greg Turnquist
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
*/
@ConfigurationProperties(prefix = "endpoints.autoconfig", ignoreUnknownFields = false)
public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
@@ -61,7 +62,7 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
/**
* Adapts {@link ConditionEvaluationReport} to a JSON friendly structure.
*/
@JsonPropertyOrder({ "positiveMatches", "negativeMatches" })
@JsonPropertyOrder({ "positiveMatches", "negativeMatches", "exclusions" })
@JsonInclude(Include.NON_EMPTY)
public static class Report {
@@ -69,11 +70,14 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
private MultiValueMap<String, MessageAndCondition> negativeMatches;
private List<String> exclusions;
private Report parent;
public Report(ConditionEvaluationReport report) {
this.positiveMatches = new LinkedMultiValueMap<String, MessageAndCondition>();
this.negativeMatches = new LinkedMultiValueMap<String, MessageAndCondition>();
this.exclusions = report.getExclusions();
for (Map.Entry<String, ConditionAndOutcomes> entry : report
.getConditionAndOutcomesBySource().entrySet()) {
add(entry.getValue().isFullMatch() ? this.positiveMatches
@@ -101,6 +105,10 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
return this.negativeMatches;
}
public List<String> getExclusions() {
return this.exclusions;
}
public Report getParent() {
return this.parent;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 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.
@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.endpoint;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import org.junit.Test;
@@ -37,6 +39,7 @@ import static org.mockito.Mockito.mock;
*
* @author Greg Turnquist
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class AutoConfigurationReportEndpointTests extends
AbstractEndpointTests<AutoConfigurationReportEndpoint> {
@@ -51,6 +54,7 @@ public class AutoConfigurationReportEndpointTests extends
Report report = getEndpointBean().invoke();
assertTrue(report.getPositiveMatches().isEmpty());
assertTrue(report.getNegativeMatches().containsKey("a"));
assertTrue(report.getExclusions().contains("com.foo.Bar"));
}
@Configuration
@@ -66,6 +70,7 @@ public class AutoConfigurationReportEndpointTests extends
.getBeanFactory());
report.recordConditionEvaluation("a", mock(Condition.class),
mock(ConditionOutcome.class));
report.recordExclusions(Arrays.asList("com.foo.Bar"));
}
@Bean