Package com.dtolabs.rundeck.core.data
Class SharedDataContextUtils
- java.lang.Object
-
- com.dtolabs.rundeck.core.data.SharedDataContextUtils
-
public class SharedDataContextUtils extends java.lang.Object
DataContextUtils provides methods for using a set of context data to substitute property references, generate environment variables, and expand tokens in a file.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
PROPERTY_REF_PATTERN
static java.lang.String
PROPERTY_REF_REGEX
static java.lang.String
PROPERTY_VIEW_REF_REGEX
static java.lang.String
UNQUOTEDPROPERTY_PREFIX
static java.util.regex.Pattern
UNQUOTEDPROPERTY_REF_PATTERN
-
Constructor Summary
Constructors Constructor Description SharedDataContextUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
escapeShell(java.lang.String s)
Escape characters meaningful to bash shell unless the string is already surrounded in single quotesstatic java.lang.String
escapeWindowsShell(java.lang.String s)
Escape characters meaningful to windows unless the string is already surrounded in single quotesstatic ReadableSharedContext
outputContext(ContextView defaultView)
static <T extends ViewTraverse<T>>
java.lang.String[]replaceDataReferences(java.lang.String[] args, MultiDataContext<T,DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, boolean failIfUnexpanded, boolean blankIfUnexpanded)
Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data contextstatic <T extends ViewTraverse<T>>
java.lang.StringreplaceDataReferences(java.lang.String input, MultiDataContext<T,DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, boolean failOnUnexpanded, boolean blankIfUnexpanded)
Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data contextstatic <T extends ViewTraverse<T>>
java.util.Map<java.lang.String,java.lang.Object>replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data)
Recursively replace data references in the values in a map which contains either string, collection or Map values.static <T extends ViewTraverse<T>>
java.util.Map<java.lang.String,java.lang.Object>replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)
Recursively replace data references in the values in a map which contains either string, collection or Map values.static <T extends ViewTraverse<T>>
java.util.Map<java.lang.String,java.lang.Object>replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,java.lang.Boolean> blankIfUnexpandedFieldMap)
Recursively replace data references in the values in a map which contains either string, collection or Map values.static <T extends ViewTraverse<T>>
java.util.Map<java.lang.String,java.lang.Object>replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,java.lang.Boolean> blankIfUnexpandedFieldMap, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> inputConverter, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> outputConverter)
Recursively replace data references in the values in a map which contains either string, collection or Map values.static <T extends ViewTraverse<T>>
java.lang.ObjectreplaceDataReferencesInObject(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data)
static <T extends ViewTraverse<T>>
java.lang.ObjectreplaceDataReferencesInObject(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)
static void
replaceTokensInReader(java.io.Reader reader, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName)
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data contextstatic void
replaceTokensInReader(java.io.Reader reader, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom)
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data contextstatic void
replaceTokensInScript(java.lang.String script, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom)
Copies the source file to a file, replacing the @key.X@ tokens with the values from the data contextstatic void
replaceTokensInScript(java.lang.String script, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom)
Copies the source file to a file, replacing the @key.X@ tokens with the values from the data contextstatic void
replaceTokensInStream(java.io.InputStream stream, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom)
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data contextstatic WFSharedContext
sharedContext()
-
-
-
Field Detail
-
PROPERTY_REF_REGEX
public static final java.lang.String PROPERTY_REF_REGEX
- See Also:
- Constant Field Values
-
PROPERTY_VIEW_REF_REGEX
public static final java.lang.String PROPERTY_VIEW_REF_REGEX
- See Also:
- Constant Field Values
-
PROPERTY_REF_PATTERN
public static final java.util.regex.Pattern PROPERTY_REF_PATTERN
-
UNQUOTEDPROPERTY_PREFIX
public static final java.lang.String UNQUOTEDPROPERTY_PREFIX
- See Also:
- Constant Field Values
-
UNQUOTEDPROPERTY_REF_PATTERN
public static final java.util.regex.Pattern UNQUOTEDPROPERTY_REF_PATTERN
-
-
Method Detail
-
outputContext
public static ReadableSharedContext outputContext(ContextView defaultView)
- Returns:
- A new output context
-
sharedContext
public static WFSharedContext sharedContext()
- Returns:
- A new context
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.lang.String[] replaceDataReferences(java.lang.String[] args, MultiDataContext<T,DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, boolean failIfUnexpanded, boolean blankIfUnexpanded)
Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context- Parameters:
args
- input string arraydata
- data context mapconverter
- converter to encode/convert the expanded valuesfailIfUnexpanded
- true to fail if a reference is not foundblankIfUnexpanded
- true to use blank if a reference is not found- Returns:
- string with values substituted, or original string
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.lang.String replaceDataReferences(java.lang.String input, MultiDataContext<T,DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, boolean failOnUnexpanded, boolean blankIfUnexpanded)
Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context- Parameters:
input
- input stringdata
- data context mapconverter
- converter to encode/convert the expanded valuesfailOnUnexpanded
- true to fail if a reference is not foundblankIfUnexpanded
- true to use blank if a reference is not found- Returns:
- string with values substituted, or original string
-
escapeShell
public static java.lang.String escapeShell(java.lang.String s)
Escape characters meaningful to bash shell unless the string is already surrounded in single quotes- Parameters:
s
- string- Returns:
- escaped string
-
escapeWindowsShell
public static java.lang.String escapeWindowsShell(java.lang.String s)
Escape characters meaningful to windows unless the string is already surrounded in single quotes- Parameters:
s
- string- Returns:
- escaped string
-
replaceTokensInScript
public static void replaceTokensInScript(java.lang.String script, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom) throws java.io.IOException
Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context- Parameters:
script
- source file pathdataContext
- input data contextstyle
- line ending styledestination
- destination file, or null to create a temp file- Throws:
java.io.IOException
- on io error
-
replaceTokensInScript
public static void replaceTokensInScript(java.lang.String script, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom) throws java.io.IOException
Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context- Parameters:
script
- source file pathdataContext
- input data contextstyle
- line ending styledestination
- destination file, or null to create a temp file- Throws:
java.io.IOException
- on io error
-
replaceTokensInStream
public static void replaceTokensInStream(java.io.InputStream stream, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom) throws java.io.IOException
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context- Parameters:
stream
- source streamdataContext
- input data contextstyle
- script file line ending style to usedestination
- destination file- Throws:
java.io.IOException
- on io error
-
replaceTokensInReader
public static void replaceTokensInReader(java.io.Reader reader, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName) throws java.io.IOException
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context- Parameters:
reader
- readerdataContext
- input data contextstyle
- script file line ending style to usedestination
- destination file- Throws:
java.io.IOException
- on io error
-
replaceTokensInReader
public static void replaceTokensInReader(java.io.Reader reader, MultiDataContext<ContextView,DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom) throws java.io.IOException
Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context- Parameters:
reader
- readerdataContext
- input data contextstyle
- script file line ending style to usedestination
- destination file- Throws:
java.io.IOException
- on io error
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,java.lang.Object> replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data)
Recursively replace data references in the values in a map which contains either string, collection or Map values.- Parameters:
input
- input mapdata
- context data- Returns:
- Map with all string values having references replaced
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,java.lang.Object> replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)
Recursively replace data references in the values in a map which contains either string, collection or Map values.- Parameters:
input
- input mapdata
- context data- Returns:
- Map with all string values having references replaced
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,java.lang.Object> replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,java.lang.Boolean> blankIfUnexpandedFieldMap)
Recursively replace data references in the values in a map which contains either string, collection or Map values.- Parameters:
input
- input mapdata
- context data- Returns:
- Map with all string values having references replaced
-
replaceDataReferences
public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,java.lang.Object> replaceDataReferences(java.util.Map<java.lang.String,java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,java.lang.Boolean> blankIfUnexpandedFieldMap, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> inputConverter, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> outputConverter)
Recursively replace data references in the values in a map which contains either string, collection or Map values.- Parameters:
input
- input mapdata
- context data- Returns:
- Map with all string values having references replaced
-
replaceDataReferencesInObject
public static <T extends ViewTraverse<T>> java.lang.Object replaceDataReferencesInObject(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data)
-
replaceDataReferencesInObject
public static <T extends ViewTraverse<T>> java.lang.Object replaceDataReferencesInObject(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,java.lang.String,T> viewMap, Converter<java.lang.String,java.lang.String> converter, MultiDataContext<T,DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)
-
-