Class PluginsContainer

All Implemented Interfaces:
Registry, Iterable<Object>, Collection<Object>, Set<Object>

public class PluginsContainer extends AbstractSet<Object> implements Set<Object>, Registry
The plugin set for a Processor. Plugins are general service objects and can be any type. The PluginsContainer treats the @{link PluginsContainer.PluginProvider special. If it is used with a type, it will expand when it encounters a PluginsContainer.PluginProvider plugin, see getPlugin(Class) and getPlugins(Class). These provided plugins are _not_ part of the this set so they won't be explicitly returned when plugins() is called.
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • defaultConstructor

      private static final MethodType defaultConstructor
    • plugins

      private final Set<Object> plugins
    • missingCommand

      private final Set<String> missingCommand
    • closeablePlugins

      private final Set<AutoCloseable> closeablePlugins
    • processor

      Processor processor
  • Constructor Details

    • PluginsContainer

      protected PluginsContainer()
  • Method Details

    • init

      protected void init(Processor processor)
      Init actions occur inside of the first-level memoizer.
    • postInit

      protected void postInit(Processor processor)
      Post init actions must occur outside of the first level memoizer. This means these actions can reentrantly see the current state of the PluginsContainer, through the Processor, which may be partially complete if addExtensions adds more plugins.
    • plugins

      protected Set<Object> plugins()
      Return the set of plugins added to this container.

      This will include PluginsContainer.PluginProviders themselves, if any, rather than any plugins the PluginsContainer.PluginProviders may provide.

      Use stream(Class) or @{link spliterator(Class) to return the complete plugins including any plugins the PluginsContainer.PluginProviders may provide as well as the plugins from the parent processor. The complete plugins may have duplicates if the same plugin is added into different processors in the hierarchy.

    • stream

      protected <T> Stream<T> stream(Class<T> type)
      Returns a stream of plugins of the specified type ordered by the processor hierarchy.

      The supplied plugins may have duplicates if the same plugin is added into different processors in the hierarchy.

    • spliterator

      protected <T> Spliterator<T> spliterator(Class<T> type)
      Returns a spliterator of plugins of the specified type ordered by the processor hierarchy.

      The supplied plugins may have duplicates if the same plugin is added into different processors in the hierarchy.

    • getPlugin

      public <T> T getPlugin(Class<T> type)
      Return the first plugin of the specified type.

      This may invoke any PluginsContainer.PluginProviders that match the specified type.

      Specified by:
      getPlugin in interface Registry
    • getPlugins

      public <T> List<T> getPlugins(Class<T> type)
      Return all plugins of the specified type. Duplicates are removed.

      This will invoke any PluginsContainer.PluginProviders that match the specified type.

      Specified by:
      getPlugins in interface Registry
    • add

      public boolean add(Object plugin)
      Specified by:
      add in interface Collection<Object>
      Specified by:
      add in interface Set<Object>
      Overrides:
      add in class AbstractCollection<Object>
    • addAll

      public boolean addAll(Collection<? extends Object> collection)
      Specified by:
      addAll in interface Collection<Object>
      Specified by:
      addAll in interface Set<Object>
      Overrides:
      addAll in class AbstractCollection<Object>
    • remove

      public boolean remove(Object plugin)
      Specified by:
      remove in interface Collection<Object>
      Specified by:
      remove in interface Set<Object>
      Overrides:
      remove in class AbstractCollection<Object>
    • iterator

      public Iterator<Object> iterator()
      Specified by:
      iterator in interface Collection<Object>
      Specified by:
      iterator in interface Iterable<Object>
      Specified by:
      iterator in interface Set<Object>
      Specified by:
      iterator in class AbstractCollection<Object>
    • spliterator

      public Spliterator<Object> spliterator()
      Specified by:
      spliterator in interface Collection<Object>
      Specified by:
      spliterator in interface Iterable<Object>
      Specified by:
      spliterator in interface Set<Object>
    • stream

      public Stream<Object> stream()
      Specified by:
      stream in interface Collection<Object>
    • size

      public int size()
      Specified by:
      size in interface Collection<Object>
      Specified by:
      size in interface Set<Object>
      Specified by:
      size in class AbstractCollection<Object>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Object>
    • loadPlugins

      protected void loadPlugins(Processor processor, String pluginString, String pluginPathString)
      Magic to load the plugins. This is quite tricky actually since we allow plugins to be downloaded (this is mainly intended for repositories since in general plugins should use extensions, however to bootstrap the extensions we need more). Since downloads might need plugins for passwords and protocols we need to first load the paths specified on the plugin clause, then check if there are any local plugins (starting with aQute.bnd and be able to load from our own class loader).

      After that, we load the plugin paths, these can use the built in connectors.

      Last but not least, we load the remaining plugins.

    • loadPluginPath

      private void loadPluginPath(Processor processor, String pluginPath, Processor.CL loader)
      Add the @link Constants.PLUGINPATH entries (which are file names) to the class loader. If this file does not exist, and there is a Constants.PLUGINPATH_URL_ATTR attribute then we download it first from that url. You can then also specify a Constants.PLUGINPATH_SHA1_ATTR attribute to verify the file.
      Parameters:
      pluginPath - the clauses for the plugin path
      loader - The class loader to extend
      See Also:
      • PLUGINPATH
    • loadPlugin

      private Object loadPlugin(Processor processor, ClassLoader loader, Attrs attrs, String className, boolean ignoreError)
      Load a plugin and customize it. If the plugin cannot be loaded then we return null.
      Parameters:
      loader - Name of the loader
      attrs -
      className -
    • isMissingPlugin

      boolean isMissingPlugin(String name)
    • close

      protected void close()