Package adams.flow.maven.shared
Class FileSystemUtilities
- java.lang.Object
-
- adams.flow.maven.shared.FileSystemUtilities
-
public final class FileSystemUtilities extends Object
The ADAMS Maven Plugin needs to fiddle with the filesystem, to create and optionally prune directories or detect/create various files. This utility class contains all such algorithms, and serves as an entry point to any Plexus Utils methods. Based on jaxb2-maven-plugin code.- Author:
- Lennart Jörelid
-
-
Field Summary
Fields Modifier and Type Field Description static FileFilter
EXISTING_DIRECTORY
FileFilter which accepts Files that exist and for whichFile.isDirectory()
istrue
.static FileFilter
EXISTING_FILE
FileFilter which accepts Files that exist and for whichFile.isFile()
istrue
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
createDirectory(File aDirectory, boolean cleanBeforeCreate)
Convenience method to successfully create a directory - or throw an exception if failing to create it.static File
getCanonicalFile(File file)
Acquires the canonical File for the supplied file.static String
getCanonicalPath(File file)
Acquires the canonical path for the supplied file.static File
getExistingFile(String path, File baseDir)
Retrieves the canonical File matching the supplied path in the following order or priority:static File
getFileFor(URL anURL, String encoding)
Acquires the file for a supplied URL, provided that its protocol is is either a file or a jar.static URL
getUrlFor(File aFile)
Retrieves the URL for the supplied File.
-
-
-
Field Detail
-
EXISTING_FILE
public static final FileFilter EXISTING_FILE
FileFilter which accepts Files that exist and for whichFile.isFile()
istrue
.
-
EXISTING_DIRECTORY
public static final FileFilter EXISTING_DIRECTORY
FileFilter which accepts Files that exist and for whichFile.isDirectory()
istrue
.
-
-
Method Detail
-
getCanonicalPath
public static String getCanonicalPath(File file)
Acquires the canonical path for the supplied file.- Parameters:
file
- A non-null File for which the canonical path should be retrieved.- Returns:
- The canonical path of the supplied file.
-
getCanonicalFile
public static File getCanonicalFile(File file)
Acquires the canonical File for the supplied file.- Parameters:
file
- A non-null File for which the canonical File should be retrieved.- Returns:
- The canonical File of the supplied file.
-
getExistingFile
public static File getExistingFile(String path, File baseDir)
Retrieves the canonical File matching the supplied path in the following order or priority:
- Absolute path: The path is used by itself (i.e.
new File(path);
). If an existing file or directory matches the provided path argument, its canonical path will be returned. - Relative path: The path is appended to the baseDir (i.e.
new File(baseDir, path);
). If an existing file or directory matches the provided path argument, its canonical path will be returned. Only in this case will be baseDir argument be considered.
If no file or directory could be derived from the supplied path and baseDir,
null
is returned.- Parameters:
path
- A non-null path which will be used to find an existing file or directory.baseDir
- A directory to which the path will be appended to search for the existing file or directory in case the file was nonexistent when interpreted as an absolute path.- Returns:
- either a canonical File for the path, or
null
if no file or directory matched the supplied path and baseDir.
- Absolute path: The path is used by itself (i.e.
-
getUrlFor
public static URL getUrlFor(File aFile) throws IllegalArgumentException
Retrieves the URL for the supplied File. Convenience method which hides exception handling for the operation in question.- Parameters:
aFile
- A File for which the URL should be retrieved.- Returns:
- The URL for the supplied aFile.
- Throws:
IllegalArgumentException
- if getting the URL yielded a MalformedURLException.
-
getFileFor
public static File getFileFor(URL anURL, String encoding)
Acquires the file for a supplied URL, provided that its protocol is is either a file or a jar.- Parameters:
anURL
- a non-null URL.encoding
- The encoding to be used by the URLDecoder to decode the path found.- Returns:
- The File pointing to the supplied URL, for file or jar protocol URLs and null otherwise.
-
createDirectory
public static void createDirectory(File aDirectory, boolean cleanBeforeCreate) throws org.apache.maven.plugin.MojoExecutionException
Convenience method to successfully create a directory - or throw an exception if failing to create it.- Parameters:
aDirectory
- The directory to create.cleanBeforeCreate
- iftrue
, the directory and all its content will be deleted before being re-created. This will ensure that the created directory is really clean.- Throws:
org.apache.maven.plugin.MojoExecutionException
- if the aDirectory could not be created (and/or cleaned).
-
-