|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object eu.lindenbaum.maven.util.FileUtils
public final class FileUtils
Containing utilities related to file handling.
Field Summary | |
---|---|
static FileFilter |
APP_FILTER
Filename filter to filter app files (.app & .appup). |
static FileFilter |
BEAM_FILTER
Filename filter to filter compiled beam files (.beam). |
static Predicate<File> |
FILE_PRED
a Predicate that checks a file for null and existance |
static FileFilter |
NULL_FILTER
a FileFilter accepting all input |
static FileFilter |
REL_FILTER
Filename filter to filter rel files (.rel). |
static FileFilter |
SOURCE_FILTER
Filename filter to filter source files (.erl & .hrl). |
static FileFilter |
SRC_FILTER
Filename filter to filter .src files. |
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static Collection<File> |
copyDirectory(File from,
File to,
FileFilter filter)
Copies the contents of the source directory recursively into the destination directory. |
static Collection<File> |
copyDirectory(File from,
File to,
FileFilter filter,
Map<String,String> replacements)
Copies the contents of the source directory recursively into the destination directory. |
static void |
copyFile(File from,
File to,
Map<String,String> replacements)
Copies the content of a file into another file (previous content will be overwritten). |
static void |
copyFiles(File destination,
File... files)
Copies the given files to a specific destination directory. |
static void |
ensureDirectories(File... dirs)
Ensures that the directories denoted by the given files exist and are directories. |
static void |
extractFileFromClassPath(Class<?> clazz,
String path,
String name,
File dest)
Writes a file that is part of the classpath to a specific destination file. |
static List<File> |
getDirectories(File root,
Collection<String> excludes)
Returns a list of sub directories of a specific directory not matching a list of given excludes. |
static List<File> |
getDirectoriesRecursive(File root,
String suffix)
Returns the list of sub directories containing files with the specified file suffix. |
static File |
getFile(String pathPostfix,
Collection<File> files)
Returns the file object of a certain file contained in a given list. |
static List<File> |
getFilesAndDirectoriesRecursive(File root,
FileFilter filter)
Returns a list of all found filterend (sub) files and directories. |
static List<File> |
getFilesRecursive(File root,
String suffix)
Get a List of files matching the given file extension (excluding
directories). |
static List<File> |
getFilesRecursive(List<File> directories,
String suffix)
Get a flattened list of all files matching the specified file extension in all of the given root directories. |
static FileFilter |
getSuffixFilter(String[] suffixes)
Returns a FileFilter which only accepts files ending with
one of the given suffixes. |
static String |
readFileFromClassPath(Class<?> clazz,
String path,
String name)
Reads a file that is part of the classpath and returns its content as a String object. |
static void |
removeDirectory(File directory)
Removes a directory recursively. |
static void |
removeEmptyDirectory(File directory)
Removes an empty directory. |
static void |
removeFileNameSuffix(String suffix,
File... files)
Renames a list of files by replacing the given string suffix from the current file name. |
static int |
removeFiles(File... files)
Removes the specific files from the file system. |
static int |
removeFilesRecursive(File root,
String suffix)
Removes all files ending with a specific suffix recursively from a directory. |
static void |
touch(File file)
Touches a file UNIX style. |
static void |
writeFile(File destination,
String data)
Writes data to a destination file. |
static void |
writeFile(File destination,
String data,
boolean executable)
Writes data to a destination file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final FileFilter SOURCE_FILTER
public static final FileFilter BEAM_FILTER
public static final FileFilter APP_FILTER
public static final FileFilter REL_FILTER
public static final FileFilter SRC_FILTER
public static FileFilter NULL_FILTER
FileFilter
accepting all input
public static Predicate<File> FILE_PRED
Predicate
that checks a file for null
and existance
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static FileFilter getSuffixFilter(String[] suffixes)
FileFilter
which only accepts files ending with
one of the given suffixes. The suffixes may be of the for .java
or
java
. Directories will always be accepted.
suffixes
- list of accepted suffixes
FileFilter
public static List<File> getFilesRecursive(File root, String suffix)
List
of files matching the given file extension (excluding
directories). By default patterns from
FileUtils.getDefaultExcludes()
will always
be excluded.
root
- directory to start recursion fromsuffix
- file extension to match, can be e.g. either ".erl"
or
"erl"
List
of found filespublic static List<File> getFilesRecursive(List<File> directories, String suffix)
directories
- used for recursive lookup, aggregated into one resultsuffix
- file extension to match, for example ".erl"
.
List
of all the found filesgetFilesRecursive(File, String)
public static File getFile(String pathPostfix, Collection<File> files)
Collection
. So for example in a list containing the
file /foo/bar/file.erl
one could look up file.erl
as well as bar/file.erl
pathPostfix
- a postfix to match against an absolute pathfiles
- to examine for the corresponding file object
File
referring to the given name or null
if no
file with the file name could be found.public static int removeFilesRecursive(File root, String suffix)
FileUtils.getDefaultExcludes()
will always
be excluded.
root
- directory to remove specific files fromsuffix
- file suffixes to remove
public static void removeDirectory(File directory)
directory
- to removepublic static void removeEmptyDirectory(File directory) throws org.apache.maven.plugin.MojoExecutionException
directory
- to remove
org.apache.maven.plugin.MojoExecutionException
public static int removeFiles(File... files)
files
- to remove.
public static void removeFileNameSuffix(String suffix, File... files) throws org.apache.maven.plugin.MojoExecutionException
suffix
- to removefiles
- to remove the filename suffix from
org.apache.maven.plugin.MojoExecutionException
- in case renaming failspublic static List<File> getFilesAndDirectoriesRecursive(File root, FileFilter filter)
FileUtils.getDefaultExcludes()
will always
be excluded.
root
- directory to start recursion fromfilter
- used to filter the found files and directories
List
of found files and directoriespublic static List<File> getDirectoriesRecursive(File root, String suffix)
FileUtils.getDefaultExcludes()
will always
be excluded.
root
- directory to start the scan fromsuffix
- file suffix to search for
null
list of directories containg files with a
certain suffixpublic static List<File> getDirectories(File root, Collection<String> excludes)
FileUtils.getDefaultExcludes()
will also
be excluded.
root
- to scanexcludes
- exact matches to exclude from the returned list
null
list of directories matching the prefixpublic static Collection<File> copyDirectory(File from, File to, FileFilter filter) throws org.apache.maven.plugin.MojoExecutionException
FileUtils.getDefaultExcludes()
will always
be excluded. Empty directories will be skipped.
from
- the source directory to copy fromto
- the destination directory to copy tofilter
- additional filter to apply before copying
Collection
of files that were copied
org.apache.maven.plugin.MojoExecutionException
getFilesAndDirectoriesRecursive(File, FileFilter)
public static Collection<File> copyDirectory(File from, File to, FileFilter filter, Map<String,String> replacements) throws org.apache.maven.plugin.MojoExecutionException
UTF-8
encoded. By default patterns from
FileUtils.getDefaultExcludes()
will always
be excluded. Empty directories will be skipped.
from
- the source directory to copy fromto
- the destination directory to copy tofilter
- additional filter to apply before copyingreplacements
- a Map
of String
patterns to be replaced
Collection
of files that were copied
org.apache.maven.plugin.MojoExecutionException
getFilesAndDirectoriesRecursive(File, FileFilter)
public static void copyFile(File from, File to, Map<String,String> replacements) throws org.apache.maven.plugin.MojoExecutionException
UTF-8
encoded.
from
- file to copy the content fromto
- file to copy the content intoreplacements
- a Map
of String
patterns to be replaced
IOException
org.apache.maven.plugin.MojoExecutionException
public static void copyFiles(File destination, File... files) throws org.apache.maven.plugin.MojoExecutionException
destination
- directory to copy the files intofiles
- to copy
org.apache.maven.plugin.MojoExecutionException
- in case a file could not be copiedpublic static void writeFile(File destination, String data) throws org.apache.maven.plugin.MojoExecutionException
destination
- to write todata
- to write
org.apache.maven.plugin.MojoExecutionException
writeFile(File, String, boolean)
public static void writeFile(File destination, String data, boolean executable) throws org.apache.maven.plugin.MojoExecutionException
destination
- to write todata
- to writeexecutable
- true
if destination should be flagged executable
org.apache.maven.plugin.MojoExecutionException
public static void ensureDirectories(File... dirs) throws org.apache.maven.plugin.MojoExecutionException
dirs
- to create/assure.
org.apache.maven.plugin.MojoExecutionException
- in case one of the directories denotes a
file or directory could not be createdpublic static void touch(File file) throws org.apache.maven.plugin.MojoExecutionException
System.currentTimeMillis()
.
file
- to touch
org.apache.maven.plugin.MojoExecutionException
public static void extractFileFromClassPath(Class<?> clazz, String path, String name, File dest) throws org.apache.maven.plugin.MojoExecutionException
clazz
- used to retrieve the classpath resource frompath
- the file's classpath prefixname
- the file to extract denoted by its name in the classpathdest
- the file to write to
org.apache.maven.plugin.MojoExecutionException
public static String readFileFromClassPath(Class<?> clazz, String path, String name) throws org.apache.maven.plugin.MojoExecutionException
String
object.
clazz
- used to retrieve the classpath resource frompath
- the file's classpath prefixname
- the file to extract denoted by its name in the classpath
null
object containing the content of the file
org.apache.maven.plugin.MojoExecutionException
- in case the file could not be found or read
errors occured
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |