Class PluginManager
- java.lang.Object
-
- org.jivesoftware.openfire.container.PluginManager
-
public class PluginManager extends Object
Manages plugins. Theplugins
directory is monitored for any new plugins, and they are dynamically loaded. An instance of this class can be obtained using:XMPPServer.getInstance().getPluginManager()
These states are defined for plugin management:- installed - the plugin archive file is present in the
plugins
directory. - extracted - the plugin archive file has been extracted.
- loaded - the plugin has (successfully) been initialized.
minServerVersion
definition.- Author:
- Matt Tucker
- See Also:
Plugin
,XMPPServer.getPluginManager()
- installed - the plugin archive file is present in the
-
-
Constructor Summary
Constructors Constructor Description PluginManager(File pluginDir)
Constructs a new plugin manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addPluginListener(PluginListener listener)
Registers a PluginListener, which will now start receiving events regarding plugin creation and destruction.void
addPluginManagerListener(PluginManagerListener listener)
Registers a PluginManagerListener, which will now start receiving events regarding plugin management.void
deletePlugin(String pluginName)
Delete a plugin, which removes the plugin.jar/war file after which the plugin is unloaded.String
getAuthor(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getAuthor(Plugin)
.String
getCanonicalName(Plugin plugin)
Returns the canonical name for a loaded plugin.String
getDatabaseKey(Plugin plugin)
Deprecated.int
getDatabaseVersion(Plugin plugin)
Deprecated.String
getDescription(Plugin plugin)
Deprecated.PluginDevEnvironment
getDevEnvironment(Plugin plugin)
Returns a plugin's dev environment if development mode is enabled for the plugin.String
getLicense(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getLicense(Plugin)
.PluginMetadata
getMetadata(String canonicalName)
Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded.Map<String,PluginMetadata>
getMetadataExtractedPlugins()
Returns metadata for all extracted plugins, mapped by their canonical name.String
getMinServerVersion(Plugin plugin)
Deprecated.String
getName(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getName(Plugin)
.Plugin
getPlugin(String canonicalName)
Deprecated.in Openfire 4.4 in favour ofgetPluginByName(String)
Optional<Plugin>
getPluginByName(String pluginName)
Returns a loaded plugin by the name contained in the plugin.xml <name/> tag, ignoring case.PluginClassLoader
getPluginClassloader(Plugin plugin)
Returns the classloader of a plugin.File
getPluginDirectory(Plugin plugin)
Deprecated.Use #getPluginPath() instead.Path
getPluginPath(Plugin plugin)
Returns the plugin's directory.Collection<Plugin>
getPlugins()
Returns a Collection of all loaded plugins.Path
getPluginsDirectory()
Returns the directory that contains all plugins.String
getVersion(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getVersion(Plugin)
.boolean
installPlugin(InputStream in, String pluginFilename)
Installs or updates an existing plugin.boolean
isExecuted()
Returns true if at least one attempt to load plugins has been done.boolean
isExtracted(String canonicalName)
Returns true if the plugin by the specified name is extracted.boolean
isInstalled(String canonicalName)
Returns true if the plugin by the specified name is installed.boolean
isLoaded(String canonicalName)
Returns true if the plugin by the specified name is loaded.boolean
isMonitorTaskRunning()
Class
loadClass(Plugin plugin, String className)
Loads a class from the classloader of a plugin.boolean
reloadPlugin(String pluginName)
void
removePluginListener(PluginListener listener)
Deregisters a PluginListener, which will no longer receive events.void
removePluginManagerListener(PluginManagerListener listener)
Deregisters a PluginManagerListener, which will no longer receive events.void
shutdown()
Shuts down all running plugins.void
start()
Starts plugins and the plugin monitoring service.static boolean
validMagicNumbers(BufferedInputStream bin)
Verifies that the first few bytes of the input stream correspond to any of the known 'magic numbers' that are known to represent a JAR archive.
-
-
-
Constructor Detail
-
PluginManager
public PluginManager(File pluginDir)
Constructs a new plugin manager.- Parameters:
pluginDir
- the directory containing all Openfire plugins, typically OPENFIRE_HOME/plugins/
-
-
Method Detail
-
start
public void start()
Starts plugins and the plugin monitoring service.
-
shutdown
public void shutdown()
Shuts down all running plugins.
-
getPluginsDirectory
public Path getPluginsDirectory()
Returns the directory that contains all plugins. This typically is OPENFIRE_HOME/plugins.- Returns:
- The directory that contains all plugins.
-
installPlugin
public boolean installPlugin(InputStream in, String pluginFilename)
Installs or updates an existing plugin.- Parameters:
in
- the input stream that contains the new plugin definition.pluginFilename
- the filename of the plugin to create or update.- Returns:
- true if the plugin was successfully installed or updated.
-
isInstalled
public boolean isInstalled(String canonicalName)
Returns true if the plugin by the specified name is installed. Specifically, this checks if the plugin archive file is present in theplugins
directory. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersion
definition.- Parameters:
canonicalName
- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is installed, otherwise false.
-
isExtracted
public boolean isExtracted(String canonicalName)
Returns true if the plugin by the specified name is extracted. Specifically, this checks if theplugins
directory contains a subdirectory that matches the canonical name of the plugin. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersion
definition.- Parameters:
canonicalName
- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is extracted, otherwise false.
-
isLoaded
public boolean isLoaded(String canonicalName)
Returns true if the plugin by the specified name is loaded. Specifically, this checks if an instance was created for the plugin class file. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersion
definition.- Parameters:
canonicalName
- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is extracted, otherwise false.
-
getMetadataExtractedPlugins
public Map<String,PluginMetadata> getMetadataExtractedPlugins()
Returns metadata for all extracted plugins, mapped by their canonical name. The collection is alphabetically sorted, by plugin name. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersion
definition.- Returns:
- A collection of metadata (possibly empty, never null).
-
getMetadata
public PluginMetadata getMetadata(String canonicalName)
Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersion
definition.- Parameters:
canonicalName
- the canonical name (lower case JAR/WAR file without exception) of the plugin- Returns:
- A collection of metadata (possibly empty, never null).
-
getPlugins
public Collection<Plugin> getPlugins()
Returns a Collection of all loaded plugins. The returned collection will not include plugins that have been downloaded, but not loaded.- Returns:
- a Collection of all loaded plugins.
-
getCanonicalName
public String getCanonicalName(Plugin plugin)
Returns the canonical name for a loaded plugin.- Parameters:
plugin
- A plugin (cannot be null).- Returns:
- The canonical name for the plugin (never null).
-
getPlugin
@Deprecated public Plugin getPlugin(String canonicalName)
Deprecated.in Openfire 4.4 in favour ofgetPluginByName(String)
Returns a loaded plugin by its canonical name ornull
if a plugin with that name does not exist. The canonical name is the lowercase-name of the plugin archive, without the file extension. For example: "broadcast".- Parameters:
canonicalName
- the name of the plugin.- Returns:
- the plugin.
-
getPluginByName
public Optional<Plugin> getPluginByName(String pluginName)
Returns a loaded plugin by the name contained in the plugin.xml <name/> tag, ignoring case. For example: "broadcast".- Parameters:
pluginName
- the name of the plugin.- Returns:
- the plugin, if found
- Since:
- Openfire 4.4
-
getPluginDirectory
@Deprecated public File getPluginDirectory(Plugin plugin)
Deprecated.Use #getPluginPath() instead.- Parameters:
plugin
- the plugin to get the directory for- Returns:
- the plugin's directory
-
getPluginPath
public Path getPluginPath(Plugin plugin)
Returns the plugin's directory.- Parameters:
plugin
- the plugin.- Returns:
- the plugin's directory.
- Since:
- Openfire 4.1
-
isExecuted
public boolean isExecuted()
Returns true if at least one attempt to load plugins has been done. A true value does not mean that available plugins have been loaded nor that plugins to be added in the future are already loaded. :)- Returns:
- true if at least one attempt to load plugins has been done.
-
deletePlugin
public void deletePlugin(String pluginName)
Delete a plugin, which removes the plugin.jar/war file after which the plugin is unloaded.- Parameters:
pluginName
- the plugin to delete
-
reloadPlugin
public boolean reloadPlugin(String pluginName)
-
loadClass
public Class loadClass(Plugin plugin, String className) throws ClassNotFoundException
Loads a class from the classloader of a plugin.- Parameters:
plugin
- the plugin.className
- the name of the class to load.- Returns:
- the class.
- Throws:
ClassNotFoundException
- if the class was not found.
-
getDevEnvironment
public PluginDevEnvironment getDevEnvironment(Plugin plugin)
Returns a plugin's dev environment if development mode is enabled for the plugin.- Parameters:
plugin
- the plugin.- Returns:
- the plugin dev environment, or
null
if development mode is not enabled for the plugin.
-
getName
@Deprecated public String getName(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getName(Plugin)
.- Parameters:
plugin
- the plugin to get the name for- Returns:
- the name of the plugin, as defined in the plugin.xml
-
getDescription
@Deprecated public String getDescription(Plugin plugin)
Deprecated.- Parameters:
plugin
- the plugin to get the description for- Returns:
- the description of the plugin
-
getAuthor
@Deprecated public String getAuthor(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getAuthor(Plugin)
.- Parameters:
plugin
- the plugin to get the author for- Returns:
- the author of the plugin
-
getVersion
@Deprecated public String getVersion(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getVersion(Plugin)
.- Parameters:
plugin
- the plugin to get the version for- Returns:
- the version of the plugin
-
getMinServerVersion
@Deprecated public String getMinServerVersion(Plugin plugin)
Deprecated.- Parameters:
plugin
- the plugin to get the minimum server version for- Returns:
- the minimum server version for the plugin
-
getDatabaseKey
@Deprecated public String getDatabaseKey(Plugin plugin)
Deprecated.- Parameters:
plugin
- the plugin to get the database key for- Returns:
- the database key for the plugin
-
getDatabaseVersion
@Deprecated public int getDatabaseVersion(Plugin plugin)
Deprecated.- Parameters:
plugin
- the plugin to get the database version for- Returns:
- the database version for the plugin
-
getLicense
@Deprecated public String getLicense(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getLicense(Plugin)
.- Parameters:
plugin
- the plugin to get the licence for- Returns:
- the licence for the plugin
-
getPluginClassloader
public PluginClassLoader getPluginClassloader(Plugin plugin)
Returns the classloader of a plugin.- Parameters:
plugin
- the plugin.- Returns:
- the classloader of the plugin.
-
validMagicNumbers
public static boolean validMagicNumbers(BufferedInputStream bin) throws IOException
Verifies that the first few bytes of the input stream correspond to any of the known 'magic numbers' that are known to represent a JAR archive. This method uses the mark/reset functionality of InputStream. This ensures that the input stream is reset back to its original position after execution of this method.- Parameters:
bin
- The input to read (cannot be null).- Returns:
- true if the stream first few bytes are equal to any of the known magic number sequences, otherwise false.
- Throws:
IOException
-
addPluginListener
public void addPluginListener(PluginListener listener)
Registers a PluginListener, which will now start receiving events regarding plugin creation and destruction. When the listener was already registered, this method will have no effect.- Parameters:
listener
- the listener to be notified (cannot be null).
-
removePluginListener
public void removePluginListener(PluginListener listener)
Deregisters a PluginListener, which will no longer receive events. When the listener was never added, this method will have no effect.- Parameters:
listener
- the listener to be removed (cannot be null).
-
addPluginManagerListener
public void addPluginManagerListener(PluginManagerListener listener)
Registers a PluginManagerListener, which will now start receiving events regarding plugin management.- Parameters:
listener
- the listener to be notified (cannot be null).
-
removePluginManagerListener
public void removePluginManagerListener(PluginManagerListener listener)
Deregisters a PluginManagerListener, which will no longer receive events. When the listener was never added, this method will have no effect.- Parameters:
listener
- the listener to be notified (cannot be null).
-
isMonitorTaskRunning
public boolean isMonitorTaskRunning()
-
-