Class JenkinsFacade

java.lang.Object
io.jenkins.plugins.util.JenkinsFacade
All Implemented Interfaces:
Serializable

public class JenkinsFacade extends Object implements 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 Details

    • JenkinsFacade

      public JenkinsFacade()
  • Method Details

    • getExtensionsFor

      public <T> List<T> getExtensionsFor(Class<T> extensionType)
      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. Normally ExtensionPoint subtype 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 describable
      D - 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

      public Descriptor getDescriptorOrDie(Class<? extends Describable> describableType)
      Works just like getDescriptor(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

      @CheckForNull public Descriptor getDescriptor(Class<? extends Describable> describableType)
      Gets the Descriptor that corresponds to the given Describable type.

      If you have an instance of type and call Describable.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 null if no such descriptor has been found
    • hasPermission

      public boolean hasPermission(Permission permission)
      Checks if the current security principal has this permission.
      Parameters:
      permission - the permission to check for
      Returns:
      false if the user doesn't have the permission
    • hasPermission

      public boolean hasPermission(Permission permission, @CheckForNull Job<?,?> project)
      Checks if the current security principal has this permission for the specified project.
      Parameters:
      permission - the permission to check for
      project - the project to check the permissions for
      Returns:
      false if the user doesn't have the permission
    • hasPermission

      public boolean hasPermission(Permission permission, @CheckForNull View view)
      Checks if the current security principal has this permission for the specified view.
      Parameters:
      permission - the permission to check for
      view - the view to check the permissions for
      Returns:
      false if 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 for
      accessControlled - the access controlled object to check the permissions for
      Returns:
      false if the user doesn't have the permission
    • hasPermission

      public boolean hasPermission(Permission permission, @CheckForNull AbstractItem item)
      Checks if the current security principal has this permission for the specified item.
      Parameters:
      permission - the permission to check for
      item - the item to check the permissions for
      Returns:
      false if the user doesn't have the permission
    • getJob

      public Optional<Job<?,?>> getJob(String name)
      Gets a Job by its full name. Full names are like path names, where each name of Item is 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

      public Optional<Run<?,?>> getBuild(String id)
      Gets a build by 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
    • getImagePath

      @Deprecated public String getImagePath(BallColor color)
      Deprecated.
      BallColor should not be used anymore, use the icon tag in jelly views or the icon class name of BallColor
      Returns the absolute URL for the specified ball icon.
      Parameters:
      color - the color
      Returns:
      the absolute URL
    • getSymbol

      public String getSymbol(SymbolRequest symbol)
      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

      public String getImagePath(String icon)
      Returns the absolute URL for the specified icon.
      Parameters:
      icon - the icon URL
      Returns:
      the absolute URL
    • getAbsoluteUrl

      public String getAbsoluteUrl(String... urlElements)
      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

      public Set<String> getAllJobNames()
      Returns the full names of all available jobs. The full name is given by AbstractItem.getFullName().
      Returns:
      the full names of all jobs
    • getAllJobs

      public List<Job> getAllJobs()
      Returns all available jobs.
      Returns:
      all jobs
    • getFullNameOf

      public String getFullNameOf(Job<?,?> job)
      Returns the full name of the specified job.
      Parameters:
      job - the job to get the name for
      Returns:
      the full name
    • isPluginInstalled

      public boolean isPluginInstalled(String pluginId)
      Returns whether the plugin with the specified ID (short name, artifact ID) is installed.
      Parameters:
      pluginId - the ID of the plugin
      Returns:
      true if the plugin is installed, false if not
    • getLegacyInstanceId

      public String 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