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 Stringprotected DependencyResolverstatic final Stringprotected booleanprotected ExtensionFactoryprotected ExtensionFinderprivate static final org.slf4j.Loggerstatic final Stringprotected Map<String, ClassLoader> A map of plugin class loaders (the key is the 'pluginId').protected PluginDescriptorFinderprotected PluginFactoryprotected PluginLoaderprotected PluginRepositoryprotected Map<String, PluginWrapper> A map of plugins this manager is responsible for (the key is the 'pluginId').static final Stringprotected Pathprotected List<PluginStateListener> The registeredPluginStateListeners.protected PluginStatusProviderprotected List<PluginWrapper> A list with all resolved plugins (resolved dependency).protected RuntimeModeCache value for the runtime mode.protected List<PluginWrapper> A list with started plugins.protected StringThe 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) ConstructsAbstractPluginManagerwith the given plugins root. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPluginStateListener(PluginStateListener listener) private voidcheckPluginId(String pluginId) protected abstract ExtensionFactoryprotected abstract ExtensionFinderprotected abstract PluginDescriptorFinderprotected abstract PluginFactoryprotected abstract PluginLoaderprotected abstract PluginRepositoryprotected PathAdd the possibility to override the plugins root.protected abstract PluginStatusProviderprotected abstract VersionManagerbooleandeletePlugin(String pluginId) Deletes a plugin.booleandisablePlugin(String pluginId) Disables a plugin from being loaded.booleanenablePlugin(String pluginId) Enables a plugin that has previously been disabled.protected voidgetExtensionClasses(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 theClassLoaderfor plugin.protected Map<String, ClassLoader> protected PluginDescriptorFinderprotected PluginFactoryprotected StringgetPluginLabel(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 StringTests for already loaded plugins on given path.protected voidbooleanprotected booleanisPluginDisabled(String pluginId) protected booleanisPluginValid(PluginWrapper pluginWrapper) Check if this plugin is valid (satisfies "requires" param) for a given system version.loadPlugin(Path pluginPath) Load a plugin.protected PluginWrapperloadPluginFromPath(Path pluginPath) voidLoad plugins.voidremovePluginStateListener(PluginStateListener listener) protected voidvoidsetExactVersionAllowed(boolean exactVersionAllowed) Set to true to allow requires expression to be exactly x.y.z.voidsetSystemVersion(String version) Set the system version.startPlugin(String pluginId) Start the specified plugin and its dependencies.voidStart all active plugins.stopPlugin(String pluginId) Stop the specified plugin and it's dependents.private PluginStatestopPlugin(String pluginId, boolean stopDependents) voidStop all active plugins.booleanunloadPlugin(String pluginId) Unload the specified plugin and it's dependents.private booleanunloadPlugin(String pluginId, boolean unloadDependents) protected voidvalidatePluginDescriptor(PluginDescriptor descriptor) Override this to change the validation criteria.whichPlugin(Class<?> clazz) Retrieves thePluginWrapperthat loaded the given class 'clazz'.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 registeredPluginStateListeners. -
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
ConstructsAbstractPluginManagerwith the given plugins root.- Parameters:
pluginsRoot- the root to search for plugins
-
-
Method Details
-
setSystemVersion
Description copied from interface:PluginManagerSet 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:
setSystemVersionin interfacePluginManager- Parameters:
version-
-
getSystemVersion
Description copied from interface:PluginManagerReturns the system version.- Specified by:
getSystemVersionin interfacePluginManager- Returns:
- the system version
-
getPlugins
Returns a copy of plugins.- Specified by:
getPluginsin interfacePluginManager
-
getPlugins
Returns a copy of plugins with that state.- Specified by:
getPluginsin interfacePluginManager
-
getResolvedPlugins
Description copied from interface:PluginManagerRetrieves all resolved plugins (with resolved dependency).- Specified by:
getResolvedPluginsin interfacePluginManager
-
getUnresolvedPlugins
Description copied from interface:PluginManagerRetrieves all unresolved plugins (with unresolved dependency).- Specified by:
getUnresolvedPluginsin interfacePluginManager
-
getStartedPlugins
Description copied from interface:PluginManagerRetrieves all started plugins.- Specified by:
getStartedPluginsin interfacePluginManager
-
getPlugin
Description copied from interface:PluginManagerRetrieves the plugin with this id, or null if the plugin does not exist.- Specified by:
getPluginin 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:PluginManagerLoad a plugin.- Specified by:
loadPluginin 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:
loadPluginsin interfacePluginManager
-
unloadPlugin
Unload the specified plugin and it's dependents.- Specified by:
unloadPluginin interfacePluginManager- Parameters:
pluginId- the unique plugin identifier, specified in its metadata- Returns:
- true if the plugin was unloaded
-
unloadPlugin
-
deletePlugin
Description copied from interface:PluginManagerDeletes a plugin.- Specified by:
deletePluginin 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:
startPluginsin interfacePluginManager
-
startPlugin
Start the specified plugin and its dependencies.- Specified by:
startPluginin interfacePluginManager- Returns:
- the plugin state
-
stopPlugins
public void stopPlugins()Stop all active plugins.- Specified by:
stopPluginsin interfacePluginManager
-
stopPlugin
Stop the specified plugin and it's dependents.- Specified by:
stopPluginin interfacePluginManager- Returns:
- the plugin state
-
stopPlugin
-
checkPluginId
-
disablePlugin
Description copied from interface:PluginManagerDisables a plugin from being loaded.- Specified by:
disablePluginin interfacePluginManager- Parameters:
pluginId- the unique plugin identifier, specified in its metadata- Returns:
- true if plugin is disabled
-
enablePlugin
Description copied from interface:PluginManagerEnables a plugin that has previously been disabled.- Specified by:
enablePluginin interfacePluginManager- Parameters:
pluginId- the unique plugin identifier, specified in its metadata- Returns:
- true if plugin is enabled
-
getPluginClassLoader
Get theClassLoaderfor plugin.- Specified by:
getPluginClassLoaderin interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClassesin interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClassesin interfacePluginManager
-
getExtensionClasses
- Specified by:
getExtensionClassesin interfacePluginManager
-
getExtensions
- Specified by:
getExtensionsin interfacePluginManager
-
getExtensions
- Specified by:
getExtensionsin interfacePluginManager
-
getExtensions
- Specified by:
getExtensionsin interfacePluginManager
-
getExtensionClassNames
- Specified by:
getExtensionClassNamesin interfacePluginManager
-
getExtensionFactory
- Specified by:
getExtensionFactoryin interfacePluginManager
-
getPluginLoader
-
getPluginsRoot
Description copied from interface:PluginManagerGets the path of the folder where plugins are installed.- Specified by:
getPluginsRootin interfacePluginManager- Returns:
- Path of plugins root
-
getRuntimeMode
Description copied from interface:PluginManagerThe runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.- Specified by:
getRuntimeModein interfacePluginManager
-
whichPlugin
Description copied from interface:PluginManagerRetrieves thePluginWrapperthat loaded the given class 'clazz'.- Specified by:
whichPluginin interfacePluginManager
-
addPluginStateListener
- Specified by:
addPluginStateListenerin interfacePluginManager
-
removePluginStateListener
- Specified by:
removePluginStateListenerin 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_NAMEsystem property is defined than this method returns that root. IfgetRuntimeMode()returnsRuntimeMode.DEVELOPMENTthanDEVELOPMENT_PLUGINS_DIRis 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:
getVersionManagerin 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
-