org.codehaus.groovy.grails.plugins
Interface GrailsPluginManager

All Superinterfaces:
ApplicationContextAware, ServletContextAware
All Known Implementing Classes:
AbstractGrailsPluginManager, DefaultGrailsPluginManager

public interface GrailsPluginManager
extends ApplicationContextAware, ServletContextAware

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
static String BEAN_NAME
           
 
Method Summary
 void checkForChanges()
          Checks all the plugins to see whether they have any changes
 void doArtefactConfiguration()
          Called prior to the initialisation of the GrailsApplication object to allow registration of additional ArtefactHandler objects
 void doDynamicMethods()
          This is called on all plugins so that they can add new methods/properties/constructors etc.
 void doPostProcessing(ApplicationContext applicationContext)
          Performs post initialization configuration for each plug-in, passing the built application context
 void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
          Executes the runtime configuration phase of plug-ins
 void doRuntimeConfiguration(String pluginName, RuntimeSpringConfiguration springConfig)
          Executes the runtime configuration for a specific plugin AND all its dependencies
 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
 GrailsPlugin[] getAllPlugins()
          Returns an array of all the loaded plug-ins
 GrailsPlugin getFailedPlugin(String name)
          Retrieves a plug-in that failed to load, or null if it doesn't exist
 GrailsPlugin getGrailsPlugin(String name)
          Retrieves a name Grails plugin instance
 GrailsPlugin getGrailsPlugin(String name, Object version)
          Retrieves a plug-in for its name and version
 Collection getPluginObservers(GrailsPlugin plugin)
          Retrieves a collection of plugins that are observing the specified plugin
 boolean hasGrailsPlugin(String name)
           
 void informObservers(String pluginName, Map event)
          inform the specified plugins observers of the event specified by the passsed Map instance
 boolean isInitialised()
           
 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 registerProvidedArtefacts(GrailsApplication application)
          Registers pre-compiled artefacts with the GrailsApplication instance, only overriding if the application doesn't already provide an artefact of the same name
 void setApplication(GrailsApplication application)
          Sets the GrailsApplication used be this plugin manager
 
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
 
Methods inherited from interface org.springframework.web.context.ServletContextAware
setServletContext
 

Field Detail

BEAN_NAME

static final String BEAN_NAME
See Also:
Constant Field Values
Method Detail

getAllPlugins

GrailsPlugin[] getAllPlugins()
Returns an array of all the loaded plug-ins

Returns:
An array of plug-ins

loadPlugins

void loadPlugins()
                 throws PluginException
Performs the initial load of plug-ins throwing an exception if any dependencies don't resolve

Throws:
PluginException - Thrown when an error occurs loading the plugins

doRuntimeConfiguration

void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
Executes the runtime configuration phase of plug-ins

Parameters:
springConfig - The RuntimeSpringConfiguration instance

doPostProcessing

void doPostProcessing(ApplicationContext applicationContext)
Performs post initialization configuration for each plug-in, passing the built application context

Parameters:
applicationContext - The ApplicationContext instance

doWebDescriptor

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

Parameters:
descriptor - The Resource of the descriptor
target - The Writer to write the result to

doWebDescriptor

void doWebDescriptor(File descriptor,
                     Writer target)
Parameters:
descriptor - The File of the descriptor
target - The target to write the changes to
See Also:
doWebDescriptor(Resource, Writer)

doDynamicMethods

void doDynamicMethods()
This is called on all plugins so that they can add new methods/properties/constructors etc.


getGrailsPlugin

GrailsPlugin getGrailsPlugin(String name)
Retrieves a name Grails plugin instance

Parameters:
name - The name of the plugin
Returns:
The GrailsPlugin instance or null if it doesn't exist

hasGrailsPlugin

boolean hasGrailsPlugin(String name)
Parameters:
name - The name of the plugin
Returns:
True if the the manager has a loaded plugin with the given name

getFailedPlugin

GrailsPlugin getFailedPlugin(String name)
Retrieves a plug-in that failed to load, or null if it doesn't exist

Parameters:
name - The name of the plugin
Returns:
A GrailsPlugin or null

getGrailsPlugin

GrailsPlugin getGrailsPlugin(String name,
                             Object version)
Retrieves a plug-in for its name and version

Parameters:
name - The name of the plugin
version - The version of the plugin
Returns:
The GrailsPlugin instance or null if it doesn't exist

doRuntimeConfiguration

void doRuntimeConfiguration(String pluginName,
                            RuntimeSpringConfiguration springConfig)
Executes the runtime configuration for a specific plugin AND all its dependencies

Parameters:
pluginName - The name of he plugin
springConfig - The runtime spring config instance

checkForChanges

void checkForChanges()
Checks all the plugins to see whether they have any changes


setApplication

void setApplication(GrailsApplication application)
Sets the GrailsApplication used be this plugin manager

Parameters:
application - The GrailsApplication instance

isInitialised

boolean isInitialised()
Returns:
the initialised

refreshPlugin

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

Parameters:
name - The name of the plugin to refresh

getPluginObservers

Collection getPluginObservers(GrailsPlugin plugin)
Retrieves a collection of plugins that are observing the specified plugin

Parameters:
plugin - The plugin to retrieve observers for
Returns:
A collection of observers

informObservers

void informObservers(String pluginName,
                     Map event)
inform the specified plugins observers of the event specified by the passsed Map instance

Parameters:
pluginName - The name of the plugin
event - The event

doArtefactConfiguration

void doArtefactConfiguration()
Called prior to the initialisation of the GrailsApplication object to allow registration of additional ArtefactHandler objects

See Also:
ArtefactHandler

registerProvidedArtefacts

void registerProvidedArtefacts(GrailsApplication application)
Registers pre-compiled artefacts with the GrailsApplication instance, only overriding if the application doesn't already provide an artefact of the same name

Parameters:
application - The GrailsApplication object


Copyright (c) 2005-2006 The Grails project