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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringattribute(String name)Gets the custom attribute value for the current URL generation..DisplayURLContextattribute(String name, String value)Adds custom attributes to the context.voidclose()Queue.Executableexecutable()Gets theQueue.Executableassociated with the current URL generation (if any).DisplayURLContextexecutable(Queue.Executable executable)Uses the suppliedQueue.Executableto fill in as much of the context as possible.Job<?,?>job()Gets theJobassociated with the current URL generation (if any).DisplayURLContextjob(Job<?,?> job)Uses the suppliedJobto fill in as much of the context as possible.static DisplayURLContextopen()Opens aDisplayURLContextfor the current thread.static DisplayURLContextopen(boolean guessPlugin)Opens aDisplayURLContextfor the current thread.PluginWrapperplugin()Gets the best guess as to thePluginWrapperrequesting the current URL generation (if any).DisplayURLContextplugin(PluginWrapper plugin)Overrides the inferred plugin tha is requesting the URL to be generated with the supplied plugin.Run<?,?>run()Gets theRunassociated with the current URL generation (if any).DisplayURLContextrun(Run<?,?> run)Uses the suppliedRunto fill in as much of the context as possible.Queue.Tasktask()Gets theQueue.Taskassociated with the current URL generation (if any).DisplayURLContexttask(Queue.Task task)Uses the suppliedQueue.Taskto fill in as much of the context as possible.
-
-
-
Method Detail
-
open
@NonNull public static DisplayURLContext open(boolean guessPlugin)
Opens aDisplayURLContextfor the current thread.- Parameters:
guessPlugin- try to infer the current plugin (resource intensive as requires a stack trace and class loading). Usefalseif you know the caller will always be Jenkins core.- Returns:
- the
DisplayURLContext.
-
open
@NonNull public static DisplayURLContext open()
Opens aDisplayURLContextfor the current thread.- Returns:
- the
DisplayURLContext.
-
task
@NonNull public DisplayURLContext task(@CheckForNull Queue.Task task)
Uses the suppliedQueue.Taskto fill in as much of the context as possible. If the task implementsJobthen thejob()will also be set. Prefer callingjob(Job)if you know the task is aJobalready.- Parameters:
task- the task.- Returns:
thisfor method chaining.
-
executable
@NonNull public DisplayURLContext executable(@CheckForNull Queue.Executable executable)
Uses the suppliedQueue.Executableto fill in as much of the context as possible. The owning task of the executable will be used to set thetask(). If the task implementsRunthen therun()andjob()will also be set. Prefer callingrun(Run)if you know the executable is aRunalready.- Parameters:
executable- the executable.- Returns:
thisfor method chaining.
-
job
@NonNull public DisplayURLContext job(@CheckForNull Job<?,?> job)
Uses the suppliedJobto fill in as much of the context as possible. If the job is also aQueue.Taskthentask()will also be set.- Parameters:
job- the job.- Returns:
thisfor method chaining.
-
run
@NonNull public DisplayURLContext run(@CheckForNull Run<?,?> run)
Uses the suppliedRunto fill in as much of the context as possible. TheRun.getParent()will be set to thejob()andtask()as appropriate. If the run is also aQueue.Executablethenexecutable()will also be set.- Parameters:
run- the run.- Returns:
thisfor 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:
thisfor 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 benull).- Returns:
thisfor method chaining.
-
task
@CheckForNull public Queue.Task task()
Gets theQueue.Taskassociated with the current URL generation (if any).- Returns:
- the
Queue.Taskassociated with the current URL generation ornullif none.
-
executable
@CheckForNull public Queue.Executable executable()
Gets theQueue.Executableassociated with the current URL generation (if any).- Returns:
- the
Queue.Executableassociated with the current URL generation ornullif none.
-
job
@CheckForNull public Job<?,?> job()
Gets theJobassociated with the current URL generation (if any).- Returns:
- the
Jobassociated with the current URL generation ornullif none.
-
run
@CheckForNull public Run<?,?> run()
Gets theRunassociated with the current URL generation (if any).- Returns:
- the
Runassociated with the current URL generation ornullif none.
-
plugin
@CheckForNull public PluginWrapper plugin()
Gets the best guess as to thePluginWrapperrequesting the current URL generation (if any).- Returns:
- the
PluginWrappermost closely associated with the current URL generation ornullif 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-