com.atlassian.bamboo.variable
Interface CustomVariableContext

All Known Implementing Classes:
CustomVariableContextForTests, CustomVariableContextImpl

@PublicApi
public interface CustomVariableContext

Bean maintaining ThreadLocal state of available variables. The state contains (if applicable): - current Plan - variable definitions (including Plan variables when applicable) - BuildContext - BuildLogger


Method Summary
 void addCustomData(String key, String value)
          Adds a VariableType.MANUAL variable to ThreadLocal state.
 void clearContext()
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 Set<String> findAllVariables(String stringWithVariables)
          Given a string, all patterns in the string matching ${bamboo.} or ${system.} will be found.
 Map<String,VariableDefinitionContext> getBuildInRepositoryVariablesIfBuildContext()
          Return variables all built-in variables produced by repository plugin for the current build context.
 Map<String,VariableSubstitutionContext> getSubstitutedVariables()
          Get all the variables that have previously been substituted in this thread.
 Map<String,VariableDefinitionContext> getVariableContexts()
          Get all variables from current thread local context.
 Map<String,VariableDefinitionContext> getVariableContexts(CommonContext commonContext)
          Deprecated. since 5.9 use getVariableContexts() if you want to use current thread local context. Use VariableSubstitutor otherwise.
 Map<String,String> getVariables(CommonContext commonContext)
          Deprecated. since 5.9 use getVariableContexts() if you want to use current thread local context. Use VariableSubstitutor otherwise.
 VariableSubstitutorFactory getVariableSubstitutorFactory()
           
 String removeAllVariables(String unparsedString)
          Given a string, remove all variable patterns.
 void setCommonContext(CommonContext commonContext)
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 void setPlan(ImmutablePlan plan)
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 void setPlan(ImmutablePlan plan, Map<String,VariableDefinitionContext> variablesContextMap)
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 void setPlan(PlanIdentifier plan, Map<String,VariableDefinitionContext> variablesContextMap)
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 void setVariables(Map<String,VariableDefinitionContext> variablesContextMap)
          Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)
 String substituteString(String value)
          Substitutes variables in the input string with their values using data from existing ThreadLocal state.
 String substituteString(String value, CommonContext commonContext, BuildLogger buildLogger)
          Deprecated. since 5.9 use substituteString(String) if you want to use current thread local context. Use VariableSubstitutor otherwise.
<V> V
withVariableSubstitutor(VariableSubstitutor variableSubstitutor, Callable<V> callable)
          Run operation with provided VariableSubstitutor in thread local context.
 void withVariableSubstitutor(VariableSubstitutor variableSubstitutor, Runnable runnable)
          Run operation with provided VariableSubstitutor in thread local context.
<V> V
withVariableSubstitutor(VariableSubstitutor variableSubstitutor, com.google.common.base.Supplier<V> supplier)
          Run operation with provided VariableSubstitutor in thread local context.
 

Method Detail

addCustomData

void addCustomData(String key,
                   String value)
Adds a VariableType.MANUAL variable to ThreadLocal state.

Parameters:
key - name of the variable
value - value of the variable

substituteString

@Nullable
String substituteString(@Nullable
                                 String value)
Substitutes variables in the input string with their values using data from existing ThreadLocal state.

Parameters:
value - input string
Returns:
substituted string

substituteString

@Deprecated
@Nullable
String substituteString(@Nullable
                                            String value,
                                            @Nullable
                                            CommonContext commonContext,
                                            @Nullable
                                            BuildLogger buildLogger)
Deprecated. since 5.9 use substituteString(String) if you want to use current thread local context. Use VariableSubstitutor otherwise.

Substitutes variables in the input string with their values using provided data, i.e. overriding (for this call only) any existing ThreadLocal state.

Parameters:
value - input string
commonContext - build context
buildLogger - build logger
Returns:
substituted string

getVariableContexts

@Deprecated
@NotNull
Map<String,VariableDefinitionContext> getVariableContexts(@Nullable
                                                                             CommonContext commonContext)
Deprecated. since 5.9 use getVariableContexts() if you want to use current thread local context. Use VariableSubstitutor otherwise.

Get all variables from context.

Parameters:
commonContext - build or deployment context
Returns:
mapping between variable keys and contexts
Since:
5.7

getVariableContexts

@NotNull
Map<String,VariableDefinitionContext> getVariableContexts()
Get all variables from current thread local context.

Returns:
mapping between variable keys and contexts
Since:
5.9

getVariables

