Package org.sonar.api.batch.fs.internal
Class DefaultFileSystem
- java.lang.Object
-
- org.sonar.api.batch.fs.internal.DefaultFileSystem
-
- All Implemented Interfaces:
FileSystem
public class DefaultFileSystem extends java.lang.Object implements FileSystem
- Since:
- 4.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultFileSystem.Cache-
Nested classes/interfaces inherited from interface org.sonar.api.batch.fs.FileSystem
FileSystem.Index
-
-
Field Summary
Fields Modifier and Type Field Description protected FilePredicatespredicates
-
Constructor Summary
Constructors Modifier Constructor Description DefaultFileSystem(java.io.File baseDir)Only for testingDefaultFileSystem(java.nio.file.Path baseDir)Only for testingprotectedDefaultFileSystem(java.nio.file.Path baseDir, DefaultFileSystem.Cache cache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DefaultFileSystemadd(InputFile inputFile)java.io.FilebaseDir()Absolute base directory of module.java.nio.file.PathbaseDirPath()java.nio.charset.Charsetencoding()Default encoding of files in this project.java.lang.Iterable<java.io.File>files(FilePredicate predicate)Files matching the given predicate.booleanhasFiles(FilePredicate predicate)Returns true if at least oneInputFilematches the given predicate.InputDirinputDir(java.io.File dir)ReturnsInputDirmatching the currentFile.InputFileinputFile(FilePredicate predicate)Returns the single element matching the predicate.java.lang.Iterable<InputFile>inputFiles()java.lang.Iterable<InputFile>inputFiles(FilePredicate predicate)Input files matching the given attributes.java.util.SortedSet<java.lang.String>languages()Languages detected in all files, whatever their type (main or test)FilePredicatespredicates()Factory ofFilePredicatejava.io.FileresolvePath(java.lang.String path)Utility method mainly used to resolve location of reports.DefaultFileSystemsetEncoding(java.nio.charset.Charset e)DefaultFileSystemsetWorkDir(java.nio.file.Path d)java.io.FileworkDir()Absolute work directory.
-
-
-
Field Detail
-
predicates
protected final FilePredicates predicates
-
-
Constructor Detail
-
DefaultFileSystem
public DefaultFileSystem(java.nio.file.Path baseDir)
Only for testing
-
DefaultFileSystem
public DefaultFileSystem(java.io.File baseDir)
Only for testing
-
DefaultFileSystem
protected DefaultFileSystem(java.nio.file.Path baseDir, DefaultFileSystem.Cache cache)
-
-
Method Detail
-
baseDirPath
public java.nio.file.Path baseDirPath()
-
baseDir
public java.io.File baseDir()
Description copied from interface:FileSystemAbsolute base directory of module.- Specified by:
baseDirin interfaceFileSystem
-
setEncoding
public DefaultFileSystem setEncoding(java.nio.charset.Charset e)
-
encoding
public java.nio.charset.Charset encoding()
Description copied from interface:FileSystemDefault encoding of files in this project. If it's not defined, then the platform default encoding is returned. When reading anInputFileit is preferable to useInputFile.charset()- Specified by:
encodingin interfaceFileSystem
-
setWorkDir
public DefaultFileSystem setWorkDir(java.nio.file.Path d)
-
workDir
public java.io.File workDir()
Description copied from interface:FileSystemAbsolute work directory. It can be used to store third-party analysis reports.
The work directory can be located outsideFileSystem.baseDir().- Specified by:
workDirin interfaceFileSystem
-
inputFile
public InputFile inputFile(FilePredicate predicate)
Description copied from interface:FileSystemReturns the single element matching the predicate. If more than one elements match the predicate, thenIllegalArgumentExceptionis thrown. Returnsnullif no files match.How to use :
InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));- Specified by:
inputFilein interfaceFileSystem- See Also:
FileSystem.predicates()
-
inputFiles
public java.lang.Iterable<InputFile> inputFiles()
-
inputFiles
public java.lang.Iterable<InputFile> inputFiles(FilePredicate predicate)
Description copied from interface:FileSystemInput files matching the given attributes. Return all the files if the parameterattributesis empty.Important - result is an
Iterableto benefit from streaming and decreasing memory consumption. It should be iterated only once, else copy it into a list :com.google.common.collect.Lists.newArrayList(inputFiles(predicate))How to use :
FilePredicates p = fs.predicates(); Iterable<InputFile> files = fs.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN)));- Specified by:
inputFilesin interfaceFileSystem- See Also:
FileSystem.predicates()
-
hasFiles
public boolean hasFiles(FilePredicate predicate)
Description copied from interface:FileSystemReturns true if at least oneInputFilematches the given predicate. This method can be faster than checking ifFileSystem.inputFiles(org.sonar.api.batch.fs.FilePredicate)has elements.- Specified by:
hasFilesin interfaceFileSystem- See Also:
FileSystem.predicates()
-
files
public java.lang.Iterable<java.io.File> files(FilePredicate predicate)
Description copied from interface:FileSystemFiles matching the given predicate.- Specified by:
filesin interfaceFileSystem- See Also:
FileSystem.predicates()
-
inputDir
public InputDir inputDir(java.io.File dir)
Description copied from interface:FileSystemReturnsInputDirmatching the currentFile.- Specified by:
inputDirin interfaceFileSystem- Returns:
- null if directory is not indexed.
-
add
public DefaultFileSystem add(InputFile inputFile)
-
languages
public java.util.SortedSet<java.lang.String> languages()
Description copied from interface:FileSystemLanguages detected in all files, whatever their type (main or test)- Specified by:
languagesin interfaceFileSystem
-
predicates
public FilePredicates predicates()
Description copied from interface:FileSystemFactory ofFilePredicate- Specified by:
predicatesin interfaceFileSystem
-
resolvePath
public java.io.File resolvePath(java.lang.String path)
Description copied from interface:FileSystemUtility method mainly used to resolve location of reports.- Specified by:
resolvePathin interfaceFileSystem- Returns:
- file in canonical form from specified path. Path can be absolute or relative to project basedir. For example resolvePath("pom.xml") or resolvePath("src/main/java")
-
-