Search in sources :

Example 6 with ConfigObject

use of groovy.util.ConfigObject in project grails-core by grails.

the class AbstractGrailsPluginManager method informOfClassChange.

public void informOfClassChange(File file, @SuppressWarnings("rawtypes") Class cls) {
    if (file.getName().equals(CONFIG_FILE)) {
        ConfigSlurper configSlurper = getConfigSlurper(application);
        ConfigObject c;
        try {
            c = configSlurper.parse(file.toURI().toURL());
            application.getConfig().merge(c);
            final Map flat = c.flatten();
            application.getConfig().merge(flat);
            application.configChanged();
            informPluginsOfConfigChange();
        } catch (Exception e) {
            // ignore
            LOG.debug("Error in changing Config", e);
        }
    } else {
        if (cls != null) {
            MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
            registry.removeMetaClass(cls);
            ExpandoMetaClass newMc = new ExpandoMetaClass(cls, true, true);
            newMc.initialize();
            registry.setMetaClass(cls, newMc);
            Enhanced en = AnnotationUtils.findAnnotation(cls, Enhanced.class);
            if (en != null) {
                Class<?>[] mixinClasses = en.mixins();
                if (mixinClasses != null) {
                    DefaultGroovyMethods.mixin(newMc, mixinClasses);
                }
            }
        }
        for (GrailsPlugin grailsPlugin : pluginList) {
            if (grailsPlugin.hasInterestInChange(file.getAbsolutePath())) {
                try {
                    if (cls == null) {
                        grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, new FileSystemResource(file));
                    } else {
                        grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, cls);
                    }
                    Environment.setCurrentReloadError(null);
                } catch (Exception e) {
                    LOG.error("Plugin " + grailsPlugin + " could not reload changes to file [" + file + "]: " + e.getMessage(), e);
                    Environment.setCurrentReloadError(e);
                }
            }
        }
    }
}
Also used : MetaClassRegistry(groovy.lang.MetaClassRegistry) GrailsPlugin(grails.plugins.GrailsPlugin) Enhanced(grails.artefact.Enhanced) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) FileSystemResource(org.springframework.core.io.FileSystemResource) ConfigObject(groovy.util.ConfigObject) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(org.grails.config.NavigableMap) BeansException(org.springframework.beans.BeansException) PluginException(grails.plugins.exceptions.PluginException) ConfigSlurper(groovy.util.ConfigSlurper)

Aggregations

ConfigObject (groovy.util.ConfigObject)6 ConfigSlurper (groovy.util.ConfigSlurper)4 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)2 MockApplicationContext (org.grails.support.MockApplicationContext)2 Decorator (com.opensymphony.module.sitemesh.Decorator)1 Page (com.opensymphony.module.sitemesh.Page)1 HTMLPageParser (com.opensymphony.module.sitemesh.parser.HTMLPageParser)1 Enhanced (grails.artefact.Enhanced)1 Config (grails.config.Config)1 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 PluginException (grails.plugins.exceptions.PluginException)1 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 GroovyObject (groovy.lang.GroovyObject)1 MetaClassRegistry (groovy.lang.MetaClassRegistry)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1