Package hudson.plugins.collabnet.util
Class CommonUtil
- java.lang.Object
-
- hudson.plugins.collabnet.util.CommonUtil
-
public class CommonUtil extends Object
Class for methods that are useful across Jenkins plugins.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean
getBoolean(String key, net.sf.json.JSONObject formData)
Returns true if the string value of the key in the form is "true".static String
getInterpreted(Map<String,String> envVars, String str)
Translates a string that may contain build vars like ${BUILD_VAR} to a string with those vars interpreted.static boolean
isEmpty(String str)
Determine whether a string is "empty", meaning is null or empty.static void
logRE(Logger logger, String methodName, IOException re)
Convenience method to log RemoteExceptions.static Collection<String>
sanitizeForJS(Collection<String> collection)
Deprecated.static List<String>
splitCommaStr(String commaStr)
Given a comma-delimited string, split it into an array of strings, removing unneccessary whitespace.static String
stripSlashes(String str)
String leading and trailing '/'s from a String.static boolean
unset(String value)
-
-
-
Method Detail
-
getBoolean
public static boolean getBoolean(String key, net.sf.json.JSONObject formData)
Returns true if the string value of the key in the form is "true". If it's missing, returns false.- Parameters:
key
- to find value for.formData
- that holds key/value.- Returns:
- true if the string value of this key is "true".
-
getInterpreted
public static String getInterpreted(Map<String,String> envVars, String str)
Translates a string that may contain build vars like ${BUILD_VAR} to a string with those vars interpreted.- Parameters:
envVars
- the Jenkins build env variables map.str
- the string to be interpreted.- Returns:
- the interpreted string.
- Throws:
IllegalArgumentException
- if the env var is not found.
-
logRE
public static void logRE(Logger logger, String methodName, IOException re)
Convenience method to log RemoteExceptions.- Parameters:
logger
- to log this message to.methodName
- in progress on when this exception occurred.re
- The RemoteException that was thrown.
-
sanitizeForJS
@Deprecated public static Collection<String> sanitizeForJS(Collection<String> collection)
Deprecated.Escape characters that may make javascript error (like quotes or backslashes).- Parameters:
collection
- list of strings to sanitize- Returns:
- collection of sanitized strings.
-
stripSlashes
public static String stripSlashes(String str)
String leading and trailing '/'s from a String.- Parameters:
str
- string to strip.- Returns:
- string without leading or trailing '/'s.
-
unset
public static boolean unset(String value)
- Parameters:
value
- string to test.- Returns:
- true if a String value is null or empty.
-
splitCommaStr
public static List<String> splitCommaStr(String commaStr)
Given a comma-delimited string, split it into an array of strings, removing unneccessary whitespace. Also will remove empty values (i.e. only whitespace).- Parameters:
commaStr
- comma-delimited string- Returns:
- an array of the strings, with leading and trailing whitespace removed.
-
isEmpty
public static boolean isEmpty(String str)
Determine whether a string is "empty", meaning is null or empty.- Parameters:
str
- string in question- Returns:
- true if empty
-
-