List classes with no class-level conditions in the auto-config report
This commit adds a new "Unconditional classes" section to the auto-configuration report. It lists any auto-configuration classes that do not have any class-level conditions, i.e. the class will be always be part of the application's configuration. Closes gh-2209
This commit is contained in:
parent
c0c98b0284
commit
37edee4f5e
|
@ -80,6 +80,8 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
|||
excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName")));
|
||||
factories.removeAll(excluded);
|
||||
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
||||
ConditionEvaluationReport.get(this.beanFactory).recordEvaluationCandidates(
|
||||
factories);
|
||||
|
||||
// Sort
|
||||
factories = new AutoConfigurationSorter(this.resourceLoader)
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
@ -58,6 +59,8 @@ public class ConditionEvaluationReport {
|
|||
|
||||
private List<String> exclusions = Collections.emptyList();
|
||||
|
||||
private Set<String> unconditionalClasses = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
* @see #get(ConfigurableListableBeanFactory)
|
||||
|
@ -76,6 +79,7 @@ public class ConditionEvaluationReport {
|
|||
Assert.notNull(source, "Source must not be null");
|
||||
Assert.notNull(condition, "Condition must not be null");
|
||||
Assert.notNull(outcome, "Outcome must not be null");
|
||||
this.unconditionalClasses.remove(source);
|
||||
if (!this.outcomes.containsKey(source)) {
|
||||
this.outcomes.put(source, new ConditionAndOutcomes());
|
||||
}
|
||||
|
@ -92,6 +96,16 @@ public class ConditionEvaluationReport {
|
|||
this.exclusions = new ArrayList<String>(exclusions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the names of the classes that are candidates for condition evaluation
|
||||
* @param evaluationCandidates the names of the classes whose conditions will be
|
||||
* evaluated
|
||||
*/
|
||||
public void recordEvaluationCandidates(List<String> evaluationCandidates) {
|
||||
Assert.notNull(evaluationCandidates, "evaluationCandidates must not be null");
|
||||
this.unconditionalClasses = new HashSet<String>(evaluationCandidates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns condition outcomes from this report, grouped by the source.
|
||||
* @return the condition outcomes
|
||||
|
@ -127,6 +141,14 @@ public class ConditionEvaluationReport {
|
|||
return Collections.unmodifiableList(this.exclusions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the classes that were evaluated but were not conditional.
|
||||
* @return the names of the unconditional classes
|
||||
*/
|
||||
public Set<String> getUnconditionalClasses() {
|
||||
return Collections.unmodifiableSet(this.unconditionalClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent report (from a parent BeanFactory if there is one).
|
||||
* @return the parent report (or null if there isn't one)
|
||||
|
|
|
@ -151,6 +151,17 @@ public class AutoConfigurationReportLoggingInitializer implements
|
|||
}
|
||||
}
|
||||
message.append("\n\n");
|
||||
message.append("Unconditional classes:\n");
|
||||
message.append("----------------------\n");
|
||||
if (report.getUnconditionalClasses().isEmpty()) {
|
||||
message.append("\n None\n");
|
||||
}
|
||||
else {
|
||||
for (String unconditionalClass : report.getUnconditionalClasses()) {
|
||||
message.append("\n " + unconditionalClass + "\n");
|
||||
}
|
||||
}
|
||||
message.append("\n\n");
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue