org.codehaus.groovy.grails.plugins
Class DefaultGrailsPluginManager

java.lang.Object
  extended by org.codehaus.groovy.grails.plugins.AbstractGrailsPluginManager
      extended by org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
All Implemented Interfaces:
GrailsPluginManager, ApplicationContextAware, ServletContextAware

public class DefaultGrailsPluginManager
extends AbstractGrailsPluginManager
implements GrailsPluginManager

A class that handles the loading and management of plug-ins in the Grails system. A plugin a just like a normal Grails application except that it contains a file ending in *Plugin.groovy in the root of the directory.

A Plugin class is a Groovy class that has a version and optionally closures called doWithSpring, doWithContext and doWithWebDescriptor

The doWithSpring closure uses the BeanBuilder syntax (@see grails.spring.BeanBuilder) to provide runtime configuration of Grails via Spring

The doWithContext closure is called after the Spring ApplicationContext is built and accepts a single argument (the ApplicationContext)

The doWithWebDescriptor uses mark-up building to provide additional functionality to the web.xml file

Example:

 class ClassEditorGrailsPlugin {
      def version = 1.1
      def doWithSpring = { application ->
          classEditor(org.springframework.beans.propertyeditors.ClassEditor, application.classLoader)
      }
 }
 

A plugin can also define "dependsOn" and "evict" properties that specify what plugins the plugin depends on and which ones it is incompatable with and should evict

Since:
0.4
Author:
Graeme Rocher

Field Summary
 
Fields inherited from class org.codehaus.groovy.grails.plugins.AbstractGrailsPluginManager
application, applicationContext, classNameToPluginMap, failedPlugins, initialised, loadCorePlugins, pluginClasses, pluginList, pluginResources, plugins
 
Fields inherited from interface org.codehaus.groovy.grails.plugins.GrailsPluginManager
BEAN_NAME
 
Constructor Summary
DefaultGrailsPluginManager(Class[] plugins, GrailsApplication application)
           
DefaultGrailsPluginManager(Resource[] pluginFiles, GrailsApplication application)
           
DefaultGrailsPluginManager(String[] pluginResources, GrailsApplication application)
           
DefaultGrailsPluginManager(String resourcePath, GrailsApplication application)
           
 
Method Summary
protected  boolean canRegisterPlugin(GrailsPlugin plugin)
           
 void checkForChanges()
          Checks all the plugins to see whether they have any changes
 void doDynamicMethods()
          This is called on all plugins so that they can add new methods/properties/constructors etc.
 void doWebDescriptor(File descriptor, Writer target)
           
 void doWebDescriptor(Resource descriptor, Writer target)
          Takes the specified web descriptor reference and configures it with all the plugins outputting the result to the target Writer instance
protected  void evictPlugin(GrailsPlugin evictor, String evicteeName)
           
(package private)  List getPluginList()
           
 Collection getPluginObservers(GrailsPlugin plugin)
          Retrieves a collection of plugins that are observing the specified plugin
 ServletContext getServletContext()
           
 GrailsPlugin[] getUserPlugins()
          Gets plugin installed by the user and not provided by the framework
static String getWeb23DTD()
           
 void informObservers(String pluginName, Map event)
          inform the specified plugins observers of the event specified by the passed Map instance
 void informPluginsOfConfigChange()
           
 void loadPlugins()
          Performs the initial load of plug-ins throwing an exception if any dependencies don't resolve
 void refreshPlugin(String name)
          Refreshes the specified plugin.
 void setApplication(GrailsApplication application)
          Sets the GrailsApplication used be this plugin manager
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setParentApplicationContext(ApplicationContext parent)
           
(package private)  void setPluginFilter(PluginFilter pluginFilter)
           
 void setServletContext(ServletContext servletContext)
           
 void startPluginChangeScanner()
           
 void stopPluginChangeScanner()
           
 
Methods inherited from class org.codehaus.groovy.grails.plugins.AbstractGrailsPluginManager
checkInitialised, doArtefactConfiguration, doPostProcessing, doRuntimeConfiguration, doRuntimeConfiguration, getAllPlugins, getFailedLoadPlugins, getFailedPlugin, getGrailsPlugin, getGrailsPlugin, getGrailsPluginForClassName, getPluginPath, getPluginPathForClass, getPluginPathForInstance, getPluginResources, getPluginViewsPathForClass, getPluginViewsPathForInstance, getTypeFilters, hasGrailsPlugin, informOfClassChange, isInitialised, registerProvidedArtefacts, setLoadCorePlugins, shutdown, supportsCurrentBuildScope
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.groovy.grails.plugins.GrailsPluginManager
doArtefactConfiguration, doPostProcessing, doRuntimeConfiguration, doRuntimeConfiguration, getAllPlugins, getFailedLoadPlugins, getFailedPlugin, getGrailsPlugin, getGrailsPlugin, getGrailsPluginForClassName, getPluginPath, getPluginPathForClass, getPluginPathForInstance, getPluginViewsPathForClass, getPluginViewsPathForInstance, getTypeFilters, hasGrailsPlugin, informOfClassChange, isInitialised, registerProvidedArtefacts, setLoadCorePlugins, shutdown, supportsCurrentBuildScope
 

