/*
 * Copyright 2015 devbury LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package devbury.dewey.core;

import devbury.dewey.core.event.MessageEventListener;
import devbury.dewey.core.server.DeweySettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;
import java.util.List;

@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableCaching
@EnableScheduling
@ComponentScan
public class CoreConfiguration {

    private static final Logger logger = LoggerFactory.getLogger(CoreConfiguration.class);

    @Autowired(required = false)
    private List<MessageEventListener> messageEventListeners;

    @Autowired
    private DeweySettings deweySettings;

    @Bean
    @ConditionalOnMissingBean(CacheManager.class)
    public GuavaCacheManager guavaCacheManager() {
        return new GuavaCacheManager();
    }

    @PostConstruct
    public void init() {
        logger.info("Dewey server: {}", deweySettings.getServer());
        logger.info("Installed plugins:");
        if (messageEventListeners != null) {
            messageEventListeners.forEach(m -> logger.info("  Installed plugin {}", m.getClass().getSimpleName()));
        } else {
            logger.info("  NONE!");
        }
    }
}
@@ -644,34 +644,28 @@
 ore.
-event.MessageEventListener
+server.DeweySettings
 ;%0Aim
@@ -691,37 +691,30 @@
 core.server.
-DeweySettings
+Plugin
 ;%0Aimport org
@@ -1061,32 +1061,87 @@
 vaCacheManager;%0A
+import org.springframework.context.ApplicationContext;%0A
 import org.sprin
@@ -1431,20 +1431,29 @@
 va.util.
-Li
 st
+ream.Stream
 ;%0A%0A@Enab
@@ -1688,87 +1688,58 @@
 ired
-(required = false)%0A    private List%3CMessageEventListener%3E messageEventListeners
+%0A    private ApplicationContext applicationContext
 ;%0A%0A 
@@ -2119,160 +2119,77 @@
     
-if (messageEventListeners != null) %7B%0A            messageEventListeners.forEach(m -%3E logger.info(%22  Installed plugin %7B%7D%22, m.getClass().getSimpleName()
+Stream.of(applicationContext.getBeanNamesForAnnotation(Plugin.class
 ))
-;
 %0A   
@@ -2197,62 +2197,80 @@
     
-%7D else %7B%0A            logger.info(%22  NONE!%22);%0A        %7D
+        .sorted()%0A                .forEach(m -%3E logger.info(%22  %7B%7D%22, m));
 %0A   

Update logging to include all beans that have the Plugin annotation.