Package hudson
Class PluginManager
java.lang.Object
hudson.model.AbstractModelObject
hudson.PluginManager
- All Implemented Interfaces:
ModelObject
,SearchableModelObject
,SearchItem
,OnMaster
,org.kohsuke.stapler.StaplerOverridable
,org.kohsuke.stapler.StaplerProxy
- Direct Known Subclasses:
LocalPluginManager
@ExportedBean
public abstract class PluginManager
extends AbstractModelObject
implements OnMaster, org.kohsuke.stapler.StaplerOverridable, org.kohsuke.stapler.StaplerProxy
Manages
PluginWrapper
s.
Setting default Plugin Managers. The default plugin manager in Jenkins
can be replaced by defining a
System Property (hudson.PluginManager.className
). See createDefault(Jenkins)
.
This className should be available on early startup, so it cannot come only from a library
(e.g. Jenkins module or Extra library dependency in the WAR file project).
Plugins cannot be used for such purpose.
In order to be correctly instantiated, the class definition must have at least one constructor with the same
signature as the following ones:
File
argument refers to the Jenkins home directory.- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Remembers why a plugin failed to deploy.static final class
static final class
AdministrativeMonitor
that checks if there are any plugins with cycle dependencies.static final class
AdministrativeMonitor
that checks if there are any plugins that are deprecated.static final class
AdministrativeMonitor
that informs the administrator about a required plugin update.static final class
ClassLoader
that can see all plugins.static class
This allows "Update Center" to live at the URL/pluginManager/updates/
in addition to its/updateCenter/
URL which is provided byJenkins.getUpdateCenter()
. -
Field Summary
Modifier and TypeFieldDescriptionprotected final List<PluginWrapper>
All active plugins, topologically sorted so that when X depends on Y, Y appears in the list before X does.static final Permission
Deprecated.final jakarta.servlet.ServletContext
Deprecated.as of 1.355PluginManager
can now live longer thanJenkins
instance, so useHudson.getInstance().servletContext
instead.static final String
Custom plugin manager system property or context param.protected final List<PluginManager.FailedPlugin>
static boolean
protected final List<PluginWrapper>
All discovered plugins.boolean
Once plugin is uploaded, this flag becomes true.final File
Plug-in root directory.static boolean
Escape hatch for StaplerProxy-based access controlfinal ClassLoader
ClassLoader
that can load all the publicly visible classes from plugins (and including the classloader that loads Hudson itself.)static final Permission
Deprecated.in Jenkins 2.222 useJenkins.ADMINISTER
instead -
Constructor Summary
ModifierConstructorDescriptionprotected
PluginManager
(jakarta.servlet.ServletContext context, File rootDir) protected
PluginManager
(javax.servlet.ServletContext context, File rootDir) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
addDependencies
(URL hpiResUrl, String fromPath, Set<URL> dependencySet) protected void
copyBundledPlugin
(URL src, String fileName) Copies the plugin from the given URL to the given destination.static PluginManager
createDefault
(Jenkins jenkins) Creates thePluginManager
to use if no one is provided to aJenkins
object.protected PluginStrategy
Creates a hudson.PluginStrategy, looking at the corresponding system property.disablePlugins
(PluginWrapper.PluginDisableStrategy strategy, List<String> plugins) Disable a list of plugins using a strategy for their dependents plugins.<T> Collection<Class<? extends T>>
Deprecated.UseServiceLoader
instead, or (more commonly)ExtensionList
.doCheckPluginUrl
(org.kohsuke.stapler.StaplerRequest2 request, String value) doCheckUpdateSiteUrl
(org.kohsuke.stapler.StaplerRequest2 request, String value) org.kohsuke.stapler.HttpResponse
void
doInstall
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Performs the installation of the plugins.org.kohsuke.stapler.HttpResponse
doInstallNecessaryPlugins
(org.kohsuke.stapler.StaplerRequest2 req) RunsprevalidateConfig(java.io.InputStream)
on posted XML and redirects to theUpdateCenter
.org.kohsuke.stapler.HttpResponse
doInstallPlugins
(org.kohsuke.stapler.StaplerRequest2 req) Installs a list of plugins from a JSON POST.void
Called to progress status beyond installing plugins, e.g.org.kohsuke.stapler.HttpResponse
Get the list of all plugins - available and installed.org.kohsuke.stapler.HttpResponse
doPluginsSearch
(String query, Integer limit) net.sf.json.JSONArray
doPrevalidateConfig
(org.kohsuke.stapler.StaplerRequest2 req) LikedoInstallNecessaryPlugins(StaplerRequest2)
but only checks if everything is installed or if some plugins need updates or installation.org.kohsuke.stapler.HttpResponse
doProxyConfigure
(org.kohsuke.stapler.StaplerRequest2 req) org.kohsuke.stapler.HttpResponse
doSiteConfigure
(String site) Bare-minimum configuration mechanism to change the update center.org.kohsuke.stapler.HttpResponse
doUpdateSources
(org.kohsuke.stapler.StaplerRequest2 req) org.kohsuke.stapler.HttpResponse
doUploadPlugin
(org.kohsuke.stapler.StaplerRequest req) Deprecated.org.kohsuke.stapler.HttpResponse
doUploadPlugin
(org.kohsuke.stapler.StaplerRequest2 req) Uploads a plugin.void
dynamicLoad
(File arc) TODO: revisit where/how to expose this.void
dynamicLoad
(File arc, boolean removeExisting, List<PluginWrapper> batch) Try the dynamicLoad, removeExisting to attempt to dynamic load disabled pluginsgetApi()
getBundledPluginManifest
(String shortName) Deprecated.removed without replacementprotected String
Defines the location of the detached plugins in the WAR.Returns the last error raised during the update sites checking.Find all registered overrides (intended to allow overriding/adding views)Get the plugin instance that implements a specific class, use to find your plugin singleton.Get the plugin instance with the given short name.All discovered plugins.getPlugins
(Class<? extends Plugin> pluginSuperclass) Get the plugin instances that extend a specific class, use to find similar plugins.Returns the URL of this item relative to the parentSearchItem
.If non-null, the base directory for all exploded .hpi/.jpi plugins.boolean
boolean
hasAdoptThisPluginLabel
(PluginWrapper plugin) protected String
org.jvnet.hudson.reactor.TaskBuilder
initTasks
(InitStrategy initStrategy) Called immediately after the construction.install
(Collection<String> plugins, boolean dynamicLoad) Performs the installation of the plugins.boolean
isMetaLabel
(String label) static boolean
isNonMetaLabel
(String label) boolean
Returns true if any new plugin was added.protected abstract Collection<String>
If the war file has any "/WEB-INF/plugins/[*.jpi | *.hpi]", extract them into the plugin directory.protected void
Load detached plugins and their dependencies.loadPluginsFromWar
(String fromPath) loadPluginsFromWar
(String fromPath, FilenameFilter filter) parseRequestedPlugins
(InputStream configXml) Parses configuration XML files and picks up references to XML files.prevalidateConfig
(InputStream configXml) Prepares plugins for some expected XML configuration.void
void
start
(List<PluginWrapper> plugins) void
stop()
Orderly terminates all the plugins.unscientific
(double d) whichPlugin
(Class c) Return thePluginWrapper
that loaded the given class 'c'.Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError, sendError, sendError, sendError
-
Field Details
-
CUSTOM_PLUGIN_MANAGER
Custom plugin manager system property or context param. -
plugins
All discovered plugins. -
activePlugins
All active plugins, topologically sorted so that when X depends on Y, Y appears in the list before X does. -
failedPlugins
-
rootDir
Plug-in root directory. -
context
Deprecated.as of 1.355PluginManager
can now live longer thanJenkins
instance, so useHudson.getInstance().servletContext
instead. -
uberClassLoader
ClassLoader
that can load all the publicly visible classes from plugins (and including the classloader that loads Hudson itself.) -
pluginUploaded
public volatile boolean pluginUploadedOnce plugin is uploaded, this flag becomes true. This is used to report a message that Jenkins needs to be restarted for new plugins to take effect. -
FAST_LOOKUP
public static boolean FAST_LOOKUP -
UPLOAD_PLUGINS
Deprecated.in Jenkins 2.222 useJenkins.ADMINISTER
instead -
CONFIGURE_UPDATECENTER
Deprecated.in Jenkins 2.222 useJenkins.ADMINISTER
instead -
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECKEscape hatch for StaplerProxy-based access control
-
-
Constructor Details
-
PluginManager
- Since:
- 2.475
-
PluginManager
Deprecated.
-
-
Method Details
-
createDefault
Creates thePluginManager
to use if no one is provided to aJenkins
object. This method will be called after creation ofJenkins
object, but before it is fully initialized.- Parameters:
jenkins
- Jenkins Instance.- Returns:
- Plugin manager to use. If no custom class is configured or in case of any error, the default
LocalPluginManager
is returned.
-
getApi
-
getWorkDir
If non-null, the base directory for all exploded .hpi/.jpi plugins.- Returns:
- the base directory for all exploded .hpi/.jpi plugins or
null
to leave this up to the strategy.
-
getOverrides
Find all registered overrides (intended to allow overriding/adding views)- Specified by:
getOverrides
in interfaceorg.kohsuke.stapler.StaplerOverridable
- Returns:
- List of extensions
- Since:
- 1.627
-
initTasks
Called immediately after the construction. This is a separate method so that code executed from here will see a valid value inJenkins.pluginManager
. -
getDetachedLocation
Defines the location of the detached plugins in the WAR.- Returns:
- by default,
/WEB-INF/detached-plugins
- Since:
- 2.377
-
loadPluginsFromWar
-
loadPluginsFromWar
@NonNull protected Set<String> loadPluginsFromWar(@NonNull String fromPath, @CheckForNull FilenameFilter filter) -
addDependencies
protected static void addDependencies(URL hpiResUrl, String fromPath, Set<URL> dependencySet) throws URISyntaxException, MalformedURLException -
loadDetachedPlugins
protected void loadDetachedPlugins()Load detached plugins and their dependencies.Only loads plugins that:
- Have been detached since the last running version.
- Are already installed and need to be upgraded. This can be the case if this Jenkins install has been running since before plugins were "unbundled".
- Are dependencies of one of the above e.g. script-security is not one of the detached plugins but it must be loaded if matrix-project is loaded.
-
getBundledPluginManifest
Deprecated.removed without replacementReturns the manifest of a bundled but not-extracted plugin. -
dynamicLoad
public void dynamicLoad(File arc) throws IOException, InterruptedException, RestartRequiredException TODO: revisit where/how to expose this. This is an experiment. -
dynamicLoad
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void dynamicLoad(File arc, boolean removeExisting, @CheckForNull List<PluginWrapper> batch) throws IOException, InterruptedException, RestartRequiredException Try the dynamicLoad, removeExisting to attempt to dynamic load disabled plugins -
start
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void start(List<PluginWrapper> plugins) throws Exception - Throws:
Exception
-
resolveDependentPlugins
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void resolveDependentPlugins() -
loadBundledPlugins
If the war file has any "/WEB-INF/plugins/[*.jpi | *.hpi]", extract them into the plugin directory.- Returns:
- File names of the bundled plugins. Normally empty (not to be confused with
loadDetachedPlugins()
) but OEM WARs may have some. - Throws:
Exception
- Any exception will be reported and halt the startup.
-
copyBundledPlugin
Copies the plugin from the given URL to the given destination. Despite the name, this is used also fromloadDetachedPlugins()
. Includes a reasonable up-to-date check. A convenience method to be used byloadBundledPlugins()
.- Parameters:
fileName
- likeabc.jpi
- Throws:
IOException
-
createPluginStrategy
Creates a hudson.PluginStrategy, looking at the corresponding system property. -
getPluginStrategy
-
isPluginUploaded
public boolean isPluginUploaded()Returns true if any new plugin was added. -
getPlugins
All discovered plugins. -
getPluginsSortedByTitle
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public List<PluginWrapper> getPluginsSortedByTitle() -
getFailedPlugins
-
getPlugin
Get the plugin instance with the given short name.- Parameters:
shortName
- the short name of the plugin- Returns:
- The plugin singleton or
null
if a plugin with the given short name does not exist. The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session. UsePluginWrapper.isActive()
to check it.
-
getPlugin
Get the plugin instance that implements a specific class, use to find your plugin singleton. Note: beware the classloader fun.- Parameters:
pluginClazz
- The class that your plugin implements.- Returns:
- The plugin singleton or
null
if for some reason the plugin is not loaded. The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session. UsePlugin.getWrapper()
and thenPluginWrapper.isActive()
to check it.
-
getPlugins
Get the plugin instances that extend a specific class, use to find similar plugins. Note: beware the classloader fun.- Parameters:
pluginSuperclass
- The class that your plugin is derived from.- Returns:
- The list of plugins implementing the specified class.
-
getDisplayName
- Specified by:
getDisplayName
in interfaceModelObject
-
getSearchUrl
Description copied from interface:SearchItem
Returns the URL of this item relative to the parentSearchItem
.- Specified by:
getSearchUrl
in interfaceSearchItem
- Returns:
- URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Jenkins.)
-
discover
Deprecated.UseServiceLoader
instead, or (more commonly)ExtensionList
.Discover all the service provider implementations of the given class, viaMETA-INF/services
. -
whichPlugin
Return thePluginWrapper
that loaded the given class 'c'.- Since:
- 1.402.
-
stop
public void stop()Orderly terminates all the plugins. -
isNonMetaLabel
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean isNonMetaLabel(String label) -
getUpdates
-
doPluginsSearch
-
doPlugins
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doPlugins()Get the list of all plugins - available and installed.- Returns:
- The list of all plugins - available and installed.
-
doUpdateSources
public org.kohsuke.stapler.HttpResponse doUpdateSources(org.kohsuke.stapler.StaplerRequest2 req) throws IOException - Throws:
IOException
-
doInstallPluginsDone
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public void doInstallPluginsDone()Called to progress status beyond installing plugins, e.g. if there were failures that prevented installation from naturally proceeding -
doInstall
public void doInstall(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Performs the installation of the plugins.- Throws:
IOException
jakarta.servlet.ServletException
-
doInstallPlugins
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doInstallPlugins(org.kohsuke.stapler.StaplerRequest2 req) throws IOException Installs a list of plugins from a JSON POST.- Parameters:
req
- The request object.- Returns:
- A JSON response that includes a "correlationId" in the "data" element.
That "correlationId" can then be used in calls to
UpdateCenter.doInstallStatus(org.kohsuke.stapler.StaplerRequest2)
. - Throws:
IOException
- Error reading JSON payload fro request.
-
install
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public List<Future<UpdateCenter.UpdateCenterJob>> install(@NonNull Collection<String> plugins, boolean dynamicLoad) Performs the installation of the plugins.- Parameters:
plugins
- The collection of plugins to install.dynamicLoad
- If true, the plugin will be dynamically loaded into this Jenkins. If false, the plugin will only take effect after the reboot. SeeUpdateCenter.isRestartRequiredForCompletion()
- Returns:
- The install job list.
- Since:
- 2.0
-
doSiteConfigure
public org.kohsuke.stapler.HttpResponse doSiteConfigure(@QueryParameter String site) throws IOException Bare-minimum configuration mechanism to change the update center.- Throws:
IOException
-
doProxyConfigure
@POST public org.kohsuke.stapler.HttpResponse doProxyConfigure(org.kohsuke.stapler.StaplerRequest2 req) throws IOException, jakarta.servlet.ServletException - Throws:
IOException
jakarta.servlet.ServletException
-
doUploadPlugin
public org.kohsuke.stapler.HttpResponse doUploadPlugin(org.kohsuke.stapler.StaplerRequest2 req) throws IOException, jakarta.servlet.ServletException Uploads a plugin.- Throws:
IOException
jakarta.servlet.ServletException
-
doUploadPlugin
@Deprecated @StaplerNotDispatchable public org.kohsuke.stapler.HttpResponse doUploadPlugin(org.kohsuke.stapler.StaplerRequest req) throws IOException, javax.servlet.ServletException Deprecated.- Throws:
IOException
javax.servlet.ServletException
-
doCheckPluginUrl
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public FormValidation doCheckPluginUrl(org.kohsuke.stapler.StaplerRequest2 request, @QueryParameter String value) throws IOException - Throws:
IOException
-
doCheckUpdateSiteUrl
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public FormValidation doCheckUpdateSiteUrl(org.kohsuke.stapler.StaplerRequest2 request, @QueryParameter String value) throws InterruptedException - Throws:
InterruptedException
-
doCheckUpdatesServer
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.kohsuke.stapler.HttpResponse doCheckUpdatesServer() throws IOException- Throws:
IOException
-
getLastErrorCheckUpdateCenters
Returns the last error raised during the update sites checking.- Returns:
- the last error message
-
identifyPluginShortName
-
getProxyDescriptor
-
prevalidateConfig
public List<Future<UpdateCenter.UpdateCenterJob>> prevalidateConfig(InputStream configXml) throws IOException Prepares plugins for some expected XML configuration. If the configuration (typically a job’sconfig.xml
) needs some plugins to be installed (or updated), those jobs will be triggered. Plugins are dynamically loaded whenever possible. RequiresJenkins.ADMINISTER
.- Parameters:
configXml
- configuration that might be uploaded- Returns:
- an empty list if all is well, else a list of submitted jobs which must be completed before this configuration can be fully read
- Throws:
IOException
- if loading or parsing the configuration failed- Since:
- 1.483
- See Also:
-
doPrevalidateConfig
public net.sf.json.JSONArray doPrevalidateConfig(org.kohsuke.stapler.StaplerRequest2 req) throws IOException LikedoInstallNecessaryPlugins(StaplerRequest2)
but only checks if everything is installed or if some plugins need updates or installation. This method runs without side-effect. I'm still requiring the ADMINISTER permission since XML file can contain various external references and we don't configure parsers properly against that.- Throws:
IOException
- Since:
- 1.483
-
doInstallNecessaryPlugins
public org.kohsuke.stapler.HttpResponse doInstallNecessaryPlugins(org.kohsuke.stapler.StaplerRequest2 req) throws IOException RunsprevalidateConfig(java.io.InputStream)
on posted XML and redirects to theUpdateCenter
.- Throws:
IOException
- Since:
- 1.483
-
parseRequestedPlugins
Parses configuration XML files and picks up references to XML files.- Throws:
IOException
-
createCache
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public PluginManager.MetadataCache createCache() -
disablePlugins
@NonNull public List<PluginWrapper.PluginDisableResult> disablePlugins(@NonNull PluginWrapper.PluginDisableStrategy strategy, @NonNull List<String> plugins) throws IOException Disable a list of plugins using a strategy for their dependents plugins.- Parameters:
strategy
- the strategy regarding how the dependent plugins are processedplugins
- the list of plugins- Returns:
- the list of results for every plugin and their dependent plugins.
- Throws:
IOException
- seePluginWrapper.disable()
-
unscientific
-
getTarget
- Specified by:
getTarget
in interfaceorg.kohsuke.stapler.StaplerProxy
-
isMetaLabel
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public boolean isMetaLabel(String label) -
hasAdoptThisPluginLabel
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public boolean hasAdoptThisPluginLabel(UpdateSite.Plugin plugin) -
hasAdoptThisPluginLabel
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public boolean hasAdoptThisPluginLabel(PluginWrapper plugin)
-
Jenkins.ADMINISTER
instead