Package com.piketec.jenkins.plugins.tpt
Class Utils
- java.lang.Object
-
- com.piketec.jenkins.plugins.tpt.Utils
-
public class Utils extends 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 File
getAbsolutePath(File workspaceDir, 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 String
getGeneratedReportDir(JenkinsConfiguration ec)
Creates a String with a path to create for the report dir.static String
getGeneratedTestDataDir(JenkinsConfiguration ec)
Creates a String with a path to create for the test data dir.static List<InvisibleActionTPTExecution>
getInvisibleActionTPTExecutions(Run<?,?> build)
Get all InvisibleActionTPTExecution of a build.static File
getTptPluginRootDir()
static boolean
isValidWidnowsFileName(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 List<String>
parseCommandLine(String toProcess)
Translates a command line String to seperate arguments usingCommandline.translateCommandline(String)
.static <T> String
toString(Collection<T> list, String delimeter)
Transforms the list into a String by calling toString() on every item, seperating them by the givendelimeter
-
-
-
Method Detail
-
getGeneratedTestDataDir
public static 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 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 File getTptPluginRootDir() throws IOException
- Returns:
- the rootdir from the "piketec-tpt" plugin, used for knowing where to get html files, json or some data stored there.
- Throws:
IOException
- If no Jenkins isntance could be found
-
getAbsolutePath
public static File getAbsolutePath(File workspaceDir, 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> String toString(Collection<T> list, 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 IOException, 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:
IOException
- If path could not be deletedInterruptedException
- If thread was interrupted
-
copyRecursive
public static void copyRecursive(FilePath from, FilePath to, TptLogger logger) throws IOException, 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:
IOException
- If an IO error occursInterruptedException
- If thread was interrupted
-
isValidWidnowsFileName
public static boolean isValidWidnowsFileName(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 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:
InterruptedException
- If thread was interrupted
-
getInvisibleActionTPTExecutions
public static 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
-
-