Class PluginManager
java.lang.Object
de.iip_ecosphere.platform.support.plugins.PluginManager
Manages plugins to separate overlapping classpaths and dependencies of alternatives and optionals.
Identifies plugins via
PluginSetupDescriptor and loads plugin on demand and via the plugin
id. Additionally, considers comma/semicolon separated paths in env/system property
"okto.plugins" to be loaded as unpacked plugins.
The PluginManager does not load plugins automatically as the first point in time to address
the PluginManager may be too early, see PluginSetup. Call loadPlugins(),
loadAllFrom(File, PluginSetupDescriptor...)
loadAllFrom(File, PluginFilter, PluginSetupDescriptor...) explicitly.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAllows to filter out plugins that shall not be loaded.static classCollects information about a plugin. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Map<String, PluginDescriptor<?>> static final Stringstatic final StringPrefix identification key for classpath meta-information on the optional plugin ids.static final StringPrefix identification key for sequence number meta-information on the setup descriptor.static final StringPrefix identification key for classpath meta-information on the setup descriptor.static final StringPostfix of plugin id to indicate a default plugin that is also returned if no plugin id matches. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddToLoad(List<PluginManager.PluginInfo> toLoad, File cpFile, int sequenceNr, Supplier<PluginSetupDescriptor> supplier) Creates aPluginManager.PluginInfoand adds it to the set of plugins to load.private static voidaddToLoad(List<PluginManager.PluginInfo> toLoad, File cpFile, int sequenceNr, Supplier<PluginSetupDescriptor> supplier, List<String> pluginIds) Creates aPluginManager.PluginInfoand adds it to the set of plugins to load.static voidcleanup()CallsPlugin.cleanup()on all known plugins.private static StringextractSuffix(String prefix, String line, String dflt) Extracts the suffix after removing the prefix.static <T> Plugin<T> Returns a plugin for a specific type, possibly the default plugin.static <T> Plugin<T> Returns a plugin for a specific type.static Plugin<?> Returns a specific plugin.static <T> Plugin<T> Returns a specific plugin.static <T,I extends PluginInstanceDescriptor<T>>
TgetPluginInstance(Class<T> pluginCls, Class<I> iCls) Returns an instance of a plugin, either via this plugin manager or via an optional JSL descriptor.static ClassLoaderReturns the class loader of the specified plugin.static ClassLoadergetPluginLoader(String id, ClassLoader dflt) Returns the class loader of the specified plugin.static voidloadAllFrom(File folder, PluginManager.PluginFilter filter, PluginSetupDescriptor... local) Loads all plugins infolder, either in individual folders per plugin or merged into on jar folder with individual classpath files.static voidloadAllFrom(File folder, PluginSetupDescriptor... local) Loads all plugins infolder, either in individual folders per plugin or merged into on jar folder with individual classpath files.private static booleanloadedBy(Object obj, ClassLoader loader) Returns whetherobjwas loaded byloader.private static voidloadPluginFrom(File cpFile, int maxFiles, PluginManager.PluginFilter filter, PluginSetupDescriptor... local) Loads the plugin specified by its classpath file and its jar file folder based on metadata in the classpath file.static voidLoads new plugins from all known plugin setup descriptors.private static voidloadPlugins(boolean onlyNew) Loads plugins from all known plugin setup descriptors.private static intparseSequenceNr(File cpFile, String text, int dflt) Parses the plugin sequence number.plugins()Returns all known plugins.static voidregisterPlugin(PluginDescriptor<?> desc) Registers the given plugin descriptor as a new plugin without installation directory.static voidregisterPlugin(PluginDescriptor<?> desc, boolean onlyNew, File installDir) Registers the given plugin descriptor.static voidExplicitly registers the given plugin (setup) descriptor.private static voidregisterPlugin(PluginSetupDescriptor desc, boolean onlyNew) Registers the given plugin (setup) descriptor.private static List<PluginManager.PluginInfo> sortPlugins(List<PluginManager.PluginInfo> infos) Sorts the plugins, basically according to their initial sequence number and then, if given, after the last specified dependent plugin (or if not matching at the end).
-
Field Details
-
POSTFIX_ID_DEFAULT
Postfix of plugin id to indicate a default plugin that is also returned if no plugin id matches.- See Also:
-
KEY_SETUP_DESCRIPTOR
Prefix identification key for classpath meta-information on the setup descriptor.- See Also:
-
KEY_SEQUENCE_NR
Prefix identification key for sequence number meta-information on the setup descriptor.- See Also:
-
KEY_PLUGIN_IDS
Prefix identification key for classpath meta-information on the optional plugin ids.- See Also:
-
FILE_PLUGINS_PROPERTY
- See Also:
-
plugins
-
pluginsByType
-
descriptors
-
-
Constructor Details
-
PluginManager
public PluginManager()
-
-
Method Details
-
getPlugin
Returns a specific plugin.- Parameters:
id- the unique id of the plugin- Returns:
- the plugin, may be null for none
-
getPlugin
Returns a specific plugin.- Type Parameters:
T- the type of plugin to return- Parameters:
id- the id of the plugincls- the class the plugin shall be of- Returns:
- the plugin (primary or for secondary ids the first registered one), may be null for none
-
getPlugin
Returns a plugin for a specific type, possibly the default plugin.- Type Parameters:
T- the type of plugin to return- Parameters:
cls- the class the plugin shall be of- Returns:
- the plugin, preferrably the default plugin, may be null for none
-
getPluginInstance
public static <T,I extends PluginInstanceDescriptor<T>> T getPluginInstance(Class<T> pluginCls, Class<I> iCls) Returns an instance of a plugin, either via this plugin manager or via an optional JSL descriptor.- Type Parameters:
T- the type of the pluginI- the type of the JSL instance descriptor- Parameters:
pluginCls- the plugin classiCls- the instance descriptor class, may be null- Returns:
- the plugin instance, null if none was found/created
-
getPlugin
Returns a plugin for a specific type.- Type Parameters:
T- the type of plugin to return- Parameters:
cls- the class the plugin shall be ofid- the optional id of the plugin to return, may be null or empty leading to the default/first registered plugin- Returns:
- the plugin, preferrably the default plugin if
iddoes not match, may be null for none
-
plugins
Returns all known plugins.- Returns:
- all known plugins
-
loadPlugins
public static void loadPlugins()Loads new plugins from all known plugin setup descriptors. -
cleanup
public static void cleanup()CallsPlugin.cleanup()on all known plugins. -
loadPlugins
private static void loadPlugins(boolean onlyNew) Loads plugins from all known plugin setup descriptors.- Parameters:
onlyNew- iftrueconsiders only unknown/new plugins, iffalseconsides all plugins and issues warnings
-
registerPlugin
Explicitly registers the given plugin (setup) descriptor. Obtains the class loader of the descriptor and loads the knownplugin descriptors.- Parameters:
desc- the plugin setup descriptor- See Also:
-
registerPlugin
Registers the given plugin (setup) descriptor. Obtains the class loader of the descriptor and loads the knownplugin descriptors. Mandates that knownplugin descriptorsare loaded by the class loader(s) ofdesc.- Parameters:
desc- the plugin setup descriptoronlyNew- iftrueconsiders only unknown/new plugins, iffalseconsides all plugins and issues warnings- See Also:
-
loadedBy
Returns whetherobjwas loaded byloader.- Parameters:
obj- the object to inspectloader- the class loader to compare- Returns:
trueifobjwas loaded byloader,falseelse
-
registerPlugin
Registers the given plugin descriptor as a new plugin without installation directory.- Parameters:
desc- the descriptor to register
-
registerPlugin
Registers the given plugin descriptor. May warn if aplugin idis already registered and ignores thendesc.- Parameters:
desc- the descriptor to registeronlyNew- iftrueconsiders only unknown/new plugins, iffalseconsiders all plugins and issues warningsinstallDir- the installation directory, may be null
-
getPluginLoader
Returns the class loader of the specified plugin.- Parameters:
id- the plugin id- Returns:
- the class loader or the current cpntext class loader if unknown
-
getPluginLoader
Returns the class loader of the specified plugin.- Parameters:
id- the plugin id- Returns:
- the class loader or
dfltif unknown
-
loadAllFrom
Loads all plugins infolder, either in individual folders per plugin or merged into on jar folder with individual classpath files.- Parameters:
folder- the parent folder of the plugins folder or of the classpaths (jars in parent folder)local- additional local plugin setup descriptors to be considered before the file-based ones
-
loadAllFrom
public static void loadAllFrom(File folder, PluginManager.PluginFilter filter, PluginSetupDescriptor... local) Loads all plugins infolder, either in individual folders per plugin or merged into on jar folder with individual classpath files.- Parameters:
folder- the parent folder of the plugins folder or of the classpaths (jars in parent folder)filter- optional filter removing those plugins that shall not be loaded, e.g., as covered bylocal; may be null for nonelocal- additional local plugin setup descriptors to be considered before the file-based ones
-
extractSuffix
Extracts the suffix after removing the prefix.- Parameters:
prefix- the prefix to look for, may be nullline- the line to extract the suffix fromdflt- the default value if there is no prefix, usuallyline- Returns:
lineor the line without the prefix
-
addToLoad
private static void addToLoad(List<PluginManager.PluginInfo> toLoad, File cpFile, int sequenceNr, Supplier<PluginSetupDescriptor> supplier) Creates aPluginManager.PluginInfoand adds it to the set of plugins to load.- Parameters:
toLoad- the list of plugins to loadcpFile- the classpath file defining the pluginsequenceNr- the indicative sequence number to load the pluginsupplier- the supplier to create the setup descriptor
-
addToLoad
private static void addToLoad(List<PluginManager.PluginInfo> toLoad, File cpFile, int sequenceNr, Supplier<PluginSetupDescriptor> supplier, List<String> pluginIds) Creates aPluginManager.PluginInfoand adds it to the set of plugins to load.- Parameters:
toLoad- the list of plugins to loadcpFile- the classpath file defining the pluginsequenceNr- the indicative sequence number to load the pluginsupplier- the supplier to create the setup descriptorpluginIds- the dependent plugin ids to be considered, may be null
-
parseSequenceNr
Parses the plugin sequence number.- Parameters:
cpFile- the plugin being processed (for logging)text- the text representing the sequence number, may be nulldflt- the default sequence number to use in case of parsing problems- Returns:
- the sequence number
-
loadPluginFrom
private static void loadPluginFrom(File cpFile, int maxFiles, PluginManager.PluginFilter filter, PluginSetupDescriptor... local) Loads the plugin specified by its classpath file and its jar file folder based on metadata in the classpath file.- Parameters:
cpFile- the classpath filefilter- optional filter removing those plugins that shall not be loaded, e.g., as covered bylocal; may be null for nonelocal- additional local plugin setup descriptors to be considered before the file-based ones
-
sortPlugins
Sorts the plugins, basically according to their initial sequence number and then, if given, after the last specified dependent plugin (or if not matching at the end).- Parameters:
infos- the plugin informations to sort
-