public class Utils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
array(T... arguments)
Creates an array with given arguments
|
static File |
createDir(String dirPath)
Creates a directory including all parent directories.
|
static File |
createFile(File file)
Creates a file including all parent directories.
|
static org.apache.maven.settings.Server |
decryptServer(String serverId,
org.apache.maven.execution.MavenSession mavenSession,
org.apache.maven.settings.crypto.SettingsDecrypter decrypter,
CdsMojoLogger logger) |
static File |
findDirectory(String directoryName,
Collection<File> roots) |
static File |
findExecutable(String execName,
CdsMojoLogger logger)
Finds the location of given executable on local file-system.
|
static File |
findFile(String fileName,
Collection<File> roots) |
static File |
getPackageDir(File srcBaseDir,
String packageName)
Returns the directory for a given Java package.
|
static Stream<File> |
getResourceDirs(org.apache.maven.project.MavenProject project)
Returns a stream with all resource directories of a given Maven project.
|
static Document |
parse(File file)
Parses a given xml file into a
Document. |
static Map<String,String> |
parseCdsdkVersionOutput(String cdsdkVersionOutput)
Parses the given
cds version console output and returns a Map filled with cds component name as
key and version information as value. |
static File |
prepareDestination(File destination,
boolean directory) |
static void |
runIfLockable(File lockFile,
Runnable runnable,
int maxWait)
Runs the given
Runnable if a lock could be acquired on given file. |
static void |
setExecutionFlag(File file)
Sets execution flag at given file.
|
static <T> void |
setIfNotNull(Consumer<T> setter,
T value)
Calls a given setter with given value, if value isn't
null. |
static String[] |
splitByWhitespaces(String string)
Splits the given string into tokens by using whitespace as delimiters.
|
static void |
store(File file,
Document doc)
Serializes a given
Document into a file. |
public static org.apache.maven.settings.Server decryptServer(String serverId, org.apache.maven.execution.MavenSession mavenSession, org.apache.maven.settings.crypto.SettingsDecrypter decrypter, CdsMojoLogger logger)
public static Map<String,String> parseCdsdkVersionOutput(String cdsdkVersionOutput)
cds version console output and returns a Map filled with cds component name as
key and version information as value.cdsdkVersionOutput - the console output of command line cds versionMap filled with component name as key and version information as value.@SafeVarargs public static <T> T[] array(T... arguments)
arguments - the array elementspublic static File createDir(String dirPath) throws IOException
dirPath - the directory pathIOException - if the directory can’t be created or the file already exists but isn’t a directorypublic static File createFile(File file) throws IOException
file - the file to createdIOException - if the file can’t be createdpublic static File findDirectory(String directoryName, Collection<File> roots) throws IOException
roots - start directories for finding the directorydirectoryName - the glob directory name patternnull if not foundIOException - if an I/O error occurred while finding the filepublic static File findExecutable(String execName, CdsMojoLogger logger) throws IOException
execName - name of executable to findlogger - a logger instanceFile representing the found executable or null if not foundIOException - if an I/O error occurred during searchFileNotFoundException - if executable couldn't be foundpublic static File findFile(String fileName, Collection<File> roots) throws IOException
roots - start directories for finding the directoryfileName - the glob file name patternnull if not foundIOException - if an I/O error occurred while finding the filepublic static File getPackageDir(File srcBaseDir, String packageName)
srcBaseDir - the source base directorypackageName - the packagepublic static Stream<File> getResourceDirs(org.apache.maven.project.MavenProject project)
project - the Maven projectpublic static Document parse(File file) throws ParserConfigurationException, SAXException, IOException
Document.file - the xml file to parseDocumentParserConfigurationException - if a DocumentBuilder can’t be created which satisfies the configuration
requested.IOException - If any IO errors occur.SAXException - If any parse errors occur.public static File prepareDestination(File destination, boolean directory) throws IOException
destination - the destination to preparedirectory - if given destination is a directoryIOException - if preparing failedpublic static void runIfLockable(File lockFile, Runnable runnable, int maxWait) throws IOException
Runnable if a lock could be acquired on given file.lockFile - the File used for synchronisationrunnable - the Runnable to execute when lock could be acquiredmaxWait - max. time to wait in seconds to acquire lockIOException - if lock couldn't be acquired in given max. wait timepublic static void setExecutionFlag(File file) throws IOException
file - the fileIOException - if setting execution flag failedFileNotFoundException - if file wasn't foundpublic static <T> void setIfNotNull(Consumer<T> setter, T value)
null.T - type of value to setsetter - the setter to callvalue - the value to setpublic static String[] splitByWhitespaces(String string)
string - the string to be split into tokenspublic static void store(File file, Document doc) throws TransformerFactoryConfigurationError, TransformerException
Document into a file.file - the target filedoc - the Document to storeTransformerFactoryConfigurationError - if the XML serializer can't be createdTransformerException - if serialization to XML failedCopyright © 2023. All rights reserved.