Package org.jclouds.scriptbuilder.util
Class Utils
- java.lang.Object
-
- org.jclouds.scriptbuilder.util.Utils
-
public class Utils extends Object
Utilities used to build init scripts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtils.VariableNameForOsFamilyInShellToken, the values whose names end in_VARIABLEdesignate variable names we know how to translate from one platform to another.
-
Field Summary
Fields Modifier and Type Field Description static Map<OsFamily,String>OS_TO_LOCAL_VAR_PATTERNstatic Map<OsFamily,String>OS_TO_POSITIONAL_VAR_PATTERNstatic Map<OsFamily,String>OS_TO_ZERO_PATH
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringreplaceTokens(String input, Map<String,String> replacements)replaces tokens that are expressed as{token}static <K1,K2,V>
Map<K2,V>transformKeys(Map<K1,V> in, com.google.common.base.Function<K1,K2> fn)change the keys but keep the values in-tact.static StringwriteComment(String comment, OsFamily family)static StringwriteFunction(String function, String source)static StringwriteFunction(String function, String source, OsFamily family)static StringwriteFunctionFromResource(String function, OsFamily family)static StringwritePositionalVars(Iterable<String> positionalVariables, OsFamily family)Writes an initialization statement for use inside a script or a function.static StringwriteUnsetVariables(Iterable<String> variablesToUnset, OsFamily family)Ensures that variables come from a known source instead of bleeding in from a profilestatic StringwriteVariableExporters(Map<String,String> exports)converts a map into variable exporters in shell intermediate language.static StringwriteVariableExporters(Map<String,String> exports, OsFamily family)converts a map into variable exports relevant to the specified platform.static StringwriteZeroPath(OsFamily family)
-
-
-
Method Detail
-
replaceTokens
public static String replaceTokens(String input, Map<String,String> replacements)
replaces tokens that are expressed as{token}ex. if input is "hello {where}"
and replacements is "where" -> "world"
then replaceTokens returns "hello world"- Parameters:
input- source to replacereplacements- token/value pairs
-
writeVariableExporters
public static String writeVariableExporters(Map<String,String> exports, OsFamily family)
converts a map into variable exports relevant to the specified platform. ex. ifkeysis the map: "MAVEN_OPTS" -> "-Xms64m -Xmx256m"
and family is UNIX
then writeVariableExporters returns literallyexport MAVEN_OPTS="-Xms64m -Xmx256m"\n- Parameters:
exports- keys are the variables to export in UPPER_UNDERSCORE case formatfamily- operating system for formatting- See Also:
Utils.VariableNameForOsFamily
-
writeVariableExporters
public static String writeVariableExporters(Map<String,String> exports)
converts a map into variable exporters in shell intermediate language.- Parameters:
exports- keys are the variables to export in UPPER_UNDERSCORE case format
-
writeFunctionFromResource
public static String writeFunctionFromResource(String function, OsFamily family)
-
writePositionalVars
public static String writePositionalVars(Iterable<String> positionalVariables, OsFamily family)
Writes an initialization statement for use inside a script or a function.- Parameters:
positionalVariables- - transfer the value of args into these statements. Note that there is no check to ensure that all source args are indeed present.
-
writeUnsetVariables
public static String writeUnsetVariables(Iterable<String> variablesToUnset, OsFamily family)
Ensures that variables come from a known source instead of bleeding in from a profile- Parameters:
variablesToUnset- - System variables to unset- See Also:
Utils.VariableNameForOsFamily
-
writeZeroPath
public static String writeZeroPath(OsFamily family)
- Returns:
- line used to zero out the path of the script such that basic commands such as unix ps will work.
-
transformKeys
public static <K1,K2,V> Map<K2,V> transformKeys(Map<K1,V> in, com.google.common.base.Function<K1,K2> fn)
change the keys but keep the values in-tact.- Type Parameters:
K1- input key typeK2- output key typeV- value type- Parameters:
in- input map to transformfn- how to transform the values- Returns:
- immutableMap with the new keys.
-
-