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 FileCreates a directory including all parent directories.static FilecreateFile(File file) Creates a file including all parent directories.static org.apache.maven.settings.ServerdecryptServer(String serverId, org.apache.maven.execution.MavenSession mavenSession, org.apache.maven.settings.crypto.SettingsDecrypter decrypter, CdsMojoLogger logger) static FilefindDirectory(String directoryName, Collection<File> roots) static FilefindExecutable(String execName, CdsMojoLogger logger) Finds the location of given executable on local file-system.static FilefindFile(String fileName, Collection<File> roots) static FilegetPackageDir(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 DocumentParses a given xml file into aDocument.parseCdsdkVersionOutput(String cdsdkVersionOutput) Parses the givencds versionconsole output and returns aMapfilled with cds component name as key and version information as value.static FileprepareDestination(File destination, boolean directory) static voidrunIfLockable(File lockFile, Runnable runnable, int maxWait) Runs the givenRunnableif a lock could be acquired on given file.static voidsetExecutionFlag(File file) Sets execution flag at given file.static <T> voidsetIfNotNull(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 voidSerializes a givenDocumentinto a file.static voidstore(OutputStream out, Document doc) Serializes a givenDocumentinto an output stream.
-
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 versionconsole output and returns aMapfilled with cds component name as key and version information as value.- Parameters:
cdsdkVersionOutput- the console output of command linecds version- Returns:
- a
Mapfilled 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
nullif 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
Filerepresenting the found executable ornullif 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
nullif 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 givenRunnableif a lock could be acquired on given file.- Parameters:
lockFile- theFileused for synchronisationrunnable- theRunnableto 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, IOException Serializes a givenDocumentinto a file.- Parameters:
file- the target filedoc- theDocumentto store- Throws:
TransformerFactoryConfigurationError- if the XML serializer can't be createdTransformerException- if serialization to XML failedIOException- if an I/O error occurred
-
store
public static void store(OutputStream out, Document doc) throws TransformerFactoryConfigurationError, TransformerException Serializes a givenDocumentinto an output stream.- Parameters:
out- the target output streamdoc- theDocumentto store- Throws:
TransformerFactoryConfigurationError- if the XML serializer can't be createdTransformerException- if serialization to XML failed
-