Package net.sourceforge.pmd.util
Class FileUtil
- java.lang.Object
-
- net.sourceforge.pmd.util.FileUtil
-
public final class FileUtil extends java.lang.Object
This is a utility class for working with Files.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<DataSource>
collectFiles(java.lang.String fileLocations, java.io.FilenameFilter filenameFilter)
Collects a list of DataSources using a comma separated list of input file locations to process.static boolean
findPatternInFile(java.io.File file, java.lang.String pattern)
Handy method to find a certain pattern into a file.static java.lang.String
getFileNameWithoutExtension(java.lang.String fileName)
Helper method to get a filename without its extensionstatic java.lang.String
normalizeFilename(java.lang.String fileName)
Normalizes the filename by taking the casing into account, e.g.static java.lang.String
readFilelist(java.io.File filelist)
Reads the file, which contains the filelist.
-
-
-
Method Detail
-
getFileNameWithoutExtension
public static java.lang.String getFileNameWithoutExtension(java.lang.String fileName)
Helper method to get a filename without its extension- Parameters:
fileName
- String- Returns:
- String
-
normalizeFilename
public static java.lang.String normalizeFilename(java.lang.String fileName)
Normalizes the filename by taking the casing into account, e.g. on Windows, the filename is changed to lowercase only.- Parameters:
fileName
- the file name- Returns:
- the normalized file name
-
collectFiles
public static java.util.List<DataSource> collectFiles(java.lang.String fileLocations, java.io.FilenameFilter filenameFilter)
Collects a list of DataSources using a comma separated list of input file locations to process. If a file location is a directory, the directory hierarchy will be traversed to look for files. If a file location is a ZIP or Jar the archive will be scanned looking for files. If a file location is a file, it will be used. For each located file, a FilenameFilter is used to decide whether to return a DataSource.- Parameters:
fileLocations
- A comma-separated list of file locations.filenameFilter
- The FilenameFilter to apply to files.- Returns:
- A list of DataSources, one for each file collected.
-
findPatternInFile
public static boolean findPatternInFile(java.io.File file, java.lang.String pattern)
Handy method to find a certain pattern into a file. While this method lives in the FileUtils, it was designed with with unit test in mind (to check result redirected into a file)- Parameters:
file
-pattern
-- Returns:
-
readFilelist
public static java.lang.String readFilelist(java.io.File filelist) throws java.io.IOException
Reads the file, which contains the filelist. This is used for the command line arguments --filelist/-filelist for both PMD and CPD. The separator in the filelist is a command and/or newlines.- Parameters:
filelist
- the file which contains the list of path names- Returns:
- a comma-separated list of file paths
- Throws:
java.io.IOException
- if the file couldn't be read
-
-