Class FileCollector
java.lang.Object
net.sourceforge.pmd.lang.document.FileCollector
- All Implemented Interfaces:
AutoCloseable
Collects files to analyse before a PMD run. This API allows opening
zip files and makes sure they will be closed at the end of a run.
- Author:
- Clément Fournier
-
Method Summary
Modifier and TypeMethodDescriptionvoidabsorb(FileCollector otherCollector) Add all files collected in the other collector into this one.booleanaddDirectory(Path dir) Add a directory recursively usingaddFile(Path)on all regular files.booleanaddDirectory(Path dir, boolean recurse) booleanAdd a file, language is determined automatically from the extension/file patterns.booleanAdd a file with the given language (which overrides the file patterns).booleanAdd a pre-configured text file.booleanaddFileOrDirectory(Path file) Add a file or directory recursively.booleanaddFileOrDirectory(Path file, boolean recurseIfDirectory) Add a file or directory recursively.booleanaddSourceFile(FileId fileId, String sourceContents) Add a text file given its contents and a name.booleanaddZipFileWithContent(Path zipFile) Opens a zip file and adds all files of the zip file to the list of files to be processed.voidclose()Close registered resources like zip files.voidexclude(FileCollector excludeCollector) Remove all files collected by the given collector from this one.voidfilterLanguages(Set<Language> languages) Exclude all collected files whose language is not part of the given collection.Returns an unmodifiable list of all files that have been collected.Returns the reporter for the file collection phase.voidsetCharset(Charset charset) Sets the charset to use for subsequent calls toaddFile(Path)and other overloads using aPath.voidsetFileFilter(Predicate<FileId> fileFilter) Sets an additional filter that is being called before adding the file to the list.voidsetRecursive(boolean collectFilesRecursively) toString()
-
Method Details
-
getCollectedFiles
Returns an unmodifiable list of all files that have been collected.- Throws:
IllegalStateException- if the collector was already closed
-
getReporter
Returns the reporter for the file collection phase. -
close
public void close()Close registered resources like zip files.- Specified by:
closein interfaceAutoCloseable
-
addFile
Add a file, language is determined automatically from the extension/file patterns. The encoding is the current encoding (setCharset(Charset)).- Parameters:
file- File to add- Returns:
- True if the file has been added
-
addFile
Add a file with the given language (which overrides the file patterns). The encoding is the current encoding (setCharset(Charset)).- Parameters:
file- Path to a filelanguage- A language. The language version will be taken to be the contextual default version.- Returns:
- True if the file has been added
-
addFile
Add a pre-configured text file. The language version will be checked to match the contextual default for the language (the file cannot be added if it has a different version).- Returns:
- True if the file has been added
-
addSourceFile
Add a text file given its contents and a name. The language version will be determined from the name as usual.- Returns:
- True if the file has been added
-
addDirectory
Add a directory recursively usingaddFile(Path)on all regular files.- Parameters:
dir- Directory path- Returns:
- True if the directory has been added
- Throws:
IOException
-
addDirectory
- Throws:
IOException
-
addFileOrDirectory
Add a file or directory recursively. Language is determined automatically from the extension/file patterns.- Returns:
- True if the file or directory has been added
- Throws:
IOException
-
addFileOrDirectory
Add a file or directory recursively. Language is determined automatically from the extension/file patterns.- Returns:
- True if the file or directory has been added
- Throws:
IOException
-
addZipFileWithContent
Opens a zip file and adds all files of the zip file to the list of files to be processed.The zip file is registered as a resource to close at the end of analysis.
- Returns:
- True if the zip file including its content has been added without errors
- Throws:
IOException
-
setRecursive
public void setRecursive(boolean collectFilesRecursively) -
setCharset
Sets the charset to use for subsequent calls toaddFile(Path)and other overloads using aPath.- Parameters:
charset- A charset
-
setFileFilter
Sets an additional filter that is being called before adding the file to the list.- Parameters:
fileFilter- the filter should returntrueif the file should be collected and analyzed.- Throws:
NullPointerException- iffileFilterisnull.
-
exclude
Remove all files collected by the given collector from this one. -
absorb
Add all files collected in the other collector into this one. Transfers resources to close as well. The parameter is left empty. -
filterLanguages
Exclude all collected files whose language is not part of the given collection. -
toString
-