@ScannerSide public interface FileSystem
FileSystem
manages all the source files to be analyzed.
This is not an extension point so it must not be implemented by plugins. It must be injected as a constructor parameter :
public class MySensor implements Sensor { private final FileSystem fs; public MySensor(FileSystem fs) { this.fs = fs; } }
DefaultFileSystem
and the related DefaultInputFile
,
for example :
DefaultFileSystem fs = new DefaultFileSystem(); fs.add(new DefaultInputFile("myprojectKey", "src/foo/bar.php"));
Modifier and Type | Interface and Description |
---|---|
static interface |
FileSystem.Index
Interface of the underlying file index.
|
Modifier and Type | Method and Description |
---|---|
java.io.File |
baseDir()
Absolute base directory of module.
|
java.nio.charset.Charset |
encoding()
Default encoding of files in this project.
|
java.lang.Iterable<java.io.File> |
files(FilePredicate predicate)
Deprecated.
since 6.6 Plugins should avoid working with
File and prefer working with InputFile |
boolean |
hasFiles(FilePredicate predicate)
Returns true if at least one
InputFile matches
the given predicate. |
InputDir |
inputDir(java.io.File dir)
Deprecated.
since 6.6 Ability to report issues or measures on directories will soon be dropped. Report issues on project if needed.
|
InputFile |
inputFile(FilePredicate predicate)
Returns the single element matching the predicate.
|
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 of
FilePredicate |
java.io.File |
resolvePath(java.lang.String path)
Utility method mainly used to resolve location of reports.
|
java.io.File |
workDir()
Absolute work directory.
|
java.io.File baseDir()
java.nio.charset.Charset encoding()
InputFile
it is preferable to use InputFile.charset()
java.io.File workDir()
baseDir()
.FilePredicates predicates()
FilePredicate
@CheckForNull InputFile inputFile(FilePredicate predicate)
IllegalArgumentException
is thrown. Returns null
if no files match.
How to use :
InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));
predicates()
@Deprecated @CheckForNull InputDir inputDir(java.io.File dir)
InputDir
matching the current File
.java.lang.IllegalArgumentException
- is File is null or not a directory.java.lang.Iterable<InputFile> inputFiles(FilePredicate predicate)
attributes
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)));
predicates()
boolean hasFiles(FilePredicate predicate)
InputFile
matches
the given predicate. This method can be faster than checking if inputFiles(org.sonar.api.batch.fs.FilePredicate)
has elements.predicates()
@Deprecated java.lang.Iterable<java.io.File> files(FilePredicate predicate)
File
and prefer working with InputFile
predicates()
java.util.SortedSet<java.lang.String> languages()
java.io.File resolvePath(java.lang.String path)