com.atlassian.bamboo.variable
Class CustomVariableContextForTests

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

public class CustomVariableContextForTests
extends Object
implements CustomVariableContext


Constructor Summary
CustomVariableContextForTests()
           
 
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 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)
          Get all variables from context.
 Map<String,String> getVariables(CommonContext commonContext)
          Get all variables from context.
 VariableSubstitutorFactory getVariableSubstitutorFactory()
           
 String removeAllVariables(String unparsedString)
          Given a string, 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 plan, 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

CustomVariableContextForTests

public CustomVariableContextForTests()
Method Detail

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

@Nullable
public String substituteString(@Nullable
                                        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

@Nullable
public String substituteString(@Nullable
                                        String value,
                                        @Nullable
                                        CommonContext commonContext,
                                        @Nullable
                                        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

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 commonContext)
Description copied from interface: CustomVariableContext
Get all variables from context.

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

removeAllVariables

@NotNull
public String removeAllVariables(@NotNull
                                         String unparsedString)
Description copied from interface: CustomVariableContext
Given a string, remove all variable patterns.

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

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:

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

setPlan

public void setPlan(@NotNull
                    PlanIdentifier 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)

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)

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

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

findAllVariables

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

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

getBuildInRepositoryVariablesIfBuildContext

@NotNull
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.