Search in sources :

Example 1 with WatchPatternParser

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

the class DefaultGrailsPlugin method evaluateOnChangeListener.

private void evaluateOnChangeListener() {
    if (pluginBean.isReadableProperty(ON_SHUTDOWN)) {
        onShutdownListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_SHUTDOWN);
    }
    if (pluginBean.isReadableProperty(ON_CONFIG_CHANGE)) {
        onConfigChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CONFIG_CHANGE);
    }
    if (pluginBean.isReadableProperty(ON_CHANGE)) {
        onChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CHANGE);
    }
    Environment env = Environment.getCurrent();
    final boolean warDeployed = env.isWarDeployed();
    final boolean reloadEnabled = env.isReloadEnabled();
    if (!((reloadEnabled || !warDeployed))) {
        return;
    }
    Object referencedResources = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, WATCHED_RESOURCES);
    try {
        List resourceList = null;
        if (referencedResources instanceof String) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Configuring plugin " + this + " to watch resources with pattern: " + referencedResources);
            }
            resourceList = Collections.singletonList(referencedResources.toString());
        } else if (referencedResources instanceof List) {
            resourceList = (List) referencedResources;
        }
        if (resourceList == null) {
            return;
        }
        List<String> resourceListTmp = new ArrayList<String>();
        final String baseLocation = env.getReloadLocation();
        for (Object ref : resourceList) {
            String stringRef = ref.toString();
            if (warDeployed) {
                addBaseLocationPattern(resourceListTmp, baseLocation, stringRef);
            } else {
                addBaseLocationPattern(resourceListTmp, baseLocation, stringRef);
            }
        }
        watchedResourcePatternReferences = new String[resourceListTmp.size()];
        for (int i = 0; i < watchedResourcePatternReferences.length; i++) {
            String resRef = resourceListTmp.get(i);
            watchedResourcePatternReferences[i] = resRef;
        }
        watchedResourcePatterns = new WatchPatternParser().getWatchPatterns(Arrays.asList(watchedResourcePatternReferences));
    } catch (IllegalArgumentException e) {
        if (GrailsUtil.isDevelopmentEnv()) {
            LOG.debug("Cannot load plug-in resource watch list from [" + GrailsArrayUtils.toString(watchedResourcePatternReferences) + "]. This means that the plugin " + this + ", will not be able to auto-reload changes effectively. Try running grails upgrade.: " + e.getMessage());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Environment(grails.util.Environment) List(java.util.List) ArrayList(java.util.ArrayList) WatchPatternParser(org.grails.plugins.support.WatchPatternParser)

Aggregations

Environment (grails.util.Environment)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WatchPatternParser (org.grails.plugins.support.WatchPatternParser)1