@PostConstruct
 public void setupAutoConfigurationReport() {
   ConditionEvaluationReport report =
       ConditionEvaluationReport.get(this.context.getBeanFactory());
   report.recordConditionEvaluation("a", mock(Condition.class), mock(ConditionOutcome.class));
   report.recordExclusions(Arrays.asList("com.foo.Bar"));
 }
  @Override
  public String[] selectImports(AnnotationMetadata metadata) {
    try {
      AnnotationAttributes attributes =
          AnnotationAttributes.fromMap(
              metadata.getAnnotationAttributes(EnableAutoConfiguration.class.getName(), true));

      Assert.notNull(
          attributes,
          "No auto-configuration attributes found. Is "
              + metadata.getClassName()
              + " annotated with @EnableAutoConfiguration?");

      // Find all possible auto configuration classes, filtering duplicates
      List<String> factories =
          new ArrayList<String>(
              new LinkedHashSet<String>(
                  SpringFactoriesLoader.loadFactoryNames(
                      EnableAutoConfiguration.class, this.beanClassLoader)));

      // Remove those specifically excluded
      Set<String> excluded = new LinkedHashSet<String>();
      excluded.addAll(Arrays.asList(attributes.getStringArray("exclude")));
      excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName")));
      factories.removeAll(excluded);
      ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);

      // Sort
      factories = new AutoConfigurationSorter(this.resourceLoader).getInPriorityOrder(factories);

      return factories.toArray(new String[factories.size()]);
    } catch (IOException ex) {
      throw new IllegalStateException(ex);
    }
  }
 @Test
 public void exclusionsAreApplied() {
   configureExclusions(FreeMarkerAutoConfiguration.class.getName());
   String[] imports = this.importSelector.selectImports(this.annotationMetadata);
   assertThat(imports.length, is(equalTo(getAutoConfigurationClassNames().size() - 1)));
   assertThat(
       ConditionEvaluationReport.get(this.beanFactory).getExclusions(),
       contains(FreeMarkerAutoConfiguration.class.getName()));
 }
 @Test
 public void importsAreSelected() {
   configureExclusions();
   String[] imports = this.importSelector.selectImports(this.annotationMetadata);
   assertThat(
       imports.length,
       is(
           equalTo(
               SpringFactoriesLoader.loadFactoryNames(
                       EnableAutoConfiguration.class, getClass().getClassLoader())
                   .size())));
   assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(), hasSize(0));
 }
 private static void locateParent(BeanFactory beanFactory, ConditionEvaluationReport report) {
   if (beanFactory != null && report.parent == null && beanFactory.containsBean(BEAN_NAME)) {
     report.parent = beanFactory.getBean(BEAN_NAME, ConditionEvaluationReport.class);
   }
 }