private void addBaseLocationPattern(
     List<String> resourceList, final String baseLocation, String pattern) {
   if (baseLocation != null) {
     final String reloadLocationResourcePattern =
         getResourcePatternForBaseLocation(baseLocation, pattern);
     resourceList.add(reloadLocationResourcePattern);
   } else {
     resourceList.add(pattern);
   }
 }
 @SuppressWarnings("unchecked")
 private void evaluatePluginInfluencePolicy() {
   if (pluginBean.isReadableProperty(INFLUENCES)) {
     List influencedList = (List) pluginBean.getPropertyValue(INFLUENCES);
     if (influencedList != null) {
       influencedPluginNames =
           (String[]) influencedList.toArray(new String[influencedList.size()]);
     }
   }
 }
 private void evaluatePluginEvictionPolicy() {
   if (pluginBean.isReadableProperty(EVICT)) {
     List pluginsToEvict =
         (List) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, EVICT);
     if (pluginsToEvict != null) {
       evictionList = new String[pluginsToEvict.size()];
       int index = 0;
       for (Object o : pluginsToEvict) {
         evictionList[index++] = o != null ? o.toString() : "";
       }
     }
   }
 }
 @SuppressWarnings("unchecked")
 private void evaluatePluginLoadAfters() {
   if (pluginBean.isReadableProperty(PLUGIN_LOAD_AFTER_NAMES)) {
     List loadAfterNamesList =
         (List)
             GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(
                 plugin, PLUGIN_LOAD_AFTER_NAMES);
     if (loadAfterNamesList != null) {
       loadAfterNames =
           (String[]) loadAfterNamesList.toArray(new String[loadAfterNamesList.size()]);
     }
   }
   if (pluginBean.isReadableProperty(PLUGIN_LOAD_BEFORE_NAMES)) {
     List loadBeforeNamesList =
         (List)
             GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(
                 plugin, PLUGIN_LOAD_BEFORE_NAMES);
     if (loadBeforeNamesList != null) {
       loadBeforeNames =
           (String[]) loadBeforeNamesList.toArray(new String[loadBeforeNamesList.size()]);
     }
   }
 }
  @SuppressWarnings("unchecked")
  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);
    }

    final boolean warDeployed = Metadata.getCurrent().isWarDeployed();
    final boolean reloadEnabled = Environment.getCurrent().isReloadEnabled();

    if (!((reloadEnabled || !warDeployed) && onChangeListener != null)) {
      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 = new ArrayList();
        resourceList.add(referencedResources.toString());
      } else if (referencedResources instanceof List) {
        resourceList = (List) referencedResources;
      }

      if (resourceList != null) {
        List<String> resourceListTmp = new ArrayList<String>();
        PluginBuildSettings pluginBuildSettings = GrailsPluginUtils.getPluginBuildSettings();

        if (pluginBuildSettings != null) {

          final Resource[] pluginDirs = pluginBuildSettings.getPluginDirectories();
          final Environment env = Environment.getCurrent();
          final String baseLocation = env.getReloadLocation();

          for (Object ref : resourceList) {
            String stringRef = ref.toString();
            if (!warDeployed) {
              for (Resource pluginDir : pluginDirs) {
                if (pluginDir != null) {
                  String pluginResources =
                      getResourcePatternForBaseLocation(
                          pluginDir.getFile().getCanonicalPath(), stringRef);
                  resourceListTmp.add(pluginResources);
                }
              }
              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 ["
                + ArrayUtils.toString(watchedResourcePatternReferences)
                + "]. This means that the plugin "
                + this
                + ", will not be able to auto-reload changes effectively. Try runnng grails upgrade.: "
                + e.getMessage());
      }
    } catch (IOException e) {
      if (GrailsUtil.isDevelopmentEnv()) {
        LOG.debug(
            "Cannot load plug-in resource watch list from ["
                + ArrayUtils.toString(watchedResourcePatternReferences)
                + "]. This means that the plugin "
                + this
                + ", will not be able to auto-reload changes effectively. Try runnng grails upgrade.: "
                + e.getMessage());
      }
    }
  }