Package com.sap.cds.maven.plugin.util
Class Utils
java.lang.Object
com.sap.cds.maven.plugin.util.Utils
A helper class providing utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
array
(T... arguments) Creates an array with given argumentsstatic File
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.getResourceDirs
(org.apache.maven.project.MavenProject project) Returns a stream with all resource directories of a given Maven project.static Document
Parses a given xml file into aDocument
.parseCdsdkVersionOutput
(String cdsdkVersionOutput) Parses the givencds version
console output and returns aMap
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 givenRunnable
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'tnull
.static String[]
splitByWhitespaces
(String string) Splits the given string into tokens by using whitespace as delimiters.static void
Serializes a givenDocument
into a file.
-
Method Details
-
decryptServer
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) -
parseCdsdkVersionOutput
Parses the givencds version
console output and returns aMap
filled with cds component name as key and version information as value.- Parameters:
cdsdkVersionOutput
- the console output of command linecds version
- Returns:
- a
Map
filled with component name as key and version information as value.
-
array
Creates an array with given arguments- Parameters:
arguments
- the array elements- Returns:
- the string array containing given arguments
-
createDir
Creates a directory including all parent directories.- Parameters:
dirPath
- the directory path- Returns:
- the created directory
- Throws:
IOException
- if the directory can’t be created or the file already exists but isn’t a directory
-
createFile
Creates a file including all parent directories.- Parameters:
file
- the file to created- Returns:
- the created file
- Throws:
IOException
- if the file can’t be created
-
findDirectory
- Parameters:
roots
- start directories for finding the directorydirectoryName
- the glob directory name pattern- Returns:
- the file or
null
if not found - Throws:
IOException
- if an I/O error occurred while finding the file
-
findExecutable
Finds the location of given executable on local file-system.- Parameters:
execName
- name of executable to findlogger
- a logger instance- Returns:
- a
File
representing the found executable ornull
if not found - Throws:
IOException
- if an I/O error occurred during searchFileNotFoundException
- if executable couldn't be found
-
findFile
- Parameters:
roots
- start directories for finding the directoryfileName
- the glob file name pattern- Returns:
- the file or
null
if not found - Throws:
IOException
- if an I/O error occurred while finding the file
-
getPackageDir
Returns the directory for a given Java package.- Parameters:
srcBaseDir
- the source base directorypackageName
- the package- Returns:
- the package directory
-
getResourceDirs
Returns a stream with all resource directories of a given Maven project.- Parameters:
project
- the Maven project- Returns:
- a stream with all resource directories
-
parse
public static Document parse(File file) throws ParserConfigurationException, SAXException, IOException Parses a given xml file into aDocument
.- Parameters:
file
- the xml file to parse- Returns:
- the parsed
Document
- Throws:
ParserConfigurationException
- if a DocumentBuilder can’t be created which satisfies the configuration requested.IOException
- If any IO errors occur.SAXException
- If any parse errors occur.
-
prepareDestination
- Parameters:
destination
- the destination to preparedirectory
- if given destination is a directory- Returns:
- given destination file
- Throws:
IOException
- if preparing failed
-
runIfLockable
Runs the givenRunnable
if a lock could be acquired on given file.- Parameters:
lockFile
- theFile
used for synchronisationrunnable
- theRunnable
to execute when lock could be acquiredmaxWait
- max. time to wait in seconds to acquire lock- Throws:
IOException
- if lock couldn't be acquired in given max. wait time
-
setExecutionFlag
Sets execution flag at given file.- Parameters:
file
- the file- Throws:
IOException
- if setting execution flag failedFileNotFoundException
- if file wasn't found
-
setIfNotNull
Calls a given setter with given value, if value isn'tnull
.- Type Parameters:
T
- type of value to set- Parameters:
setter
- the setter to callvalue
- the value to set
-
splitByWhitespaces
Splits the given string into tokens by using whitespace as delimiters.- Parameters:
string
- the string to be split into tokens- Returns:
- the tokens
-
store
public static void store(File file, Document doc) throws TransformerFactoryConfigurationError, TransformerException Serializes a givenDocument
into a file.- Parameters:
file
- the target filedoc
- theDocument
to store- Throws:
TransformerFactoryConfigurationError
- if the XML serializer can't be createdTransformerException
- if serialization to XML failed
-