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 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 List<File> |
getResourceDirs(org.apache.maven.project.MavenProject project)
Returns a list with all resource directories of a given Maven project.
|
static Document |
parse(File file)
Parses a given xml file into a
Document. |
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. |
@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 FileNotFoundException, 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 List<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, FileNotFoundException
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 © 2021. All rights reserved.