Constructor Detail

DefaultGrailsPluginManager

public DefaultGrailsPluginManager(String resourcePath,
                                  GrailsApplication application)
                           throws IOException
Throws:
IOException

DefaultGrailsPluginManager

public DefaultGrailsPluginManager(String[] pluginResources,
                                  GrailsApplication application)

DefaultGrailsPluginManager

public DefaultGrailsPluginManager(Class[] plugins,
                                  GrailsApplication application)
                           throws IOException
Throws:
IOException

DefaultGrailsPluginManager

public DefaultGrailsPluginManager(Resource[] pluginFiles,
                                  GrailsApplication application)
Method Detail

getUserPlugins

public GrailsPlugin[] getUserPlugins()
Description copied from interface: GrailsPluginManager
Gets plugin installed by the user and not provided by the framework

Specified by:
getUserPlugins in interface GrailsPluginManager
Returns:
A list of user plugins

startPluginChangeScanner

public void startPluginChangeScanner()

stopPluginChangeScanner

public void stopPluginChangeScanner()

refreshPlugin

public void refreshPlugin(String name)
Description copied from interface: GrailsPluginManager
Refreshes the specified plugin. A refresh will force to plugin to "touch" each of its watched resources and fire modified events for each

Specified by:
refreshPlugin in interface GrailsPluginManager
Parameters:
name - The name of the plugin to refresh

getPluginObservers

public Collection getPluginObservers(GrailsPlugin plugin)
Description copied from interface: GrailsPluginManager
Retrieves a collection of plugins that are observing the specified plugin

Specified by:
getPluginObservers in interface GrailsPluginManager
Parameters:
plugin - The plugin to retrieve observers for
Returns:
A collection of observers

informObservers

public void informObservers(String pluginName,
                            Map event)
Description copied from interface: GrailsPluginManager
inform the specified plugins observers of the event specified by the passed Map instance

Specified by:
informObservers in interface GrailsPluginManager
Parameters:
pluginName - The name of the plugin
event - The event

loadPlugins

public void loadPlugins()
                 throws PluginException
Description copied from interface: GrailsPluginManager
Performs the initial load of plug-ins throwing an exception if any dependencies don't resolve

Specified by:
loadPlugins in interface GrailsPluginManager
Throws:
PluginException - Thrown when an error occurs loading the plugins

canRegisterPlugin

protected boolean canRegisterPlugin(GrailsPlugin plugin)

evictPlugin

protected void evictPlugin(GrailsPlugin evictor,
                           String evicteeName)

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Specified by:
setApplicationContext in interface ApplicationContextAware
Overrides:
setApplicationContext in class AbstractGrailsPluginManager
Throws:
BeansException

setParentApplicationContext

public void setParentApplicationContext(ApplicationContext parent)

checkForChanges

public void checkForChanges()
Description copied from interface: GrailsPluginManager
Checks all the plugins to see whether they have any changes

Specified by:
checkForChanges in interface GrailsPluginManager

informPluginsOfConfigChange

public void informPluginsOfConfigChange()

doWebDescriptor

public void doWebDescriptor(Resource descriptor,
                            Writer target)
Description copied from interface: GrailsPluginManager
Takes the specified web descriptor reference and configures it with all the plugins outputting the result to the target Writer instance

Specified by:
doWebDescriptor in interface GrailsPluginManager
Parameters:
descriptor - The Resource of the descriptor
target - The Writer to write the result to

doWebDescriptor

public void doWebDescriptor(File descriptor,
                            Writer target)
Specified by:
doWebDescriptor in interface GrailsPluginManager
Parameters:
descriptor - The File of the descriptor
target - The target to write the changes to
See Also:
GrailsPluginManager.doWebDescriptor(Resource, Writer)

setApplication

public void setApplication(GrailsApplication application)
Description copied from interface: GrailsPluginManager
Sets the GrailsApplication used be this plugin manager

Specified by:
setApplication in interface GrailsPluginManager
Overrides:
setApplication in class AbstractGrailsPluginManager
Parameters:
application - The GrailsApplication instance

doDynamicMethods

public void doDynamicMethods()
Description copied from interface: GrailsPluginManager
This is called on all plugins so that they can add new methods/properties/constructors etc.

Specified by:
doDynamicMethods in interface GrailsPluginManager
Overrides:
doDynamicMethods in class AbstractGrailsPluginManager

setServletContext

public void setServletContext(ServletContext servletContext)
Specified by:
setServletContext in interface ServletContextAware

getServletContext

public ServletContext getServletContext()

setPluginFilter

void setPluginFilter(PluginFilter pluginFilter)

getPluginList

List getPluginList()

getWeb23DTD

public static String getWeb23DTD()


Copyright (c) 2005-2009 The Grails project