Package io.jenkins.plugins.util
Class JenkinsFacade
java.lang.Object
io.jenkins.plugins.util.JenkinsFacade
- All Implemented Interfaces:
Serializable
Facade to Jenkins server. Encapsulates all calls to the running Jenkins server so that tests can replace this facade
with a stub.
- Author:
- Ullrich Hafner
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAbsoluteUrl(String... urlElements) Returns an absolute URL for the specified url elements: e.g., creates the sequence ${rootUrl}/element1/element2.Returns the full names of all available jobs.Returns all available jobs.Gets abuildby the full ID.getDescriptor(Class<? extends Describable> describableType) Gets theDescriptorthat corresponds to the givenDescribabletype.getDescriptorOrDie(Class<? extends Describable> describableType) Works just likegetDescriptor(Class)but don't take no for an answer.<T extends Describable<T>,D extends Descriptor<T>>
DescriptorExtensionList<T,D> getDescriptorsFor(Class<T> describableType) Returns the discovered instances for the given descriptor type.<T> List<T>getExtensionsFor(Class<T> extensionType) Returns the discovered instances for the given extension type.getFullNameOf(Job<?, ?> job) Returns the full name of the specified job.getImagePath(String icon) Returns the absolute URL for the specified icon.Gets aJobby its full name.Returns the unique identifier of this Jenkins that has been historically used to identify this Jenkins to the outside world.getSymbol(SymbolRequest symbol) Returns a symbol that can be embedded in a page.booleanhasPermission(Permission permission) Checks if the current security principal has this permission.booleanhasPermission(Permission permission, AbstractItem item) Checks if the current security principal has this permission for the specified item.booleanhasPermission(Permission permission, Job<?, ?> project) Checks if the current security principal has this permission for the specified project.booleanhasPermission(Permission permission, View view) Checks if the current security principal has this permission for the specified view.booleanhasPermission(Permission permission, AccessControlled accessControlled) Checks if the current security principal has this permission for the specified access controlled object.booleanisPluginInstalled(String pluginId) Returns whether the plugin with the specified ID (short name, artifact ID) is installed.
-
Constructor Details
-
JenkinsFacade
public JenkinsFacade()
-
-
Method Details
-
getExtensionsFor
Returns the discovered instances for the given extension type.- Type Parameters:
T- type of the extension- Parameters:
extensionType- The base type that represents the extension point. NormallyExtensionPointsubtype but that's not a hard requirement.- Returns:
- the discovered instances - might be an empty list
-
getDescriptorsFor
public <T extends Describable<T>,D extends Descriptor<T>> DescriptorExtensionList<T,D> getDescriptorsFor(Class<T> describableType) Returns the discovered instances for the given descriptor type.- Type Parameters:
T- type of the describableD- type of the descriptor- Parameters:
describableType- the base type that represents the descriptor of the describable- Returns:
- the discovered instances - might be an empty list
-
getDescriptorOrDie
Works just likegetDescriptor(Class)but don't take no for an answer.- Parameters:
describableType- the base type that represents the descriptor of the describable- Returns:
- the discovered descriptor
- Throws:
AssertionError- If the descriptor is missing.
-
getDescriptor
Gets theDescriptorthat corresponds to the givenDescribabletype.If you have an instance of
typeand callDescribable.getDescriptor(), you'll get the same instance that this method returns.- Parameters:
describableType- the base type that represents the descriptor of the describable- Returns:
- the discovered descriptor, or
nullif no such descriptor has been found
-
hasPermission
Checks if the current security principal has this permission.- Parameters:
permission- the permission to check for- Returns:
falseif the user doesn't have the permission
-
hasPermission
Checks if the current security principal has this permission for the specified project.- Parameters:
permission- the permission to check forproject- the project to check the permissions for- Returns:
falseif the user doesn't have the permission
-
hasPermission
Checks if the current security principal has this permission for the specified view.- Parameters:
permission- the permission to check forview- the view to check the permissions for- Returns:
falseif the user doesn't have the permission
-
hasPermission
public boolean hasPermission(Permission permission, @CheckForNull AccessControlled accessControlled) Checks if the current security principal has this permission for the specified access controlled object.- Parameters:
permission- the permission to check foraccessControlled- the access controlled object to check the permissions for- Returns:
falseif the user doesn't have the permission
-
hasPermission
Checks if the current security principal has this permission for the specified item.- Parameters:
permission- the permission to check foritem- the item to check the permissions for- Returns:
falseif the user doesn't have the permission
-
getJob
Gets aJobby its full name. Full names are like path names, where each name ofItemis combined by '/'.- Parameters:
name- the full name of the job- Returns:
- the selected job, if it exists under the given full name and if it is accessible
-
getBuild
Gets abuildby the full ID.- Parameters:
id- the ID of the build- Returns:
- the selected build, if it exists with the given ID and if it is accessible
-
getSymbol
Returns a symbol that can be embedded in a page. The returned String is a well formatted HTML snippet that can be embedded in a page.- Parameters:
symbol- the symbol- Returns:
- the symbol
-
getImagePath
Returns the absolute URL for the specified icon.- Parameters:
icon- the icon URL- Returns:
- the absolute URL
-
getAbsoluteUrl
Returns an absolute URL for the specified url elements: e.g., creates the sequence ${rootUrl}/element1/element2.- Parameters:
urlElements- the url elements- Returns:
- the absolute URL
-
getAllJobNames
Returns the full names of all available jobs. The full name is given byAbstractItem.getFullName().- Returns:
- the full names of all jobs
-
getAllJobs
Returns all available jobs.- Returns:
- all jobs
-
getFullNameOf
Returns the full name of the specified job.- Parameters:
job- the job to get the name for- Returns:
- the full name
-
isPluginInstalled
Returns whether the plugin with the specified ID (short name, artifact ID) is installed.- Parameters:
pluginId- the ID of the plugin- Returns:
trueif the plugin is installed,falseif not
-
getLegacyInstanceId
Returns the unique identifier of this Jenkins that has been historically used to identify this Jenkins to the outside world.- Returns:
- legacy instance id of this Jenkins
-