Class PluginManager<T extends ApplicationComponent>

  • All Implemented Interfaces:

    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 -->
         <description>Project Awesome</description>
         <!-- your license -->
             <name>GNU Lesser General Public License 2.1</name>
         <!-- icons contained in your plugin jar -->
             <small>/com/yourdomain/project/[email protected]</small>
             <large>/com/yourdomain/project/[email protected]</large>
             0.9.0 - first version
         <!-- info about your organization -->
             <name>YourCompany Inc</name>
             <email>[email protected]</email>
         <!-- versions of beaTunes this plugin works with -->
         <!-- 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 ... -->

    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.

    Hendrik Schreiber
    See Also:
    • 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
      • loadRemotePluginDescriptors

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

        public int getRemotePluginDescriptorCount()
      • getInstallablePluginDescriptors

        public List<RuntimePluginDescriptor> getInstallablePluginDescriptors()
        Lists plugins that are not installed, but could be installed.
        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.
        pluginDescriptor - plugin descriptor
        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:
        annotationClass - annotation the plugin has to be annotated with
        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:
        interfaceClass - interface the plugin has to implement
        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:
        interfaceClass - interface the plugin has to implement
        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.
        id - id string
        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.
        plugin class loader
      • addClassLoader

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

        public void registerRuntimePluginDescriptor​(RuntimePluginDescriptor runtimePluginDescriptor)
      • getPluginDescriptors

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

        public List<RuntimePluginDescriptor> getEnabledPluginDescriptors()
        Currently enabled plugin descriptors.
        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)