Package org.pepsoft.util.plugins
Class PluginManager
java.lang.Object
org.pepsoft.util.plugins.PluginManager
A general purpose plugin manager.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>findPlugins(Class<T> type, String descriptorPath, ClassLoader classLoader) Obtain a list of instances of all plugins available through a particular classloader, or from plugin jars discovered by a previous invocation ofloadPlugins(File, PublicKey, String, Version, boolean), which implement a particular type.Get the list of errors, if any, that occurred while loading the plugins.Get the list of informational messages, if any, that were generated while loading the plugins.static ClassLoaderGet a classloader which gives access to the classes of all the plugins.static DescriptorloadDescriptor(InputStream in, String name) Load a plugin descriptor from an input stream.static voidloadPlugins(File pluginDir, PublicKey publicKey, String descriptorPath, Version hostVersion, boolean updatePlugins) Load plugin jars from a directory, which are signed with a particular private key.
-
Method Details
-
loadPlugins
public static void loadPlugins(File pluginDir, PublicKey publicKey, String descriptorPath, Version hostVersion, boolean updatePlugins) Load plugin jars from a directory, which are signed with a particular private key. Optionally check for updates and replace versions which have updates with their newer versions.This method should be invoked only once. Any discovered and properly signed plugin jars will be available to be returned by later invocations of the
findPlugins(Class, String, ClassLoader)method.- Parameters:
pluginDir- The directory from which to load the plugins.publicKey- The public key corresponding to the private key with which the plugins must have been signed.descriptorPath- The resource path of the file containing the plugin descriptor.hostVersion- The version of the host, for the update checking process and for checking the minimum required host version of the plugins.
-
findPlugins
public static <T> List<T> findPlugins(Class<T> type, String descriptorPath, ClassLoader classLoader) Obtain a list of instances of all plugins available through a particular classloader, or from plugin jars discovered by a previous invocation ofloadPlugins(File, PublicKey, String, Version, boolean), which implement a particular type.- Type Parameters:
T- The type of plugin to return.- Parameters:
type- The type of plugin to return.descriptorPath- The resource path of the file containing the plugin descriptor.classLoader- The classloader from which to discover plugins.- Returns:
- A list of newly instantiated plugin objects of the specified type available from the specified classloader and/or any earlier discovered plugin jars.
-
getPluginClassLoader
Get a classloader which gives access to the classes of all the plugins.- Returns:
- A classloader which gives access to the classes of all the plugins.
-
getMessages
Get the list of informational messages, if any, that were generated while loading the plugins.- Returns:
- The list of informational messages, if any, that were generated
while loading the plugins. May be empty, but is never
null.
-
getErrors
Get the list of errors, if any, that occurred while loading the plugins.- Returns:
- The list of errors, if any, that occurred while loading the
plugins. May be empty, but is never
null.
-
loadDescriptor
Load a plugin descriptor from an input stream. Both the old format and the new JSON-based format are supported.- Parameters:
in- The input stream from which to read the descriptor. Will be closed.name- A name associated with the input stream, to be used as a fall back plugin name. May benullif not available.- Returns:
- The plugin descriptor read from the stream.
- Throws:
IOException
-