org.jclouds.scriptbuilder.util
Class Utils

java.lang.Object
  extended by org.jclouds.scriptbuilder.util.Utils

public class Utils
extends Object

Utilities used to build init scripts.

Author:
Adrian Cole

Nested Class Summary
static class Utils.FunctionNotFoundException
           
static class Utils.LowerCamelToUpperUnderscore
           
static class Utils.UpperUnderscoreToLowerCamel
           
 
Field Summary
static Utils.LowerCamelToUpperUnderscore FUNCTION_LOWER_CAMEL_TO_UPPER_UNDERSCORE
           
static Utils.UpperUnderscoreToLowerCamel FUNCTION_UPPER_UNDERSCORE_TO_LOWER_CAMEL
           
static Map<OsFamily,String> OS_TO_LOCAL_VAR_PATTERN
           
static Map<OsFamily,String> OS_TO_POSITIONAL_VAR_PATTERN
           
static Map<OsFamily,String> OS_TO_ZERO_PATH
           
 
Constructor Summary
Utils()
           
 
Method Summary
static String replaceTokens(String input, Map<String,String> replacements)
          replaces tokens that are expressed as {token}

ex.

static String writeComment(String comment, OsFamily family)
           
static String writeFunction(String function, String source)
           
static String writeFunction(String function, String source, OsFamily family)
           
static String writeFunctionFromResource(String function, OsFamily family)
           
static String writePositionalVars(List<String> positionalVariablesInLowerCamelCase, OsFamily family)
          Writes an initialization statement for use inside a script or a function.
static String writeUnsetVariables(List<String> variablesInLowerCamelCase, OsFamily family)
          Ensures that variables come from a known source instead of bleeding in from a profile
static String writeVariableExporters(Map<String,String> variablesInLowerCamelCase)
          converts a map into variable exporters in shell intermediate language.
static String writeVariableExporters(Map<String,String> variablesInLowerCamelCase, OsFamily family)
          converts a map into variable exports relevant to the specified platform.
static String writeZeroPath(OsFamily family)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FUNCTION_LOWER_CAMEL_TO_UPPER_UNDERSCORE

public static final Utils.LowerCamelToUpperUnderscore FUNCTION_LOWER_CAMEL_TO_UPPER_UNDERSCORE

FUNCTION_UPPER_UNDERSCORE_TO_LOWER_CAMEL

public static final Utils.UpperUnderscoreToLowerCamel FUNCTION_UPPER_UNDERSCORE_TO_LOWER_CAMEL

OS_TO_POSITIONAL_VAR_PATTERN

public static final Map<OsFamily,String> OS_TO_POSITIONAL_VAR_PATTERN

OS_TO_LOCAL_VAR_PATTERN

public static final Map<OsFamily,String> OS_TO_LOCAL_VAR_PATTERN

OS_TO_ZERO_PATH

public static final Map<OsFamily,String> OS_TO_ZERO_PATH
Constructor Detail

Utils

public Utils()
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 replace
replacements - token/value pairs

writeVariableExporters

public static String writeVariableExporters(Map<String,String> variablesInLowerCamelCase,
                                            OsFamily family)
converts a map into variable exports relevant to the specified platform.

ex. if variablesInLowerCamelCase is "mavenOpts" -> "-Xms64m -Xmx256m"
and family is UNIX
then writeVariableExporters returns literally export MAVEN_OPTS="-Xms64m -Xmx256m"\n

Parameters:
variablesInLowerCamelCase - lower camel keys to values
family - operating system for formatting

writeVariableExporters

public static String writeVariableExporters(Map<String,String> variablesInLowerCamelCase)
converts a map into variable exporters in shell intermediate language.

Parameters:
variablesInLowerCamelCase - lower camel keys to values

writeFunction

public static String writeFunction(String function,
                                   String source,
                                   OsFamily family)

writeFunctionFromResource

public static String writeFunctionFromResource(String function,
                                               OsFamily family)

writeFunction

public static String writeFunction(String function,
                                   String source)

writePositionalVars

public static String writePositionalVars(List<String> positionalVariablesInLowerCamelCase,
                                         OsFamily family)
Writes an initialization statement for use inside a script or a function.

Parameters:
positionalVariablesInLowerCamelCase - - 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(List<String> variablesInLowerCamelCase,
                                         OsFamily family)
Ensures that variables come from a known source instead of bleeding in from a profile

Parameters:
variablesInLowerCamelCase - - System variables to unset

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.

writeComment

public static String writeComment(String comment,
                                  OsFamily family)


Copyright © 2009-2012 jclouds. All Rights Reserved.