Package org.codehaus.mojo.jaxb2.shared
Class FileSystemUtilities
- java.lang.Object
- 
- org.codehaus.mojo.jaxb2.shared.FileSystemUtilities
 
- 
 public final class FileSystemUtilities extends Object The Jaxb2 Maven Plugin needs to fiddle with the filesystem a great deal, 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.- Since:
- 2.0
- Author:
- Lennart Jörelid
 
- 
- 
Field SummaryFields Modifier and Type Field Description static FileFilterEXISTING_DIRECTORYFileFilter which accepts Files that exist and for whichFile.isDirectory()istrue.static FileFilterEXISTING_FILEFileFilter which accepts Files that exist and for whichFile.isFile()istrue.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcreateDirectory(File aDirectory, boolean cleanBeforeCreate)Convenience method to successfully create a directory - or throw an exception if failing to create it.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 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(List<File> files, Filter<File> acceptFilter, org.apache.maven.plugin.logging.Log log)Filters all supplied files using the providedacceptFilter.static FilegetCanonicalFile(File file)Acquires the canonical File for the supplied file.static StringgetCanonicalPath(File file)Acquires the canonical path for the supplied file.static FilegetExistingFile(String path, File baseDir)Retrieves the canonical File matching the supplied path in the following order or priority:static FilegetFileFor(URL anURL, String encoding)Acquires the file for a supplied URL, provided that its protocol is is either a file or a jar.static URLgetUrlFor(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 Stringrelativize(String path, File parentDir, boolean removeInitialFileSep)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.
 
- 
- 
- 
Field Detail- 
EXISTING_FILEpublic static final FileFilter EXISTING_FILE FileFilter which accepts Files that exist and for whichFile.isFile()istrue.
 - 
EXISTING_DIRECTORYpublic static final FileFilter EXISTING_DIRECTORY FileFilter which accepts Files that exist and for whichFile.isDirectory()istrue.
 
- 
 - 
Method Detail- 
getCanonicalPathpublic 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.
 
 - 
getCanonicalFilepublic 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.
 
 - 
getExistingFilepublic 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, nullis 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 nullif no file or directory matched the supplied path and baseDir.
 
- Absolute path: The path is used by itself (i.e. 
 - 
getUrlForpublic 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.
 
 - 
getFileForpublic 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.
 
 - 
filterFilespublic 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.- Parameters:
- 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.
- Returns:
- URLs to all Files under the supplied sources (or standardDirectories, if no explicit sources are given) which do not match the supplied Java Regular excludePatterns.
 
 - 
filterFilespublic 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.- Parameters:
- 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.
- Returns:
- All files under the supplied sources (or standardDirectory, if no explicit sources are given) which do not match the supplied Java Regular excludePatterns.
 
 - 
filterFilespublic static List<File> filterFiles(List<File> files, Filter<File> acceptFilter, org.apache.maven.plugin.logging.Log log) Filters all supplied files using the providedacceptFilter.- Parameters:
- files- The list of files to resolve, filter and return. If the- filesList contains directories, they are searched for Files recursively. Any found Files in such a search are included in the resulting File List if they match the acceptFilter supplied.
- acceptFilter- A filter matched to all files in the given List. If the acceptFilter matches a file, it is included in the result.
- log- The active Maven Log.
- Returns:
- All files in (or files in subdirectories of directories provided in) the files List, provided that each file is accepted by an ExclusionRegExpFileFilter.
 
 - 
resolveRecursivelypublic 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. Each file included in the result must pass an ExclusionRegExpFileFilter synthesized from the supplied exclusions pattern(s).- Parameters:
- files- The list of files to resolve, filter and return. If the- filesList 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.
- Returns:
- All files in (or files in subdirectories of directories provided in) the files List, provided that each file is accepted by an ExclusionRegExpFileFilter.
 
 - 
createDirectorypublic 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- 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.
- Throws:
- org.apache.maven.plugin.MojoExecutionException- if the aDirectory could not be created (and/or cleaned).
 
 - 
relativizepublic static String relativize(String path, File parentDir, boolean removeInitialFileSep) 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.- Parameters:
- path- The path to strip off basedir path from, and return.
- parentDir- The maven project basedir.
- removeInitialFileSep- If true, an initial- File#separatoris removed before returning.
- Returns:
- The path relative to basedir, if it is situated below the basedir. Otherwise the supplied path.
 
 - 
listFilespublic 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. If the supplied fileOrDir is a Directory, it is listed and any of the files immediately within the fileOrDir directory are returned within the resulting List provided that they match any of the supplied filters.- Parameters:
- 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 Log
- Returns:
- A List holding the supplied File (or child Files, in case fileOrDir is a Directory) given that at least one Filter accepts them.
 
 - 
listFilespublic 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. If the supplied fileOrDir is a Directory, it is listed and any of the files immediately within the fileOrDir directory are returned within the resulting List provided that they match any of the supplied filters.- Parameters:
- 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 Log
- Returns:
- A List holding the supplied File (or child Files, in case fileOrDir is a Directory) given that at least one Filter accepts them.
 
 
- 
 
-