Package org.sonar.api.batch.fs
Interface FileSystem
-
- All Known Implementing Classes:
DefaultFileSystem
@ScannerSide public interface FileSystem
TheFileSystemmanages 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; } }How to use in unit tests
The unit tests needing an instance of FileSystem can use the implementationDefaultFileSystemand the relatedDefaultInputFile, for example :DefaultFileSystem fs = new DefaultFileSystem(); fs.add(new DefaultInputFile("myprojectKey", "src/foo/bar.php"));- Since:
- 4.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceFileSystem.IndexInterface of the underlying file index.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description java.io.FilebaseDir()Absolute base directory of module.java.nio.charset.Charsetencoding()Default encoding of files in this project.java.lang.Iterable<java.io.File>files(FilePredicate predicate)Deprecated.since 6.6 Plugins should avoid working withFileand prefer working withInputFilebooleanhasFiles(FilePredicate predicate)Returns true if at least oneInputFilematches the given predicate.InputDirinputDir(java.io.File dir)Deprecated.since 6.6 Ability to report issues or measures on directories will soon be dropped.InputFileinputFile(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)FilePredicatespredicates()Factory ofFilePredicatejava.io.FileresolvePath(java.lang.String path)Utility method mainly used to resolve location of reports.java.io.FileworkDir()Absolute work directory.
-
-
-
Method Detail
-
baseDir
java.io.File baseDir()
Absolute base directory of module.
-
encoding
java.nio.charset.Charset encoding()
Default 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()
-
workDir
java.io.File workDir()
Absolute work directory. It can be used to store third-party analysis reports.
The work directory can be located outsidebaseDir().
-
predicates
FilePredicates predicates()
Factory ofFilePredicate
-
inputFile
@CheckForNull InputFile inputFile(FilePredicate predicate)
Returns 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"));- See Also:
predicates()
-
inputDir
@Deprecated @CheckForNull 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.ReturnsInputDirmatching the currentFile.- Returns:
- null if directory is not indexed.
- Throws:
java.lang.IllegalArgumentException- is File is null or not a directory.- Since:
- 4.5
-
inputFiles
java.lang.Iterable<InputFile> inputFiles(FilePredicate predicate)
Input 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)));- See Also:
predicates()
-
hasFiles
boolean hasFiles(FilePredicate predicate)
Returns true if at least oneInputFilematches the given predicate. This method can be faster than checking ifinputFiles(org.sonar.api.batch.fs.FilePredicate)has elements.- See Also:
predicates()
-
files
@Deprecated java.lang.Iterable<java.io.File> files(FilePredicate predicate)
Deprecated.since 6.6 Plugins should avoid working withFileand prefer working withInputFileFiles matching the given predicate.- See Also:
predicates()
-
languages
java.util.SortedSet<java.lang.String> languages()
Languages detected in all files, whatever their type (main or test)
-
resolvePath
java.io.File resolvePath(java.lang.String path)
Utility method mainly used to resolve location of reports.- 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")
- Since:
- 5.0
-
-