Class PluginRepository
The PluginRepository
is a registry of plugins.
Engine
building code can use a PluginRepository
to assemble a set of plugins to use
to populate an engine. A PluginRepository
can in theory be used to assemble multiple engine instances.
While this isn't very interesting for a CLI, where engine construction is per invocation, this might come in use
with a webapp or API.
Each plugin is given its own classloader, PluginClassLoader
, which isolates it from other plugins and from
the Engine itself.
See comments on addPath(File)
for notes on Plugin structure.
Derived from the Nutch project's plugin system
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionList<nz.org.riskscape.engine.plugin.Plugin>
activateAll
(Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor) protected nz.org.riskscape.engine.plugin.Plugin
activatePlugin
(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor, Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor) void
addActivated
(nz.org.riskscape.engine.plugin.Plugin plugin) Register an already 'activated' plugin with this repository.void
Constructs aPluginDescriptor
from either a single jar file or a directory containing jars and adds it to thisPluginRepository
.nz.org.riskscape.engine.plugin.ExtensionPoints
collectFeatures
(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints) Collects all theExtensionPoint
s andPluginFeature
s advertised by activated plugins and returns them in a newExtensionPoints
object.static void
collectFeatures
(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, List<nz.org.riskscape.engine.plugin.Plugin> plugins) Collect all theExtensionPoint
s andPluginFeature
s from the given list of plugins and add them to the givenExtensionPoints
.static void
collectFeatures
(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, nz.org.riskscape.engine.plugin.Plugin... plugins) Collect all theExtensionPoint
s andPluginFeature
s from the given plugins and add them to the givenExtensionPoints
.void
finalize()
List<nz.org.riskscape.engine.plugin.Plugin>
<T extends nz.org.riskscape.engine.plugin.Plugin>
Optional<T>getActivatedPlugin
(Class<T> pluginClass) Optional<nz.org.riskscape.engine.plugin.Plugin>
getActivatedPlugin
(String pluginId) Optional<nz.org.riskscape.engine.plugin.PluginDescriptor>
getPluginById
(String dependencyId) void
register
(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor) Register a plugin, but without activating it.void
scanDirectory
(Path directory)
-
Field Details
-
INSTANCE
-
-
Method Details
-
collectFeatures
public static void collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, List<nz.org.riskscape.engine.plugin.Plugin> plugins) Collect all the
ExtensionPoint
s andPluginFeature
s from the given list of plugins and add them to the givenExtensionPoints
. -
collectFeatures
public static void collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, nz.org.riskscape.engine.plugin.Plugin... plugins) Collect all the
ExtensionPoint
s andPluginFeature
s from the given plugins and add them to the givenExtensionPoints
. -
scanDirectory
-
addActivated
public void addActivated(nz.org.riskscape.engine.plugin.Plugin plugin) Register an already 'activated' plugin with this repository. This allows a plugin to be used that has been constructed outside of the usual code-loading mechanism
-
register
public void register(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor) Register a plugin, but without activating it. It will get activated in due course by the activateAll method instead.
-
addPath
Constructs a
PluginDescriptor
from either a single jar file or a directory containing jars and adds it to thisPluginRepository
.If plugin points to a directory, that directory must contain at least a jar named
plugin.jar
which must contain a manifest that the PluginDescriptor can read. All other jars will be loaded from that directory, with plugin.jar always being loaded first.If plugin points to a jar file, then this is loaded by itself like
plugin.jar
from the directory example before- Parameters:
plugin
- either a jar file or a directory
-
activateAll
-
collectFeatures
public nz.org.riskscape.engine.plugin.ExtensionPoints collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints) Collects all the
ExtensionPoint
s andPluginFeature
s advertised by activated plugins and returns them in a newExtensionPoints
object. -
activatePlugin
protected nz.org.riskscape.engine.plugin.Plugin activatePlugin(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor, Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor) -
getPluginById
- Returns:
- a
PluginDescriptor
from the list of registered plugins with the given dependencyId, or empty if there is no plugin registered with that id
-
finalize
-
getActivatedPlugin
-
getActivatedPlugin
-
getActivated
- Returns:
- a set of all the activated plugins in this repository
-