Search in sources :

Example 1 with Enhanced

use of grails.artefact.Enhanced in project grails-core by grails.

the class GrailsClassUtils method hasBeenEnhancedForFeature.

/**
 * Checks to see if a class is marked with @grails.artefact.Enhanced and if the enhancedFor
 * attribute of the annotation contains a specific feature name
 *
 * @param controllerClass The class to inspect
 * @param featureName The name of a feature to check for
 * @return true if controllerClass is marked with Enhanced and the enhancedFor attribute includes featureName, otherwise returns false
 * @see Enhanced
 * @see Enhanced#enhancedFor()
 */
public static Boolean hasBeenEnhancedForFeature(final Class<?> controllerClass, final String featureName) {
    boolean hasBeenEnhanced = false;
    final Enhanced enhancedAnnotation = controllerClass.getAnnotation(Enhanced.class);
    if (enhancedAnnotation != null) {
        final String[] enhancedFor = enhancedAnnotation.enhancedFor();
        if (enhancedFor != null) {
            hasBeenEnhanced = GrailsArrayUtils.contains(enhancedFor, featureName);
        }
    }
    return hasBeenEnhanced;
}
Also used : Enhanced(grails.artefact.Enhanced)

Example 2 with Enhanced

use of grails.artefact.Enhanced 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

Enhanced (grails.artefact.Enhanced)2 GrailsPlugin (grails.plugins.GrailsPlugin)1 PluginException (grails.plugins.exceptions.PluginException)1 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)1 MetaClassRegistry (groovy.lang.MetaClassRegistry)1 ConfigObject (groovy.util.ConfigObject)1 ConfigSlurper (groovy.util.ConfigSlurper)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (org.grails.config.NavigableMap)1 BeansException (org.springframework.beans.BeansException)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1