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 String
attribute(String name)
Gets the custom attribute value for the current URL generation..DisplayURLContext
attribute(String name, String value)
Adds custom attributes to the context.void
close()
Queue.Executable
executable()
Gets theQueue.Executable
associated with the current URL generation (if any).DisplayURLContext
executable(Queue.Executable executable)
Uses the suppliedQueue.Executable
to fill in as much of the context as possible.Job<?,?>
job()
Gets theJob
associated with the current URL generation (if any).DisplayURLContext
job(Job<?,?> job)
Uses the suppliedJob
to fill in as much of the context as possible.static DisplayURLContext
open()
Opens aDisplayURLContext
for the current thread.static DisplayURLContext
open(boolean guessPlugin)
Opens aDisplayURLContext
for the current thread.PluginWrapper
plugin()
Gets the best guess as to thePluginWrapper
requesting the current URL generation (if any).DisplayURLContext
plugin(PluginWrapper plugin)
Overrides the inferred plugin tha is requesting the URL to be generated with the supplied plugin.Run<?,?>
run()
Gets theRun
associated with the current URL generation (if any).DisplayURLContext
run(Run<?,?> run)
Uses the suppliedRun
to fill in as much of the context as possible.Queue.Task
task()
Gets theQueue.Task
associated with the current URL generation (if any).DisplayURLContext
task(Queue.Task task)
Uses the suppliedQueue.Task
to fill in as much of the context as possible.
-
-
-
Method Detail
-
open
@NonNull public static DisplayURLContext open(boolean guessPlugin)
Opens aDisplayURLContext
for the current thread.- Parameters:
guessPlugin
- try to infer the current plugin (resource intensive as requires a stack trace and class loading). Usefalse
if you know the caller will always be Jenkins core.- Returns:
- the
DisplayURLContext
.
-
open
@NonNull public static DisplayURLContext open()
Opens aDisplayURLContext
for the current thread.- Returns:
- the
DisplayURLContext
.
-
task
@NonNull public DisplayURLContext task(@CheckForNull Queue.Task task)
Uses the suppliedQueue.Task
to fill in as much of the context as possible. If the task implementsJob
then thejob()
will also be set. Prefer callingjob(Job)
if you know the task is aJob
already.- Parameters:
task
- the task.- Returns:
this
for method chaining.
-
executable
@NonNull public DisplayURLContext executable(@CheckForNull Queue.Executable executable)
Uses the suppliedQueue.Executable
to fill in as much of the context as possible. The owning task of the executable will be used to set thetask()
. If the task implementsRun
then therun()
andjob()
will also be set. Prefer callingrun(Run)
if you know the executable is aRun
already.- Parameters:
executable
- the executable.- Returns:
this
for method chaining.
-
job
@NonNull public DisplayURLContext job(@CheckForNull Job<?,?> job)
Uses the suppliedJob
to fill in as much of the context as possible. If the job is also aQueue.Task
thentask()
will also be set.- Parameters:
job
- the job.- Returns:
this
for method chaining.
-
run
@NonNull public DisplayURLContext run(@CheckForNull Run<?,?> run)
Uses the suppliedRun
to 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.Executable
thenexecutable()
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 benull
).- Returns:
this
for method chaining.
-
task
@CheckForNull public Queue.Task task()
Gets theQueue.Task
associated with the current URL generation (if any).- Returns:
- the
Queue.Task
associated with the current URL generation ornull
if none.
-
executable
@CheckForNull public Queue.Executable executable()
Gets theQueue.Executable
associated with the current URL generation (if any).- Returns:
- the
Queue.Executable
associated with the current URL generation ornull
if none.
-
job
@CheckForNull public Job<?,?> job()
Gets theJob
associated with the current URL generation (if any).- Returns:
- the
Job
associated with the current URL generation ornull
if none.
-
run
@CheckForNull public Run<?,?> run()
Gets theRun
associated with the current URL generation (if any).- Returns:
- the
Run
associated with the current URL generation ornull
if none.
-
plugin
@CheckForNull public PluginWrapper plugin()
Gets the best guess as to thePluginWrapper
requesting the current URL generation (if any).- Returns:
- the
PluginWrapper
most closely associated with the current URL generation ornull
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-