Class Common
- java.lang.Object
-
- org.thoughtslive.jenkins.plugins.hubot.util.Common
-
public class Common extends Object
Common utility functions.- Author:
- Naresh Rayapati
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommon.STEP
-
Constructor Summary
Constructors Constructor Description Common()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> ResponseData<T>buildErrorResponse(Exception e)Builds error response from the given exception.static MapexpandMacros(String tokens, Run<?,?> run, FilePath ws, TaskListener listener)Expands given macro, see Token Marco plugin.static StringgetBuildNumber(PrintStream logger, EnvVars envVars)Returns build number from the given Environment Vars.static StringgetJobName(EnvVars envVars)static ThrowablegetRootCause(Throwable throwable)Returns actual Cause from the given exception.static voidlog(PrintStream logger, Object message)Write a message to the given print stream.static <T> ResponseData<T>logResponse(ResponseData<T> response, PrintStream logger, boolean failOnError)Log code and error message if any.static <T> ResponseData<T>parseResponse(retrofit2.Response<T> response)Converts Retrofit'sResponsetoResponseDatastatic StringprepareBuildCause(List<Cause> causes)Retrun the build cause.static StringprepareBuildUserId(List<Cause> causes, EnvVars envVars)Return the current build user Id.static StringprepareBuildUserName(List<Cause> causes, EnvVars envVars)Return the current build user.static StringsanitizeURL(String url)Attaches the "/" at end of given url.
-
-
-
Method Detail
-
sanitizeURL
public static String sanitizeURL(String url)
Attaches the "/" at end of given url.- Parameters:
url- url as a string.- Returns:
- url which ends with "/"
-
log
public static void log(PrintStream logger, Object message)
Write a message to the given print stream.- Parameters:
logger-PrintStreammessage- to log.
-
getBuildNumber
public static String getBuildNumber(PrintStream logger, EnvVars envVars)
Returns build number from the given Environment Vars.- Parameters:
logger-PrintStreamenvVars-EnvVars- Returns:
- build number of current job.
-
parseResponse
public static <T> ResponseData<T> parseResponse(retrofit2.Response<T> response) throws IOException
Converts Retrofit'sResponsetoResponseData- Parameters:
response- instance ofResponse- Returns:
- an instance of
ResponseData - Throws:
IOException
-
buildErrorResponse
public static <T> ResponseData<T> buildErrorResponse(Exception e)
Builds error response from the given exception.- Parameters:
e- instance ofException- Returns:
- an instance of
ResponseData
-
getRootCause
public static Throwable getRootCause(Throwable throwable)
Returns actual Cause from the given exception.- Returns:
Throwable
-
prepareBuildUserName
public static String prepareBuildUserName(List<Cause> causes, EnvVars envVars)
Return the current build user.- Parameters:
causes- build causes.envVars- environment variables.- Returns:
- user name.
-
prepareBuildCause
public static String prepareBuildCause(List<Cause> causes)
Retrun the build cause.- Returns:
- build cause.
-
prepareBuildUserId
public static String prepareBuildUserId(List<Cause> causes, EnvVars envVars)
Return the current build user Id.- Parameters:
causes- build causes.envVars- environment variables.- Returns:
- user name.
-
expandMacros
public static Map expandMacros(String tokens, Run<?,?> run, FilePath ws, TaskListener listener)
Expands given macro, see Token Marco plugin.
-
logResponse
public static <T> ResponseData<T> logResponse(ResponseData<T> response, PrintStream logger, boolean failOnError) throws AbortException
Log code and error message if any.- Returns:
- response data.
- Throws:
AbortException
-
-