public abstract class DataBoundTokenMacro extends TokenMacro
TokenMacro
that does parameter databinding to fields.
When you define your token macro as a subtype of this class, a fresh instance is created for each
evaluation, and fields or setters with the DataBoundTokenMacro.Parameter
annotation will receive the corresponding
parameter values, then the evaluate(AbstractBuild, TaskListener, String)
method gets invoked.
In this way, you simplify the parameter parsing and type conversion overhead.
Modifier and Type | Class and Description |
---|---|
static interface |
DataBoundTokenMacro.Parameter |
ExtensionPoint.LegacyInstancesAreScopedToHudson
Modifier and Type | Field and Description |
---|---|
boolean |
escapeHtml |
Constructor and Description |
---|
DataBoundTokenMacro() |
Modifier and Type | Method and Description |
---|---|
abstract String |
evaluate(AbstractBuild<?,?> context,
TaskListener listener,
String macroName) |
String |
evaluate(AbstractBuild<?,?> build,
TaskListener listener,
String macroName,
Map<String,String> arguments,
com.google.common.collect.ListMultimap<String,String> argumentMultimap)
Evaluates the macro and produces the token.
|
String |
evaluate(Run<?,?> run,
FilePath workspace,
TaskListener listener,
String macroName) |
String |
evaluate(Run<?,?> run,
FilePath workspace,
TaskListener listener,
String macroName,
Map<String,String> arguments,
com.google.common.collect.ListMultimap<String,String> argumentMultimap) |
boolean |
handlesHtmlEscapeInternally()
Indicates whether this macro handles
escapeHtml on its own inside the evaluate methods. |
boolean |
hasNestedContent()
Returns true if this object allows for nested content replacements.
|
acceptsMacroName, all, expand, expand, expand, expand, expandAll, expandAll, expandAll, expandAll, getAcceptedMacroNames, getAutoCompleteList, getPreviousRun, getWorkspace
public String evaluate(AbstractBuild<?,?> build, TaskListener listener, String macroName, Map<String,String> arguments, com.google.common.collect.ListMultimap<String,String> argumentMultimap) throws MacroEvaluationException, IOException, InterruptedException
TokenMacro
Functions.getCurrentLocale()
.evaluate
in class TokenMacro
build
- The build object for which this macro is evaluated.listener
- If the progress/status needs to be reported to the build console output, this object can be used.macroName
- The macro name that you acceptedarguments
- Arguments as a map. If multiple values are specified for one key, this will only retain the last one.
This is passed in separately from argumentMultimap
becauseargumentMultimap
- The same arguments, but in a multi-map. If multiple values are specified for one key, all of them
are retained here in the order of appearance. For those macros that support multiple values for the same key
this is more accurate than arguments
, but it's bit more tedious to use.MacroEvaluationException
- If the evaluation failed, for example because of the parameter error, and that the error message
should be presented.IOException
- Other fatal IOException
s that should leave the stack trace in the console.InterruptedException
- If the evaluation involves some remoting operation, user might cancel the build, which results
in an InterruptedException
. Don't catch it, just propagate.public String evaluate(Run<?,?> run, FilePath workspace, TaskListener listener, String macroName, Map<String,String> arguments, com.google.common.collect.ListMultimap<String,String> argumentMultimap) throws MacroEvaluationException, IOException, InterruptedException
evaluate
in class TokenMacro
MacroEvaluationException
IOException
InterruptedException
public boolean handlesHtmlEscapeInternally()
escapeHtml
on its own inside the evaluate
methods.
If this method returns false
and escapeHtml
is true
then the returned value from
evaluate(AbstractBuild, TaskListener, String)
and evaluate(Run, FilePath, TaskListener, String)
will be escaped. If this method returns true
no escaping will be performed,
and it is assumed the escaping will be handled internally by the implementing class. It is then also assumed that
the help.jelly
file for that class mentions the escapeHtml
parameter.public abstract String evaluate(AbstractBuild<?,?> context, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException
public String evaluate(Run<?,?> run, FilePath workspace, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException
public boolean hasNestedContent()
TokenMacro
hasNestedContent
in class TokenMacro
TokenMacro.expand(AbstractBuild, TaskListener, String)
for additional expansion.Copyright © 2016–2022. All rights reserved.