@NotNull
@Deprecated
Map<String,String> getVariables(@Nullable
                                                   CommonContext commonContext)
Deprecated. since 5.9 use getVariableContexts() if you want to use current thread local context. Use VariableSubstitutor otherwise.

Get all variables from context.

Parameters:
commonContext - Build or Deployment context
Returns:
mapping between variable keys and values

removeAllVariables

@NotNull
String removeAllVariables(@NotNull
                                  String unparsedString)
Given a string, remove all variable patterns.

Parameters:
unparsedString - string values to be analyzed
Returns:
value with variables removed

getSubstitutedVariables

@NotNull
Map<String,VariableSubstitutionContext> getSubstitutedVariables()
Get all the variables that have previously been substituted in this thread.

Returns:

setCommonContext

@Deprecated
void setCommonContext(@NotNull
                                 CommonContext commonContext)
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Set context reference in ThreadLocal state. Sets the variable definitions to those contained in the context. context has priority over Plans and Deployment Jobs when resolving the variables.

Parameters:
commonContext -

clearContext

@Deprecated
void clearContext()
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Clear ThreadLocal state.


setPlan

@Deprecated
void setPlan(@NotNull
                        PlanIdentifier plan,
                        @Nullable
                        Map<String,VariableDefinitionContext> variablesContextMap)
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Sets Plan reference and variable definitions in ThreadLocal state. Clears history of substituted variables (getSubstitutedVariables()

Parameters:
plan -
variablesContextMap - variable definitions (including plan variables)

setPlan

@Deprecated
void setPlan(@NotNull
                        ImmutablePlan plan,
                        @Nullable
                        Map<String,VariableDefinitionContext> variablesContextMap)
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Sets Plan reference and variable definitions in ThreadLocal state. Clears history of substituted variables (getSubstitutedVariables()

Parameters:
plan -
variablesContextMap - variable definitions (including plan variables)

setPlan

@Deprecated
void setPlan(@NotNull
                        ImmutablePlan plan)
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Sets Plan reference and default variable definitions (globals and from plan) in ThreadLocal state. Clears history of substituted variables (getSubstitutedVariables()

Parameters:
plan -
Since:
5.6

setVariables

@Deprecated
void setVariables(Map<String,VariableDefinitionContext> variablesContextMap)
Deprecated. since 5.9 use CustomVariableContextRunner or withVariableSubstitutor(VariableSubstitutor, Runnable)

Set variable definitions in ThreadLocal state. Clears history of substituted variables (getSubstitutedVariables()

Parameters:
variablesContextMap - variable definitions

findAllVariables

@NotNull
Set<String> findAllVariables(@Nullable
                                     String stringWithVariables)
Given a string, all patterns in the string matching ${bamboo.} or ${system.} will be found.

Parameters:
stringWithVariables - String value to be analyzed
Returns:
Array of string values with variables extrapolated

getBuildInRepositoryVariablesIfBuildContext

@NotNull
Map<String,VariableDefinitionContext> getBuildInRepositoryVariablesIfBuildContext()
Return variables all built-in variables produced by repository plugin for the current build context. Current thread local state must contain BuildContext, otherwise returned map will be empty. Note: variables are used in repository definition, they will be resolved according to current state of the CustomVariableContext

Since:
5.9

getVariableSubstitutorFactory

@NotNull
VariableSubstitutorFactory getVariableSubstitutorFactory()
Returns:
factory for VariableSubstitutor
Since:
5.9

withVariableSubstitutor

void withVariableSubstitutor(@NotNull
                             VariableSubstitutor variableSubstitutor,
                             @NotNull
                             Runnable runnable)
Run operation with provided VariableSubstitutor in thread local context. Restore current thread local state when finished.

Since:
5.9

withVariableSubstitutor

<V> V withVariableSubstitutor(@NotNull
                              VariableSubstitutor variableSubstitutor,
                              @NotNull
                              Callable<V> callable)
                          throws Exception
Run operation with provided VariableSubstitutor in thread local context. Restore current thread local state when finished.

Throws:
Exception
Since:
5.9

withVariableSubstitutor

<V> V withVariableSubstitutor(@NotNull
                              VariableSubstitutor variableSubstitutor,
                              @NotNull
                              com.google.common.base.Supplier<V> supplier)
Run operation with provided VariableSubstitutor in thread local context. Restore current thread local state when finished.

Since:
5.9


Copyright © 2015 Atlassian Software Systems Pty Ltd. All rights reserved.