/* Copyright 2011 SpringSource
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.codehaus.groovy.grails.cli.agent;

import com.springsource.loaded.Plugins;
import com.springsource.loaded.ReloadEventProcessorPlugin;
import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
import org.codehaus.groovy.grails.plugins.PluginManagerHolder;

/**
 *
 * Reloading agent plugin for use with the GrailsPluginManager
 *
 * @author Graeme Rocher
 * @since 1.4
 */
public class GrailsPluginManagerReloadPlugin implements ReloadEventProcessorPlugin {

    public void reloadEvent(String typename, Class<?> aClass, String encodedTimestamp) {
        GrailsPluginManager pluginManager = PluginManagerHolder.getPluginManager();
        if(pluginManager != null) {
            pluginManager.informOfClassChange(aClass);
        }
    }


    public static void register() {
        Plugins.registerGlobalPlugin(new GrailsPluginManagerReloadPlugin());
    }
}

@@ -734,16 +734,80 @@
 Plugin;%0A
+import org.codehaus.groovy.grails.commons.ClassPropertyFetcher;%0A
 import o
@@ -857,24 +857,24 @@
 ginManager;%0A
-
 import org.c
@@ -923,16 +923,77 @@
 rHolder;
+%0Aimport org.springframework.beans.CachedIntrospectionResults;
 %0A%0A/**%0A *
@@ -1188,16 +1188,16 @@
 ugin %7B%0A%0A
-
     publ
@@ -1273,24 +1273,165 @@
 imestamp) %7B%0A
+        CachedIntrospectionResults.clearClassLoader(aClass.getClassLoader());%0A        ClassPropertyFetcher.clearClassPropertyFetcherCache();%0A
         Grai

clear some caches on reload