Class DisplayURLContext

java.lang.Object
org.jenkinsci.plugins.displayurlapi.DisplayURLContext
All Implemented Interfaces:
Closeable, AutoCloseable

public class DisplayURLContext extends Object implements Closeable
Holds contextual information that can be used when generating an URL for display. On the current thread, each context is layered with the most specific context information being provided when queried.
  • Method Details

    • open

      @NonNull public static DisplayURLContext open(boolean guessPlugin)
      Opens a DisplayURLContext for the current thread.
      Parameters:
      guessPlugin - try to infer the current plugin (resource intensive as requires a stack trace and class loading). Use false if you know the caller will always be Jenkins core.
      Returns:
      the DisplayURLContext.
    • open

      @NonNull public static DisplayURLContext open()
      Opens a DisplayURLContext for the current thread.
      Returns:
      the DisplayURLContext.
    • task

      @NonNull public DisplayURLContext task(@CheckForNull Queue.Task task)
      Uses the supplied Queue.Task to fill in as much of the context as possible. If the task implements Job then the job() will also be set. Prefer calling job(Job) if you know the task is a Job already.
      Parameters:
      task - the task.
      Returns:
      this for method chaining.
    • executable

      @NonNull public DisplayURLContext executable(@CheckForNull Queue.Executable executable)
      Uses the supplied Queue.Executable to fill in as much of the context as possible. The owning task of the executable will be used to set the task(). If the task implements Run then the run() and job() will also be set. Prefer calling run(Run) if you know the executable is a Run already.
      Parameters:
      executable - the executable.
      Returns:
      this for method chaining.
    • job

      @NonNull public DisplayURLContext job(@CheckForNull Job<?,?> job)
      Uses the supplied Job to fill in as much of the context as possible. If the job is also a Queue.Task then task() will also be set.
      Parameters:
      job - the job.
      Returns:
      this for method chaining.
    • run

      @NonNull public DisplayURLContext run(@CheckForNull Run<?,?> run)
      Uses the supplied Run to fill in as much of the context as possible. The Run.getParent() will be set to the job() and task() as appropriate. If the run is also a Queue.Executable then executable() will also be set.
      Parameters:
      run - the run.
      Returns:
      this for method chaining.
    • plugin

      @NonNull public DisplayURLContext plugin(@CheckForNull PluginWrapper plugin)
      Overrides the inferred plugin tha is requesting the URL to be generated with the supplied plugin.
      Parameters:
      plugin - the plugin.
      Returns:
      this for method chaining.
    • attribute

      @NonNull public DisplayURLContext attribute(String name, String value)
      Adds custom attributes to the context.
      Parameters:
      name - the name of the attribute.
      value - the value of the attribute (may be null).
      Returns:
      this for method chaining.
    • task

      @CheckForNull public Queue.Task task()
      Gets the Queue.Task associated with the current URL generation (if any).
      Returns:
      the Queue.Task associated with the current URL generation or null if none.
    • executable

      @CheckForNull public Queue.Executable executable()
      Gets the Queue.Executable associated with the current URL generation (if any).
      Returns:
      the Queue.Executable associated with the current URL generation or null if none.
    • job

      @CheckForNull public Job<?,?> job()
      Gets the Job associated with the current URL generation (if any).
      Returns:
      the Job associated with the current URL generation or null if none.
    • run

      @CheckForNull public Run<?,?> run()
      Gets the Run associated with the current URL generation (if any).
      Returns:
      the Run associated with the current URL generation or null if none.
    • plugin

      @CheckForNull public PluginWrapper plugin()
      Gets the best guess as to the PluginWrapper requesting the current URL generation (if any).
      Returns:
      the PluginWrapper most closely associated with the current URL generation or null if initiated by Jenkins core.
    • attribute

      @CheckForNull public String attribute(String name)
      Gets the custom attribute value for the current URL generation..
      Parameters:
      name - the name of the attribute.
      Returns:
      the value or null.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable