Package com.piketec.jenkins.plugins.tpt
Class Utils
- java.lang.Object
-
- com.piketec.jenkins.plugins.tpt.Utils
-
public class Utils extends java.lang.Object
Collection of some utility methods and constants- Author:
- jkuhnert, PikeTec GmbH
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkId(JenkinsConfiguration ec, Run<?,?> build, TptLogger logger)
Check for duplicate ID of already finished JenkinsConfiguration.static boolean
checkIdAndAddInvisibleActionTPTExecution(JenkinsConfiguration resolvedConfig, Run<?,?> build, TptLogger logger)
Check for duplicate ID of already finished JenkinsConfiguration.static void
copyRecursive(FilePath from, FilePath to, TptLogger logger)
Copies all files from a remote location to another remote location.static void
deleteFiles(FilePath path)
TPT changes its workind directory during execution, fails to set it back correctly after multicore execution and prevents the deletion of test data directory.static java.io.File
getAbsolutePath(java.io.File workspaceDir, java.io.File path)
Builds a absolute path from the workspace directory and the given path.static EnvVars
getEnvironment(AbstractBuild<?,?> build, Launcher launcher, TptLogger logger)
Get the environment variables for a build.static java.lang.String
getGeneratedReportDir(JenkinsConfiguration ec)
Creates a String with a path to create for the report dir.static java.lang.String
getGeneratedTestDataDir(JenkinsConfiguration ec)
Creates a String with a path to create for the test data dir.static java.util.List<InvisibleActionTPTExecution>
getInvisibleActionTPTExecutions(Run<?,?> build)
Get all InvisibleActionTPTExecution of a build.static java.io.File
getTptPluginRootDir()
static boolean
isValidWidnowsFileName(java.lang.String name)
Checks if name does not contain a lien break, <, >, :, \, ", /, \, |, ?, * nor matches any of the reserved names CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.static java.util.List<java.lang.String>
parseCommandLine(java.lang.String toProcess)
Translates a command line String to seperate arguments usingCommandline.translateCommandline(String)
.static <T> java.lang.String
toString(java.util.Collection<T> list, java.lang.String delimeter)
Transforms the list into a String by calling toString() on every item, seperating them by the givendelimeter
-
-
-
Method Detail
-
getGeneratedTestDataDir
public static java.lang.String getGeneratedTestDataDir(JenkinsConfiguration ec)
Creates a String with a path to create for the test data dir. This will be relative to the build workspace- Parameters:
ec
- through the jenkins configuration we get the id of the configuration, which is used to create a unique path.- Returns:
- a String with the folders for the test data dir.
-
getGeneratedReportDir
public static java.lang.String getGeneratedReportDir(JenkinsConfiguration ec)
Creates a String with a path to create for the report dir. This will be relative to the build workspace- Parameters:
ec
- through the jenkins configuration we get the id of the configuration, which is used to create a unique path.- Returns:
- a String with the folders for the report dir.
-
getTptPluginRootDir
public static java.io.File getTptPluginRootDir() throws java.io.IOException
- Returns:
- the rootdir from the "piketec-tpt" plugin, used for knowing where to get html files, json or some data stored there.
- Throws:
java.io.IOException
- If no Jenkins isntance could be found
-
getAbsolutePath
public static java.io.File getAbsolutePath(java.io.File workspaceDir, java.io.File path)
Builds a absolute path from the workspace directory and the given path.- If both are
null
, the current working directory will returned - hopefully it is inside the workspace. - If the workspace is
null
, the path will returned. - If the path is
null
, the workspace will returned. - If the path is absolute, the path will returned.
- If the path is relative, the path will append to the workspace and returned.
- Parameters:
workspaceDir
- Current workspace for the build.path
- Relative or absolute path.- Returns:
- A absolute path, but it can be a nonexisting file system object or not a directory.
- If both are
-
toString
public static <T> java.lang.String toString(java.util.Collection<T> list, java.lang.String delimeter)
Transforms the list into a String by calling toString() on every item, seperating them by the givendelimeter
- Type Parameters:
T
- The types of items contained in the list- Parameters:
list
- The list to tranform to Stringdelimeter
- The sting seperating the items- Returns:
- The list represneted as a string
-
deleteFiles
public static void deleteFiles(FilePath path) throws java.io.IOException, java.lang.InterruptedException
TPT changes its workind directory during execution, fails to set it back correctly after multicore execution and prevents the deletion of test data directory. This method only deletes the files in a directory recursively ifFilePath.deleteContents()
fails. Also TPT may keep tptbin-Files open for some Time in a cache, so we will retry more often to delete the files than the standard implementation.- Parameters:
path
- The paths to delete- Throws:
java.io.IOException
- If path could not be deletedjava.lang.InterruptedException
- If thread was interrupted
-
copyRecursive
public static void copyRecursive(FilePath from, FilePath to, TptLogger logger) throws java.io.IOException, java.lang.InterruptedException
Copies all files from a remote location to another remote location. FilePath.copyRecursiveTo is not able to do that. See https://issues.jenkins-ci.org/browse/JENKINS-2126- Parameters:
from
- Target pathto
- Source pathlogger
- for dumping messages- Throws:
java.io.IOException
- If an IO error occursjava.lang.InterruptedException
- If thread was interrupted
-
isValidWidnowsFileName
public static boolean isValidWidnowsFileName(java.lang.String name)
Checks if name does not contain a lien break, <, >, :, \, ", /, \, |, ?, * nor matches any of the reserved names CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.- Parameters:
name
- The name to check- Returns:
true
if the name can be used as a windows file name
-
getEnvironment
public static EnvVars getEnvironment(AbstractBuild<?,?> build, Launcher launcher, TptLogger logger) throws java.lang.InterruptedException
Get the environment variables for a build. In pipeline all strings should be handled as litereals and replacing is dones by Groovy so we do not acceptRun
here.- Parameters:
build
- The build.launcher
- The launcherlogger
- for dumping messages- Returns:
- the environment variables from the agent machine the code is running on
- Throws:
java.lang.InterruptedException
- If thread was interrupted
-
getInvisibleActionTPTExecutions
public static java.util.List<InvisibleActionTPTExecution> getInvisibleActionTPTExecutions(Run<?,?> build)
Get all InvisibleActionTPTExecution of a build.- Parameters:
build
- The build to get the InvisibleActionTPTExecution list from- Returns:
- The list of InvisibleActionTPTExecution
-
checkIdAndAddInvisibleActionTPTExecution
public static boolean checkIdAndAddInvisibleActionTPTExecution(JenkinsConfiguration resolvedConfig, Run<?,?> build, TptLogger logger)
Check for duplicate ID of already finished JenkinsConfiguration. Adds an InvisibleActionTPTExecution if ID is valid. Is synchronized to ensure that parallel parts of a pipeline using the same ID leads to a failure. Method is not heavily used, so staic synchronized is feasible.- Parameters:
resolvedConfig
- JenkinsConfiguration with IDbuild
- Build that executes the JenkinsConfiguration and may already have executed other JenkinsConfiguration wich must have a different ID.logger
- to write an error message to- Returns:
true
if the ID is unique and a valid windows file name
-
checkId
public static boolean checkId(JenkinsConfiguration ec, Run<?,?> build, TptLogger logger)
Check for duplicate ID of already finished JenkinsConfiguration.- Parameters:
ec
- JenkinsConfiguration with IDbuild
- Build that executes the JenkinsConfiguration and may already have executed other JenkinsConfiguration wich must have a different ID.logger
- to write an error message to- Returns:
true
if the ID is unique and a valid windows file name
-
parseCommandLine
public static java.util.List<java.lang.String> parseCommandLine(java.lang.String toProcess)
Translates a command line String to seperate arguments usingCommandline.translateCommandline(String)
.- Returns:
- a fixed-size list backed by the command line array
-
-