com.atlassian.bamboo.variable
Class CustomVariableContextImpl

java.lang.Object
  extended by com.atlassian.bamboo.variable.CustomVariableContextImpl
All Implemented Interfaces:
CustomVariableContext

public class CustomVariableContextImpl
extends Object
implements CustomVariableContext


Constructor Summary
CustomVariableContextImpl(VariableSubstitutorFactory variableSubstitutorFactory)
           
 
Method Summary
 void addCustomData(String key, String value)
          Adds a VariableType.MANUAL variable to ThreadLocal state.
 void clearContext()
          Clear ThreadLocal state.
 Set<String> findAllVariables(String variable)
          Given a string, and a Map of variables (variable -> value), all patterns in the string array matching ${bamboo.} will be substituted with the value.
 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)
          Get all variables from context.
 Map<String,String> getVariables(CommonContext buildContext)
          Get all variables from context.
 VariableSubstitutorFactory getVariableSubstitutorFactory()
           
 String removeAllVariables(String value)
          Given a string array, remove all variable patterns.
 void setCommonContext(CommonContext commonContext)
          Set context reference in ThreadLocal state.
 void setPlan(ImmutablePlan plan)
          Sets Plan reference and default variable definitions (globals and from plan) in ThreadLocal state.
 void setPlan(ImmutablePlan plan, Map<String,VariableDefinitionContext> variablesContextMap)
          Sets Plan reference and variable definitions in ThreadLocal state.
 void setPlan(PlanIdentifier planIdentifier, Map<String,VariableDefinitionContext> variablesContextMap)
          Sets Plan reference and variable definitions in ThreadLocal state.
 void setVariables(Map<String,VariableDefinitionContext> variablesContextMap)
          Set variable definitions in ThreadLocal state.
 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)
          Substitutes variables in the input string with their values using provided data, i.e.
<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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomVariableContextImpl

public CustomVariableContextImpl(VariableSubstitutorFactory variableSubstitutorFactory)
Method Detail

setPlan

public void setPlan(@NotNull
                    PlanIdentifier planIdentifier,
                    @Nullable
                    Map<String,VariableDefinitionContext> variablesContextMap)
