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 class
DefaultFileSystem.Cache
-
Nested classes/interfaces inherited from interface org.sonar.api.batch.fs.FileSystem
FileSystem.Index
-
-
Field Summary
Fields Modifier and Type Field Description protected FilePredicates
predicates
-
Constructor Summary
Constructors Modifier Constructor Description DefaultFileSystem(java.io.File baseDir)
Only for testingDefaultFileSystem(java.nio.file.Path baseDir)
Only for testingprotected
DefaultFileSystem(java.nio.file.Path baseDir, DefaultFileSystem.Cache cache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DefaultFileSystem
add(InputFile inputFile)
java.io.File
baseDir()
Absolute base directory of module.java.nio.file.Path
baseDirPath()
java.nio.charset.Charset
encoding()
Default encoding of files in this project.java.lang.Iterable<java.io.File>
files(FilePredicate predicate)
Files matching the given predicate.boolean
hasFiles(FilePredicate predicate)
Returns true if at least oneInputFile
matches the given predicate.InputDir
inputDir(java.io.File dir)
ReturnsInputDir
matching the currentFile
.InputFile
inputFile(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)FilePredicates
predicates()
Factory ofFilePredicate
java.io.File
resolvePath(java.lang.String path)
Utility method mainly used to resolve location of reports.DefaultFileSystem
setEncoding(java.nio.charset.Charset e)
DefaultFileSystem
setWorkDir(java.nio.file.Path d)
java.io.File
workDir()
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:FileSystem
Absolute base directory of module.- Specified by:
baseDir
in interfaceFileSystem
-
setEncoding
public DefaultFileSystem setEncoding(java.nio.charset.Charset e)
-
encoding
public java.nio.charset.Charset encoding()
Description copied from interface:FileSystem
Default encoding of files in this project. If it's not defined, then the platform default encoding is returned. When reading anInputFile
it is preferable to useInputFile.charset()
- Specified by:
encoding
in interfaceFileSystem
-
setWorkDir
public DefaultFileSystem setWorkDir(java.nio.file.Path d)
-
workDir
public java.io.File workDir()
Description copied from interface:FileSystem
Absolute work directory. It can be used to store third-party analysis reports.
The work directory can be located outsideFileSystem.baseDir()
.- Specified by:
workDir
in interfaceFileSystem
-
inputFile
public InputFile inputFile(FilePredicate predicate)
Description copied from interface:FileSystem
Returns the single element matching the predicate. If more than one elements match the predicate, thenIllegalArgumentException
is thrown. Returnsnull
if no files match.How to use :
InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));
- Specified by:
inputFile
in 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:FileSystem
Input files matching the given attributes. Return all the files if the parameterattributes
is empty.Important - result is an
Iterable
to 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:
inputFiles
in interfaceFileSystem
- See Also:
FileSystem.predicates()
-
hasFiles
public boolean hasFiles(FilePredicate predicate)
Description copied from interface:FileSystem
Returns true if at least oneInputFile
matches the given predicate. This method can be faster than checking ifFileSystem.inputFiles(org.sonar.api.batch.fs.FilePredicate)
has elements.- Specified by:
hasFiles
in interfaceFileSystem
- See Also:
FileSystem.predicates()
-
files
public java.lang.Iterable<java.io.File> files(FilePredicate predicate)
Description copied from interface:FileSystem
Files matching the given predicate.- Specified by:
files
in interfaceFileSystem
- See Also:
FileSystem.predicates()
-
inputDir
public InputDir inputDir(java.io.File dir)
Description copied from interface:FileSystem
ReturnsInputDir
matching the currentFile
.- Specified by:
inputDir
in 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:FileSystem
Languages detected in all files, whatever their type (main or test)- Specified by:
languages
in interfaceFileSystem
-
predicates
public FilePredicates predicates()
Description copied from interface:FileSystem
Factory ofFilePredicate
- Specified by:
predicates
in interfaceFileSystem
-
resolvePath
public java.io.File resolvePath(java.lang.String path)
Description copied from interface:FileSystem
Utility method mainly used to resolve location of reports.- Specified by:
resolvePath
in 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")
-
-