Class DefaultFileSystem

  • All Implemented Interfaces:
    FileSystem

    public class DefaultFileSystem
    extends java.lang.Object
    implements FileSystem
    Since:
    4.2
    • Constructor Detail

      • DefaultFileSystem

        public DefaultFileSystem​(java.nio.file.Path baseDir)
        Only for testing
      • DefaultFileSystem

        public DefaultFileSystem​(java.io.File baseDir)
        Only for testing
    • 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 interface FileSystem
      • 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 an InputFile it is preferable to use InputFile.charset()
        Specified by:
        encoding in interface FileSystem
      • 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 outside FileSystem.baseDir().
        Specified by:
        workDir in interface FileSystem
      • 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, then IllegalArgumentException is thrown. Returns null if no files match.

        How to use :

         InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));
         
        Specified by:
        inputFile in interface FileSystem
        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 parameter 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)));
         
         
        Specified by:
        inputFiles in interface FileSystem
        See Also:
        FileSystem.predicates()
      • inputDir

        public InputDir inputDir​(java.io.File dir)
        Description copied from interface: FileSystem
        Returns InputDir matching the current File.
        Specified by:
        inputDir in interface FileSystem
        Returns:
        null if directory is not indexed.
      • 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 interface FileSystem
      • 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 interface FileSystem
        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")