public final class FileSystemUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static FileFilter |
EXISTING_DIRECTORY
FileFilter which accepts Files that exist and for which
File.isDirectory() is true . |
static FileFilter |
EXISTING_FILE
FileFilter which accepts Files that exist and for which
File.isFile() is true . |
Modifier and Type | Method and 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 List<URL> |
filterFiles(File baseDir,
List<String> sources,
List<String> standardDirectories,
org.apache.maven.plugin.logging.Log log,
String fileTypeDescription,
List<Filter<File>> excludePatterns)
Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given),
and retrieves a List holding those files that do not match any of the supplied Java Regular Expression
excludePatterns.
|
static List<File> |
filterFiles(File baseDir,
List<String> sources,
String standardDirectory,
org.apache.maven.plugin.logging.Log log,
String fileTypeDescription,
List<Filter<File>> excludeFilters)
Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given),
and retrieves a List holding those files that do not match any of the supplied Java Regular Expression
excludePatterns.
|
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:
Absolute path: The path is used by itself (i.e.
|
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.
|
static List<File> |
listFiles(File fileOrDir,
List<Filter<File>> fileFilters,
boolean excludeFilterOperation,
org.apache.maven.plugin.logging.Log log)
If the supplied fileOrDir is a File, it is added to the returned List if any of the filters Match.
|
static List<File> |
listFiles(File fileOrDir,
List<Filter<File>> fileFilters,
org.apache.maven.plugin.logging.Log log)
If the supplied fileOrDir is a File, it is added to the returned List if any of the filters Match.
|
static String |
relativize(String path,
File parentDir)
If the supplied path refers to a file or directory below the supplied basedir, the returned
path is identical to the part below the basedir.
|
static List<File> |
resolveRecursively(List<File> files,
List<Filter<File>> exclusionFilters,
org.apache.maven.plugin.logging.Log log)
Retrieves a List of Files containing all the existing files within the supplied files List, including all
files found in directories recursive to any directories provided in the files list.
|
public static final FileFilter EXISTING_FILE
File.isFile()
is true
.public static final FileFilter EXISTING_DIRECTORY
File.isDirectory()
is true
.public static String getCanonicalPath(File file)
file
- A non-null File for which the canonical path should be retrieved.public static File getCanonicalFile(File file)
file
- A non-null File for which the canonical File should be retrieved.public static File getExistingFile(String path, File baseDir)
Retrieves the canonical File matching the supplied path in the following order or priority:
new File(path);
). If an
existing file or directory matches the provided path argument, its canonical path will be returned.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.
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.null
if no file or directory matched
the supplied path and baseDir.public static URL getUrlFor(File aFile) throws IllegalArgumentException
aFile
- A File for which the URL should be retrieved.IllegalArgumentException
- if getting the URL yielded a MalformedURLException.public static File getFileFor(URL anURL, String encoding)
anURL
- a non-null URL.encoding
- The encoding to be used by the URLDecoder to decode the path found.public static List<URL> filterFiles(File baseDir, List<String> sources, List<String> standardDirectories, org.apache.maven.plugin.logging.Log log, String fileTypeDescription, List<Filter<File>> excludePatterns)
baseDir
- The non-null basedir Directory.sources
- The sources which should be either absolute or relative (to the given baseDir)
paths to files or to directories that should be searched recursively for files.standardDirectories
- If no sources are given, revert to searching all files under these standard
directories. Each path is relativize()
-d to the supplied baseDir to
reach a directory path.log
- A non-null Maven Log for logging any operations performed.fileTypeDescription
- A human-readable short description of what kind of files are searched for, such as
"xsdSources" or "xjbSources".excludePatterns
- An optional List of patterns used to construct an ExclusionRegExpFileFilter used to
identify files which should be excluded from the result.public static List<File> filterFiles(File baseDir, List<String> sources, String standardDirectory, org.apache.maven.plugin.logging.Log log, String fileTypeDescription, List<Filter<File>> excludeFilters)
baseDir
- The non-null basedir Directory.sources
- The sources which should be either absolute or relative (to the given baseDir)
paths to files or to directories that should be searched recursively for files.standardDirectory
- If no sources are given, revert to searching all files under this standard directory.
This is the path appended to the baseDir to reach a directory.log
- A non-null Maven Log for logging any operations performed.fileTypeDescription
- A human-readable short description of what kind of files are searched for, such as
"xsdSources" or "xjbSources".excludeFilters
- An optional List of Filters used to identify files which should be excluded from
the result.public static List<File> resolveRecursively(List<File> files, List<Filter<File>> exclusionFilters, org.apache.maven.plugin.logging.Log log)
files
- The list of files to resolve, filter and return. If the files
List
contains directories, they are searched for Files recursively. Any found Files in such
a search are included in the resulting File List if they do not match any of the
exclusionFilters supplied.exclusionFilters
- A List of Filters which identify files to remove from the result - implying that any
File matched by any of these exclusionFilters will not be included in the result.log
- The active Maven Log.public static void createDirectory(File aDirectory, boolean cleanBeforeCreate) throws org.apache.maven.plugin.MojoExecutionException
aDirectory
- The directory to create.cleanBeforeCreate
- if true
, the directory and all its content will be deleted before being
re-created. This will ensure that the created directory is really clean.org.apache.maven.plugin.MojoExecutionException
- if the aDirectory could not be created (and/or cleaned).public static String relativize(String path, File parentDir)
path
- The path to strip off basedir path from, and return.parentDir
- The maven project basedir.public static List<File> listFiles(File fileOrDir, List<Filter<File>> fileFilters, org.apache.maven.plugin.logging.Log log)
fileOrDir
- A File or Directory.fileFilters
- A List of filter of which at least one must match to add the File
(or child Files, in case of a directory) to the resulting List.log
- The active Maven Logpublic static List<File> listFiles(File fileOrDir, List<Filter<File>> fileFilters, boolean excludeFilterOperation, org.apache.maven.plugin.logging.Log log)
fileOrDir
- A File or Directory.fileFilters
- A List of filter of which at least one must match to add the File (or child Files, in case
of a directory) to the resulting List.excludeFilterOperation
- if true
, all fileFilters are considered exclude filter, i.e. if
any of the Filters match the fileOrDir, that fileOrDir will be excluded from the
result.log
- The active Maven LogCopyright © 2005–2015 MojoHaus. All rights reserved.