Package org.pf4j
Class AbstractPluginManager
java.lang.Object
org.pf4j.AbstractPluginManager
- All Implemented Interfaces:
PluginManager
- Direct Known Subclasses:
DefaultPluginManager
This class implements the boilerplate plugin code that any
PluginManager
implementation would have to support.
It helps cut the noise out of the subclass that handles plugin management.
This class is not thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
protected DependencyResolver
static final String
protected boolean
protected ExtensionFactory
protected ExtensionFinder
private static final org.slf4j.Logger
static final String
protected Map
<String, ClassLoader> A map of plugin class loaders (the key is the 'pluginId').protected PluginDescriptorFinder
protected PluginFactory
protected PluginLoader
protected PluginRepository
protected Map
<String, PluginWrapper> A map of plugins this manager is responsible for (the key is the 'pluginId').static final String
protected Path
protected List
<PluginStateListener> The registeredPluginStateListener
s.protected PluginStatusProvider
protected List
<PluginWrapper> A list with all resolved plugins (resolved dependency).protected RuntimeMode
Cache value for the runtime mode.protected List
<PluginWrapper> A list with started plugins.protected String
The system version used for comparisons to the plugin requires attribute.protected List
<PluginWrapper> A list with unresolved plugins (unresolved dependency).protected VersionManager
-
Constructor Summary
ConstructorsConstructorDescriptionThe plugins root is supplied bySystem.getProperty("pf4j.pluginsDir", "plugins")
.AbstractPluginManager
(Path pluginsRoot) ConstructsAbstractPluginManager
with the given plugins root. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPluginStateListener
(PluginStateListener listener) private void
checkPluginId
(String pluginId) protected abstract ExtensionFactory
protected abstract ExtensionFinder
protected abstract PluginDescriptorFinder
protected abstract PluginFactory
protected abstract PluginLoader
protected abstract PluginRepository
protected Path
Add the possibility to override the plugins root.protected abstract PluginStatusProvider
protected abstract VersionManager
boolean
deletePlugin
(String pluginId) Deletes a plugin.boolean
disablePlugin
(String pluginId) Disables a plugin from being loaded.boolean
enablePlugin
(String pluginId) Enables a plugin that has previously been disabled.protected void
getExtensionClasses
(Class<T> type) getExtensionClasses
(Class<T> type, String pluginId) getExtensionClasses
(String pluginId) getExtensionClasses
(List<ExtensionWrapper<T>> extensionsWrapper) getExtensionClassNames
(String pluginId) <T> List
<T> getExtensions
(Class<T> type) <T> List
<T> getExtensions
(Class<T> type, String pluginId) getExtensions
(String pluginId) private <T> List
<T> getExtensions
(List<ExtensionWrapper<T>> extensionsWrapper) Retrieves the plugin with this id, or null if the plugin does not exist.getPluginClassLoader
(String pluginId) Get theClassLoader
for plugin.protected Map
<String, ClassLoader> protected PluginDescriptorFinder
protected PluginFactory
protected String
getPluginLabel
(PluginDescriptor pluginDescriptor) The plugin label is used in logging and it's a string in formatpluginId@pluginVersion
.Returns a copy of plugins.getPlugins
(PluginState pluginState) Returns a copy of plugins with that state.Gets the path of the folder where plugins are installed.Retrieves all resolved plugins (with resolved dependency).The runtime mode.Retrieves all started plugins.Returns the system version.Retrieves all unresolved plugins (with unresolved dependency).protected String
Tests for already loaded plugins on given path.protected void
boolean
protected boolean
isPluginDisabled
(String pluginId) protected boolean
isPluginValid
(PluginWrapper pluginWrapper) Check if this plugin is valid (satisfies "requires" param) for a given system version.loadPlugin
(Path pluginPath) Load a plugin.protected PluginWrapper
loadPluginFromPath
(Path pluginPath) void
Load plugins.void
removePluginStateListener
(PluginStateListener listener) protected void
void
setExactVersionAllowed
(boolean exactVersionAllowed) Set to true to allow requires expression to be exactly x.y.z.void
setSystemVersion
(String version) Set the system version.startPlugin
(String pluginId) Start the specified plugin and its dependencies.void
Start all active plugins.stopPlugin
(String pluginId) Stop the specified plugin and it's dependents.private PluginState
stopPlugin
(String pluginId, boolean stopDependents) void
Stop all active plugins.boolean
unloadPlugin
(String pluginId) Unload the specified plugin and it's dependents.private boolean
unloadPlugin
(String pluginId, boolean unloadDependents) protected void
validatePluginDescriptor
(PluginDescriptor descriptor) Override this to change the validation criteria.whichPlugin
(Class<?> clazz) Retrieves thePluginWrapper
that loaded the given class 'clazz'.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.pf4j.PluginManager
isDevelopment, isNotDevelopment
-
Field Details
-
log
private static final org.slf4j.Logger log -
PLUGINS_DIR_PROPERTY_NAME
- See Also:
-
MODE_PROPERTY_NAME
- See Also:
-
DEFAULT_PLUGINS_DIR
- See Also:
-
DEVELOPMENT_PLUGINS_DIR
- See Also:
-
pluginsRoot
-
extensionFinder
-
pluginDescriptorFinder
-
plugins
A map of plugins this manager is responsible for (the key is the 'pluginId'). -
pluginClassLoaders
A map of plugin class loaders (the key is the 'pluginId'). -
unresolvedPlugins
A list with unresolved plugins (unresolved dependency). -
resolvedPlugins
A list with all resolved plugins (resolved dependency). -
startedPlugins
A list with started plugins. -
pluginStateListeners
The registeredPluginStateListener
s. -
runtimeMode
Cache value for the runtime mode. No need to re-read it because it wont change at runtime. -
systemVersion
The system version used for comparisons to the plugin requires attribute. -
pluginRepository
-
pluginFactory
-
extensionFactory
-
pluginStatusProvider
-
dependencyResolver
-
pluginLoader
-
exactVersionAllowed
protected boolean exactVersionAllowed -
versionManager
-
-
Constructor Details
-
AbstractPluginManager
public AbstractPluginManager()The plugins root is supplied bySystem.getProperty("pf4j.pluginsDir", "plugins")
. -
AbstractPluginManager
ConstructsAbstractPluginManager
with the given plugins root.- Parameters:
pluginsRoot
- the root to search for plugins
-
-
Method Details
-
setSystemVersion
Description copied from interface:PluginManager
Set the system version. This is used to compare against the plugin requires attribute. The default system version is 0.0.0 which disables all version checking.- Specified by:
setSystemVersion
in interfacePluginManager
- Parameters:
version
-
-
getSystemVersion
Description copied from interface:PluginManager
Returns the system version.- Specified by:
getSystemVersion
in interfacePluginManager
- Returns:
- the system version
-
getPlugins
Returns a copy of plugins.- Specified by:
getPlugins
in interfacePluginManager
-
getPlugins
Returns a copy of plugins with that state.- Specified by:
getPlugins
in interfacePluginManager
-
getResolvedPlugins
Description copied from interface:PluginManager
Retrieves all resolved plugins (with resolved dependency).- Specified by:
getResolvedPlugins
in interfacePluginManager
-
getUnresolvedPlugins
Description copied from interface:PluginManager
Retrieves all unresolved plugins (with unresolved dependency).- Specified by:
getUnresolvedPlugins
in interfacePluginManager
-
getStartedPlugins
Description copied from interface:PluginManager
Retrieves all started plugins.- Specified by:
getStartedPlugins
in interfacePluginManager
-
getPlugin
Description copied from interface:PluginManager
Retrieves the plugin with this id, or null if the plugin does not exist.- Specified by:
getPlugin
in interfacePluginManager
- Parameters:
pluginId
- the unique plugin identifier, specified in its metadata- Returns:
- A PluginWrapper object for this plugin, or null if it does not exist.
-
loadPlugin
Description copied from interface:PluginManager
Load a plugin.- Specified by:
loadPlugin
in interfacePluginManager
- Parameters:
pluginPath
- the plugin location- Returns:
- the pluginId of the installed plugin as specified in its metadata
-
loadPlugins
public void loadPlugins()Load plugins.- Specified by:
loadPlugins
in interfacePluginManager
-
unloadPlugin
Unload the specified plugin and it's dependents.- Specified by:
unloadPlugin
in interfacePluginManager
- Parameters:
pluginId
- the unique plugin identifier, specified in its metadata- Returns:
- true if the plugin was unloaded
-
unloadPlugin
-
deletePlugin
Description copied from interface:PluginManager
Deletes a plugin.- Specified by:
deletePlugin
in interfacePluginManager
- Parameters:
pluginId
- the unique plugin identifier, specified in its metadata- Returns:
- true if the plugin was deleted
-
startPlugins
public void startPlugins()Start all active plugins.- Specified by:
startPlugins
in interfacePluginManager
-
startPlugin
Start the specified plugin and its dependencies.- Specified by:
startPlugin
in interfacePluginManager
- Returns:
- the plugin state
-
stopPlugins
public void stopPlugins()Stop all active plugins.- Specified by:
stopPlugins
in interfacePluginManager
-
stopPlugin
Stop the specified plugin and it's dependents.- Specified by:
stopPlugin
in interfacePluginManager
- Returns:
- the plugin state
-
stopPlugin
-
checkPluginId
-
disablePlugin
Description copied from interface:PluginManager
Disables a plugin from being loaded.- Specified by:
disablePlugin
in interfacePluginManager
- Parameters:
pluginId
- the unique plugin identifier, specified in its metadata- Returns:
- true if plugin is disabled
-
enablePlugin
Description copied from interface:PluginManager
Enables a plugin that has previously been disabled.- Specified by:
enablePlugin
in interfacePluginManager
- Parameters:
pluginId
- the unique plugin identifier, specified in its metadata- Returns:
- true if plugin is enabled
-
getPluginClassLoader
Get theClassLoader
for plugin.- Specified by:
getPluginClassLoader
in interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClasses
in interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClasses
in interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClasses
in interfacePluginManager
-
getExtensions
- Specified by:
getExtensions
in interfacePluginManager
-
getExtensions
- Specified by:
getExtensions
in interfacePluginManager
-
getExtensions
- Specified by:
getExtensions
in interfacePluginManager
-
getExtensionClassNames
- Specified by:
getExtensionClassNames
in interfacePluginManager
-
getExtensionFactory
- Specified by:
getExtensionFactory
in interfacePluginManager
-
getPluginLoader
-
getPluginsRoot
Description copied from interface:PluginManager
Gets the path of the folder where plugins are installed.- Specified by:
getPluginsRoot
in interfacePluginManager
- Returns:
- Path of plugins root
-
getRuntimeMode
Description copied from interface:PluginManager
The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.- Specified by:
getRuntimeMode
in interfacePluginManager
-
whichPlugin
Description copied from interface:PluginManager
Retrieves thePluginWrapper
that loaded the given class 'clazz'.- Specified by:
whichPlugin
in interfacePluginManager
-
addPluginStateListener
- Specified by:
addPluginStateListener
in interfacePluginManager
-
removePluginStateListener
- Specified by:
removePluginStateListener
in interfacePluginManager
-
getVersion
-
createPluginRepository
-
createPluginFactory
-
createExtensionFactory
-
createPluginDescriptorFinder
-
createExtensionFinder
-
createPluginStatusProvider
-
createPluginLoader
-
createVersionManager
-
getPluginDescriptorFinder
-
getPluginFactory
-
getPluginClassLoaders
-
initialize
protected void initialize() -
createPluginsRoot
Add the possibility to override the plugins root. If aPLUGINS_DIR_PROPERTY_NAME
system property is defined than this method returns that root. IfgetRuntimeMode()
returnsRuntimeMode.DEVELOPMENT
thanDEVELOPMENT_PLUGINS_DIR
is returned else this method returnsDEFAULT_PLUGINS_DIR
.- Returns:
- the plugins root
-
isPluginValid
Check if this plugin is valid (satisfies "requires" param) for a given system version.- Parameters:
pluginWrapper
- the plugin to check- Returns:
- true if plugin satisfies the "requires" or if requires was left blank
-
isPluginDisabled
-
resolvePlugins
protected void resolvePlugins() -
firePluginStateEvent
-
loadPluginFromPath
-
idForPath
Tests for already loaded plugins on given path.- Parameters:
pluginPath
- the path to investigate- Returns:
- id of plugin or null if not loaded
-
validatePluginDescriptor
Override this to change the validation criteria.- Parameters:
descriptor
- the plugin descriptor to validate- Throws:
PluginRuntimeException
- if validation fails
-
isExactVersionAllowed
public boolean isExactVersionAllowed()- Returns:
- true if exact versions in requires is allowed
-
setExactVersionAllowed
public void setExactVersionAllowed(boolean exactVersionAllowed) Set to true to allow requires expression to be exactly x.y.z. The default is false, meaning that using an exact version x.y.z will implicitly mean the same as >=x.y.z- Parameters:
exactVersionAllowed
- set to true or false
-
getVersionManager
- Specified by:
getVersionManager
in interfacePluginManager
-
getPluginLabel
The plugin label is used in logging and it's a string in formatpluginId@pluginVersion
. -
getExtensionClasses
private <T> List<Class<? extends T>> getExtensionClasses(List<ExtensionWrapper<T>> extensionsWrapper) -
getExtensions
-