Search in sources :

Example 1 with WatchPattern

use of org.grails.plugins.support.WatchPattern in project grails-core by grails.

the class AbstractGrailsPluginManager method informOfClassChange.

public void informOfClassChange(Class<?> aClass) {
    if (aClass == null || application == null) {
        return;
    }
    ArtefactHandler handler = application.getArtefactType(aClass);
    if (handler == null) {
        return;
    }
    String pluginName = handler.getPluginName();
    if (pluginName == null) {
        return;
    }
    GrailsPlugin plugin = getGrailsPlugin(pluginName);
    if (plugin != null) {
        if (!plugin.isEnabled(applicationContext.getEnvironment().getActiveProfiles()))
            return;
        plugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, aClass);
    } else {
        String classNameAsPath = aClass.getName().replace('.', File.separatorChar);
        String groovyClass = classNameAsPath + ".groovy";
        String javaClass = classNameAsPath + ".java";
        for (GrailsPlugin grailsPlugin : pluginList) {
            List<WatchPattern> watchPatterns = grailsPlugin.getWatchedResourcePatterns();
            if (watchPatterns != null) {
                for (WatchPattern watchPattern : watchPatterns) {
                    File parent = watchPattern.getDirectory();
                    String extension = watchPattern.getExtension();
                    if (parent != null && extension != null) {
                        File f = new File(parent, groovyClass);
                        if (f.exists() && f.getName().endsWith(extension)) {
                            grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, aClass);
                        } else {
                            f = new File(parent, javaClass);
                            if (f.exists() && f.getName().endsWith(extension)) {
                                grailsPlugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, aClass);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : WatchPattern(org.grails.plugins.support.WatchPattern) GrailsPlugin(grails.plugins.GrailsPlugin) ArtefactHandler(grails.core.ArtefactHandler) File(java.io.File)

Aggregations

ArtefactHandler (grails.core.ArtefactHandler)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 File (java.io.File)1 WatchPattern (org.grails.plugins.support.WatchPattern)1