Description copied from interface: CustomVariableContext
Sets Plan reference and variable definitions in ThreadLocal state. Clears history of substituted variables (CustomVariableContext.getSubstitutedVariables()

Specified by:
setPlan in interface CustomVariableContext
variablesContextMap - variable definitions (including plan variables)

setPlan

public void setPlan(@NotNull
                    ImmutablePlan plan)
Description copied from interface: CustomVariableContext
Sets Plan reference and default variable definitions (globals and from plan) in ThreadLocal state. Clears history of substituted variables (CustomVariableContext.getSubstitutedVariables()

Specified by:
setPlan in interface CustomVariableContext

setPlan

public void setPlan(@NotNull
                    ImmutablePlan plan,
                    @Nullable
                    Map<String,VariableDefinitionContext> variablesContextMap)
Description copied from interface: CustomVariableContext
Sets Plan reference and variable definitions in ThreadLocal state. Clears history of substituted variables (CustomVariableContext.getSubstitutedVariables()

Specified by:
setPlan in interface CustomVariableContext
variablesContextMap - variable definitions (including plan variables)

setVariables

public void setVariables(Map<String,VariableDefinitionContext> variablesContextMap)
Description copied from interface: CustomVariableContext
Set variable definitions in ThreadLocal state. Clears history of substituted variables (CustomVariableContext.getSubstitutedVariables()

Specified by:
setVariables in interface CustomVariableContext
Parameters:
variablesContextMap - variable definitions

setCommonContext

public void setCommonContext(@NotNull
                             CommonContext commonContext)
Description copied from interface: CustomVariableContext
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.

Specified by:
setCommonContext in interface CustomVariableContext

clearContext

public void clearContext()
Description copied from interface: CustomVariableContext
Clear ThreadLocal state.

Specified by:
clearContext in interface CustomVariableContext

getSubstitutedVariables

@NotNull
public Map<String,VariableSubstitutionContext> getSubstitutedVariables()
Description copied from interface: CustomVariableContext
Get all the variables that have previously been substituted in this thread.

Specified by:
getSubstitutedVariables in interface CustomVariableContext
Returns:

addCustomData

public void addCustomData(String key,
                          String value)
Description copied from interface: CustomVariableContext
Adds a VariableType.MANUAL variable to ThreadLocal state.

Specified by:
addCustomData in interface CustomVariableContext
Parameters:
key - name of the variable
value - value of the variable

substituteString

public String substituteString(String value)
Description copied from interface: CustomVariableContext
Substitutes variables in the input string with their values using data from existing ThreadLocal state.

Specified by:
substituteString in interface CustomVariableContext
Parameters:
value - input string
Returns:
substituted string

substituteString

public String substituteString(String value,
                               @Nullable
                               CommonContext commonContext,
                               BuildLogger buildLogger)
Description copied from interface: CustomVariableContext
Substitutes variables in the input string with their values using provided data, i.e. overriding (for this call only) any existing ThreadLocal state.

Specified by:
substituteString in interface CustomVariableContext
Parameters:
value - input string
commonContext - build context
buildLogger - build logger
Returns:
substituted string

removeAllVariables

@NotNull
public String removeAllVariables(@NotNull
                                         String value)
Given a string array, remove all variable patterns.

Specified by:
removeAllVariables in interface CustomVariableContext
Parameters:
value - string values to be analyzed
Returns:
value with variables removed

findAllVariables

@NotNull
public Set<String> findAllVariables(@Nullable
                                            String variable)
Given a string, and a Map of variables (variable -> value), all patterns in the string array matching ${bamboo.} will be substituted with the value.

Specified by:
findAllVariables in interface CustomVariableContext
Parameters:
variable - String value to be analyzed
Returns:
Array of string values with variables extrapolated

getVariableContexts

@NotNull
public Map<String,VariableDefinitionContext> getVariableContexts(@Nullable
                                                                         CommonContext commonContext)
Description copied from interface: CustomVariableContext
Get all variables from context.

Specified by:
getVariableContexts in interface CustomVariableContext
Parameters:
commonContext - build or deployment context
Returns:
mapping between variable keys and contexts

getVariableContexts

@NotNull
public Map<String,VariableDefinitionContext> getVariableContexts()
Description copied from interface: CustomVariableContext
Get all variables from current thread local context.

Specified by:
getVariableContexts in interface CustomVariableContext
Returns:
mapping between variable keys and contexts

getVariables

@NotNull
public Map<String,String> getVariables(@Nullable
                                               CommonContext buildContext)
Description copied from interface: CustomVariableContext
Get all variables from context.

Specified by:
getVariables in interface CustomVariableContext
Parameters:
buildContext - Build or Deployment context
Returns:
mapping between variable keys and values

getBuildInRepositoryVariablesIfBuildContext

public Map<String,VariableDefinitionContext> getBuildInRepositoryVariablesIfBuildContext()
Description copied from interface: CustomVariableContext
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

Specified by:
getBuildInRepositoryVariablesIfBuildContext in interface CustomVariableContext

getVariableSubstitutorFactory

@NotNull
public VariableSubstitutorFactory getVariableSubstitutorFactory()
Specified by:
getVariableSubstitutorFactory in interface CustomVariableContext
Returns:
factory for VariableSubstitutor

withVariableSubstitutor

public void withVariableSubstitutor(@NotNull
                                    VariableSubstitutor variableSubstitutor,
                                    @NotNull
                                    Runnable runnable)
Description copied from interface: CustomVariableContext
Run operation with provided VariableSubstitutor in thread local context. Restore current thread local state when finished.

Specified by:
withVariableSubstitutor in interface CustomVariableContext

withVariableSubstitutor

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

Specified by:
withVariableSubstitutor in interface CustomVariableContext
Throws:
Exception

withVariableSubstitutor

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

Specified by:
withVariableSubstitutor in interface CustomVariableContext


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