org.jenkinsci.plugins.tokenmacro
Class DataBoundTokenMacro

java.lang.Object
  extended by org.jenkinsci.plugins.tokenmacro.TokenMacro
      extended by org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro
All Implemented Interfaces:
hudson.ExtensionPoint

public abstract class DataBoundTokenMacro
extends TokenMacro

Convenient base class for implementing TokenMacro that does parameter databiding 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.

Author:
Kohsuke Kawaguchi

Nested Class Summary
static interface DataBoundTokenMacro.Parameter
           
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Constructor Summary
DataBoundTokenMacro()
           
 
Method Summary
abstract  java.lang.String evaluate(hudson.model.AbstractBuild<?,?> context, hudson.model.TaskListener listener, java.lang.String macroName)
           
 java.lang.String evaluate(hudson.model.AbstractBuild<?,?> context, hudson.model.TaskListener listener, java.lang.String macroName, java.util.Map<java.lang.String,java.lang.String> arguments, com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> argumentMultimap)
          Evaluates the macro and produces the token.
 
Methods inherited from class org.jenkinsci.plugins.tokenmacro.TokenMacro
acceptsMacroName, all, expand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataBoundTokenMacro

public DataBoundTokenMacro()
Method Detail

evaluate

public java.lang.String evaluate(hudson.model.AbstractBuild<?,?> context,
                                 hudson.model.TaskListener listener,
                                 java.lang.String macroName,
                                 java.util.Map<java.lang.String,java.lang.String> arguments,
                                 com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> argumentMultimap)
                          throws MacroEvaluationException,
                                 java.io.IOException,
                                 java.lang.InterruptedException
Description copied from class: TokenMacro
Evaluates the macro and produces the token.

Locale

If the token is to produce a human readable text, it should do so by using the implicit locale associated with the calling thread — see Functions.getCurrentLocale().

Specified by:
evaluate in class TokenMacro
Parameters:
context - 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 accepted
arguments - 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 because
argumentMultimap - 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.
Returns:
The result of the evaluation. Must not be null.
Throws:
MacroEvaluationException - If the evaluation failed, for example because of the parameter error, and that the error message should be presented.
java.io.IOException - Other fatal IOExceptions that should leave the stack trace in the console.
java.lang.InterruptedException - If the evaluation involves some remoting operation, user might cancel the build, which results in an InterruptedException. Don't catch it, just propagate.

evaluate

public abstract java.lang.String evaluate(hudson.model.AbstractBuild<?,?> context,
                                          hudson.model.TaskListener listener,
                                          java.lang.String macroName)
                                   throws MacroEvaluationException,
                                          java.io.IOException,
                                          java.lang.InterruptedException
Throws:
MacroEvaluationException
java.io.IOException
java.lang.InterruptedException


Copyright © 2004-2011. All Rights Reserved.