Interface GrailsPluginManager

  • All Superinterfaces:
    org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware
    All Known Implementing Classes:
    AbstractGrailsPluginManager, DefaultGrailsPluginManager, MockGrailsPluginManager, ProfilingGrailsPluginManager

    public interface GrailsPluginManager
    extends org.springframework.context.ApplicationContextAware

    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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BEAN_NAME  
    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      void checkForChanges()
      Deprecated.
      void doArtefactConfiguration()
      Called prior to the initialisation of the GrailsApplication object to allow registration of additional ArtefactHandler objects
      void doDynamicMethods()
      Called on all plugins so that they can add new methods/properties/constructors etc.
      void doPostProcessing​(org.springframework.context.ApplicationContext applicationContext)
      Performs post initialization configuration for each plug-in, passing the built application context
      void doRuntimeConfiguration​(java.lang.String pluginName, org.grails.spring.RuntimeSpringConfiguration springConfig)
      Executes the runtime configuration for a specific plugin AND all its dependencies
      void doRuntimeConfiguration​(org.grails.spring.RuntimeSpringConfiguration springConfig)
      Executes the runtime configuration phase of plug-ins
      GrailsPlugin[] getAllPlugins()
      Returns an array of all the loaded plug-ins
      GrailsPlugin[] getFailedLoadPlugins()  
      GrailsPlugin getFailedPlugin​(java.lang.String name)
      Retrieves a plug-in that failed to load, or null if it doesn't exist
      GrailsPlugin getGrailsPlugin​(java.lang.String name)
      Retrieves a name Grails plugin instance
      GrailsPlugin getGrailsPlugin​(java.lang.String name, java.lang.Object version)
      Retrieves a plug-in for its name and version
      GrailsPlugin getGrailsPluginForClassName​(java.lang.String name)
      Obtains a GrailsPlugin for the given classname
      GrailsPlugin getPluginForClass​(java.lang.Class<?> theClass)
      Obtains the GrailsPlugin for the given class
      GrailsPlugin getPluginForInstance​(java.lang.Object instance)
      Looks up the plugin that defined the given instance.
      java.util.Collection getPluginObservers​(GrailsPlugin plugin)
      Retrieves a collection of plugins that are observing the specified plugin
      java.lang.String getPluginPath​(java.lang.String name)
      Returns the pluginContextPath for the given plugin
      java.lang.String getPluginPath​(java.lang.String name, boolean forceCamelCase)
      Returns the pluginContextPath for the given plugin and will force name to camel case instead of '-' lower case my-plug-web would resolve to myPlugWeb if forceCamelCase is true.
      java.lang.String getPluginPathForClass​(java.lang.Class<? extends java.lang.Object> theClass)
      Returns the plugin path for the given class
      java.lang.String getPluginPathForInstance​(java.lang.Object instance)
      Returns the pluginContextPath for the given instance
      java.lang.String getPluginViewsPathForClass​(java.lang.Class<? extends java.lang.Object> theClass)
      Returns the plugin views directory path for the given class
      java.lang.String getPluginViewsPathForInstance​(java.lang.Object instance)
      Returns the plugin views directory for the given instance
      java.util.List<org.springframework.core.type.filter.TypeFilter> getTypeFilters()
      Get all of the TypeFilter definitions defined by the plugins
      GrailsPlugin[] getUserPlugins()
      Gets plugin installed by the user and not provided by the framework
      boolean hasGrailsPlugin​(java.lang.String name)  
      void informObservers​(java.lang.String pluginName, java.util.Map event)
      inform the specified plugins observers of the event specified by the passed Map instance
      void informOfClassChange​(java.io.File file, java.lang.Class cls)  
      void informOfClassChange​(java.lang.Class<?> aClass)
      Method for handling changes to a class and triggering on change events etc.
      void informOfFileChange​(java.io.File file)
      Fire to inform the PluginManager that a particular file changes
      void informPluginsOfConfigChange()
      Inform of a change in configuration
      boolean isInitialised()  
      boolean isShutdown()
      Indicates whether the manager has been shutdown or not
      void loadPlugins()
      Performs the initial load of plug-ins throwing an exception if any dependencies don't resolve
      void onStartup​(java.util.Map<java.lang.String,​java.lang.Object> event)
      Executes the Plugin.onStartup(Map) hook for all plugins
      void refreshPlugin​(java.lang.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
      void setLoadCorePlugins​(boolean shouldLoadCorePlugins)
      Set whether the core plugins should be loaded
      void setPluginFilter​(PluginFilter pluginFilter)
      Sets the filter to use to filter for plugins
      void shutdown()
      Shuts down the PluginManager
      • Methods inherited from interface org.springframework.context.ApplicationContextAware

        setApplicationContext
    • Method Detail

      • getAllPlugins

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

        GrailsPlugin[] getUserPlugins()
        Gets plugin installed by the user and not provided by the framework
        Returns:
        A list of user plugins
      • getFailedLoadPlugins

        GrailsPlugin[] getFailedLoadPlugins()
        Returns:
        An array of plugins that failed to load due to dependency resolution errors
      • loadPlugins

        void loadPlugins()
                  throws grails.plugins.exceptions.PluginException
        Performs the initial load of plug-ins throwing an exception if any dependencies don't resolve
        Throws:
        grails.plugins.exceptions.PluginException - Thrown when an error occurs loading the plugins
      • doRuntimeConfiguration

        void doRuntimeConfiguration​(org.grails.spring.RuntimeSpringConfiguration springConfig)
        Executes the runtime configuration phase of plug-ins
        Parameters:
        springConfig - The RuntimeSpringConfiguration instance
      • doPostProcessing

        void doPostProcessing​(org.springframework.context.ApplicationContext applicationContext)
        Performs post initialization configuration for each plug-in, passing the built application context
        Parameters:
        applicationContext - The ApplicationContext instance
      • doDynamicMethods

        void doDynamicMethods()
        Called on all plugins so that they can add new methods/properties/constructors etc.
      • onStartup

        void onStartup​(java.util.Map<java.lang.String,​java.lang.Object> event)
        Executes the Plugin.onStartup(Map) hook for all plugins
        Parameters:
        event - the Event
      • getGrailsPlugin

        GrailsPlugin getGrailsPlugin​(java.lang.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
      • getGrailsPluginForClassName

        GrailsPlugin getGrailsPluginForClassName​(java.lang.String name)
        Obtains a GrailsPlugin for the given classname
        Parameters:
        name - The name of the plugin
        Returns:
        The instance
      • hasGrailsPlugin

        boolean hasGrailsPlugin​(java.lang.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​(java.lang.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​(java.lang.String name,
                                     java.lang.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​(java.lang.String pluginName,
                                    org.grails.spring.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

        @Deprecated
        void checkForChanges()
        Deprecated.
        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​(java.lang.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

        java.util.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​(java.lang.String pluginName,
                             java.util.Map event)
        inform the specified plugins observers of the event specified by the passed 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
      • shutdown

        void shutdown()
        Shuts down the PluginManager
      • setLoadCorePlugins

        void setLoadCorePlugins​(boolean shouldLoadCorePlugins)
        Set whether the core plugins should be loaded
        Parameters:
        shouldLoadCorePlugins - True if they should
      • informOfClassChange

        void informOfClassChange​(java.lang.Class<?> aClass)
        Method for handling changes to a class and triggering on change events etc.
        Parameters:
        aClass - The class
      • getTypeFilters

        java.util.List<org.springframework.core.type.filter.TypeFilter> getTypeFilters()
        Get all of the TypeFilter definitions defined by the plugins
        Returns:
        A list of TypeFilter definitions
      • getPluginPath

        java.lang.String getPluginPath​(java.lang.String name)
        Returns the pluginContextPath for the given plugin
        Parameters:
        name - The plugin name
        Returns:
        the context path
      • getPluginPath

        java.lang.String getPluginPath​(java.lang.String name,
                                       boolean forceCamelCase)
        Returns the pluginContextPath for the given plugin and will force name to camel case instead of '-' lower case my-plug-web would resolve to myPlugWeb if forceCamelCase is true.
        Parameters:
        name - The plugin name
        forceCamelCase - Force camel case for name
        Returns:
        the context path
      • getPluginForInstance

        GrailsPlugin getPluginForInstance​(java.lang.Object instance)
        Looks up the plugin that defined the given instance. If no plugin defined the instance then null is returned.
        Parameters:
        instance - The instance
        Returns:
        The plugin that defined the instance or null
      • getPluginPathForInstance

        java.lang.String getPluginPathForInstance​(java.lang.Object instance)
        Returns the pluginContextPath for the given instance
        Parameters:
        instance - The instance
        Returns:
        The pluginContextPath
      • getPluginPathForClass

        java.lang.String getPluginPathForClass​(java.lang.Class<? extends java.lang.Object> theClass)
        Returns the plugin path for the given class
        Parameters:
        theClass - The class
        Returns:
        The pluginContextPath
      • getPluginViewsPathForInstance

        java.lang.String getPluginViewsPathForInstance​(java.lang.Object instance)
        Returns the plugin views directory for the given instance
        Parameters:
        instance - The instance
        Returns:
        The pluginContextPath
      • getPluginViewsPathForClass

        java.lang.String getPluginViewsPathForClass​(java.lang.Class<? extends java.lang.Object> theClass)
        Returns the plugin views directory path for the given class
        Parameters:
        theClass - The class
        Returns:
        The pluginContextPath
      • getPluginForClass

        GrailsPlugin getPluginForClass​(java.lang.Class<?> theClass)
        Obtains the GrailsPlugin for the given class
        Parameters:
        theClass - The class
        Returns:
        The GrailsPlugin for the given class or null if not related to any plugin
      • informPluginsOfConfigChange

        void informPluginsOfConfigChange()
        Inform of a change in configuration
      • informOfFileChange

        void informOfFileChange​(java.io.File file)
        Fire to inform the PluginManager that a particular file changes
        Parameters:
        file - The file that changed
        Since:
        2.0
      • informOfClassChange

        void informOfClassChange​(java.io.File file,
                                 java.lang.Class cls)
      • isShutdown

        boolean isShutdown()
        Indicates whether the manager has been shutdown or not
        Returns:
        True if it was shutdown
      • setPluginFilter

        void setPluginFilter​(PluginFilter pluginFilter)
        Sets the filter to use to filter for plugins
        Parameters:
        pluginFilter - The plugin filter