Class PluginManager<T extends ApplicationComponent>

  • All Implemented Interfaces:
    ApplicationComponent<T>

    public class PluginManager<T extends ApplicationComponent>
    extends Object
    implements ApplicationComponent<T>

    Loads, starts and makes plugins available.

    Note, that most actions and a number of other major components are implemented as plugins. Plugins are either jars in a plugin directory or zips in the plugin directory that are expanded. Native libraries or jars in /lib are loaded or added to the classpath, respectively. /classes is also added to the classpath.

    beaTlets are also loaded by this manager.

    Unless you code your plugin as beaTlet, each plugin has to contain at least one plugin descriptor. The descriptor is a simple XML document that resides in the file /META-INF/plugin.xml. It is needed to tell the PluginManager which classes to instantiate.

    Here's a simple example:

     
     <?xml version="1.0" encoding="UTF-8" ?>
     <!-- contains a list of plugins to be instantiated by the PluginManager -->
     <plugins>
         <name>Awesome</name>
         <id>projectawesome</id>
         <version>0.9.0</version>
         <description>Project Awesome</description>
    
         <!-- your license -->
         <license>
             <name>GNU Lesser General Public License 2.1</name>
             <url>http://www.gnu.org/licenses/lgpl.txt</url>
         </license>
    
         <!-- icons contained in your plugin jar -->
         <icon>
             <small>/com/yourdomain/project/[email protected]</small>
             <large>/com/yourdomain/project/[email protected]</large>
         </icon>
         <change-notes>
             0.9.0 - first version
         </change-notes>
    
         <!-- info about your organization -->
         <vendor>
             <name>YourCompany Inc</name>
             <url>http://www.yourdomain.com/</url>
             <email>[email protected]</email>
             <logo>http://www.yourdomain.com/images/yourcompany-logo.png</logo>
         </vendor>
    
         <!-- versions of beaTunes this plugin works with -->
         <beatunes-version>
             <min>3.0.0</min>
             <max>3.9.9</max>
         </beatunes-version>
    
         <!-- the actual plugin classes that need to be instantiated -->
         <plugin class="com.yourdomain.project.Awesome"/>
         <plugin class="com.yourdomain.project.Awesome2"/>
         <plugin class="com.yourdomain.project.Awesome3"/>
         <!-- add more plugins here ... -->
    
     </plugins>
     
     

    Should you want to write your code in a simple JRuby/Jython/Groovy script, you need to write it as beaTlet. This means you simply drop the source file into the plugin directory. If your beaTlet wants to also expose information about itself, it needs to implement the Plugin interface.

    Author:
    Hendrik Schreiber
    See Also:
    Plugin
    • Constructor Detail

      • PluginManager

        public PluginManager​(T application)
    • Method Detail

      • getUserAgent

        public String getUserAgent()
      • setUserAgent

        public void setUserAgent​(String userAgent)
      • addPluginRepository

        public void addPluginRepository​(PluginRepository pluginRepository)
      • addPluginRepository

        public void addPluginRepository​(URL pluginRepositoryURL)
      • loadRemotePluginDescriptors

        public void loadRemotePluginDescriptors()
                                         throws IOException
        Throws:
        IOException
      • loadRemotePluginDescriptors

        public void loadRemotePluginDescriptors​(boolean forceReload)
                                         throws IOException
        Throws:
        IOException
      • getRemotePluginDescriptorCount

        public int getRemotePluginDescriptorCount()
      • getInstallablePluginDescriptors

        public List<RuntimePluginDescriptor> getInstallablePluginDescriptors()
        Lists plugins that are not installed, but could be installed.
        Returns:
        list of plugin descriptors
      • getInstallablePluginDescriptorCount

        public int getInstallablePluginDescriptorCount()
      • getPluginDir

        public Path getPluginDir()
      • setPluginDir

        public void setPluginDir​(Path pluginDir)
      • setPluginDir

        public void setPluginDir​(File pluginDir)
      • getApplicationVersion

        public Version getApplicationVersion()
      • setApplicationVersion

        public void setApplicationVersion​(Version applicationVersion)
      • uninstall

        public void uninstall​(RuntimePluginDescriptor pluginDescriptor)
                       throws IOException
        Uninstalls a plugin described by its descriptor.
        Parameters:
        pluginDescriptor - plugin descriptor
        Throws:
        IOException - if something goes wrong
      • getImplementationsAnnotatedWith

        public List<?> getImplementationsAnnotatedWith​(Class<? extends Annotation> annotationClass)
        Lets you obtain a list of plugin implementations for the given interface. E.g. to get all registered Entities, call:
         getBeaTunes().getPluginManager().getImplementationsAnnotatedWith(Entity.class)
         
        Parameters:
        annotationClass - annotation the plugin has to be annotated with
        Returns:
        list of implementations
      • getImplementations

        public <A> List<A> getImplementations​(Class<A> interfaceClass)
        Lets you obtain a list of plugin implementations for the given interface. E.g. to get all registered com.tagtraum.beatunes.songtable.SongContextComponents, call:
         getBeaTunes().getPluginManager().getImplementations(SongContextComponent.class)
         
        Parameters:
        interfaceClass - interface the plugin has to implement
        Returns:
        list of implementations
      • getImplementation

        public <A> A getImplementation​(Class<A> interfaceClass)
        Lets you obtain a plugin implementations for the given interface. E.g. to get a registered com.tagtraum.beatunes.songtable.SongContextComponents, call:
         getBeaTunes().getPluginManager().getImplementation(SongContextComponent.class)
         
        Parameters:
        interfaceClass - interface the plugin has to implement
        Returns:
        one implementation or null, if none are registered
      • getPlugin

        public Object getPlugin​(Object id)
        Allows you to retrieve a plugin by id. For this to work, the plugin has to implement a String getId() method.
        Parameters:
        id - id string
        Returns:
        the plugin with the given id or null.
      • getPluginClassLoader

        public ClassLoader getPluginClassLoader()
        At this point all plugins share one classloader. This may change in the future to allow different plugins to use different versions of third party libraries.
        Returns:
        plugin class loader
      • addClassLoader

        public void addClassLoader​(ClassLoader classLoader)
        Add a classloader to the plugin classloader.
        Parameters:
        classLoader - classloader
      • registerRuntimePluginDescriptor

        public void registerRuntimePluginDescriptor​(RuntimePluginDescriptor runtimePluginDescriptor)
      • getPluginDescriptors

        public List<RuntimePluginDescriptor> getPluginDescriptors()
        All currently installed plugin descriptors.
        Returns:
        plugin descriptors
      • getEnabledPluginDescriptors

        public List<RuntimePluginDescriptor> getEnabledPluginDescriptors()
        Currently enabled plugin descriptors.
        Returns:
        enabled descriptors
      • getPluginDescriptorCount

        public int getPluginDescriptorCount()
      • initPlugins

        public void initPlugins()
        Calls ApplicationComponent.init() on all plugins that implement that method. This is done after all plugins have been instantiated. The initialization order is the same as the declaration order in the plugin descriptor plugin.xml.
      • isSuitableForCurrentApplicationVersion

        public boolean isSuitableForCurrentApplicationVersion​(PluginDescriptor pluginDescriptor)