org.sonar.api.batch.fs.internal
Class DefaultFileSystem

java.lang.Object
  extended by org.sonar.api.batch.fs.internal.DefaultFileSystem
All Implemented Interfaces:
FileSystem, BatchComponent

public class DefaultFileSystem
extends Object
implements FileSystem

Since:
4.2

Nested Class Summary
static class DefaultFileSystem.Cache
           
 
Constructor Summary
  DefaultFileSystem()
          Only for testing
protected DefaultFileSystem(DefaultFileSystem.Cache cache)
           
 
Method Summary
 DefaultFileSystem add(InputDir inputDir)
          Adds InputDir to the list.
 DefaultFileSystem add(InputFile inputFile)
          Adds InputFile to the list and registers its language, if present.
 DefaultFileSystem addLanguages(String language, String... others)
          Adds a language to the list.
 File baseDir()
          Absolute base directory of module
protected  void doPreloadFiles()
          This method is called before each search of files.
 Charset encoding()
          Default encoding of input files.
 Iterable<File> files(FilePredicate predicate)
          Files matching the given predicate.
static Collection<InputFile> filter(Iterable<InputFile> target, FilePredicate predicate)
           
 boolean hasFiles(FilePredicate predicate)
          Returns true if at least one InputFile matches the given predicate.
 InputDir inputDir(File dir)
          Returns InputDir matching the current File.
 InputFile inputFile(FilePredicate predicate)
          Returns the single element matching the predicate.
 Iterable<InputFile> inputFiles(FilePredicate predicate)
          Input files matching the given attributes.
 boolean isDefaultJvmEncoding()
           
 SortedSet<String> languages()
          Languages detected in all files, whatever their type (main or test)
 FilePredicates predicates()
          Factory of FilePredicate
 DefaultFileSystem setBaseDir(File d)
           
 DefaultFileSystem setEncoding(Charset e)
           
 DefaultFileSystem setWorkDir(File d)
           
 File workDir()
          Absolute work directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileSystem

public DefaultFileSystem()
Only for testing


DefaultFileSystem

protected DefaultFileSystem(DefaultFileSystem.Cache cache)
Method Detail

setBaseDir

public DefaultFileSystem setBaseDir(File d)

baseDir

public File baseDir()
Description copied from interface: FileSystem
Absolute base directory of module

Specified by:
baseDir in interface FileSystem

setEncoding

public DefaultFileSystem setEncoding(@Nullable
                                     Charset e)

encoding

public Charset encoding()
Description copied from interface: FileSystem
Default encoding of input files. If it's not defined, then the platform default encoding is returned

Specified by:
encoding in interface FileSystem

isDefaultJvmEncoding

public boolean isDefaultJvmEncoding()

setWorkDir

public DefaultFileSystem setWorkDir(File d)

workDir

public 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 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 files = fs.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN)));
 

Specified by:
inputFiles in interface FileSystem
See Also:
FileSystem.predicates()

hasFiles

public boolean hasFiles(FilePredicate predicate)
Description copied from interface: FileSystem
Returns true if at least one InputFile matches the given predicate. This method can be faster than checking if FileSystem.inputFiles(org.sonar.api.batch.fs.FilePredicate) has elements.

Specified by:
hasFiles in interface FileSystem
See Also:
FileSystem.predicates()

files

public Iterable<File> files(FilePredicate predicate)
Description copied from interface: FileSystem
Files matching the given predicate.

Specified by:
files in interface FileSystem
See Also:
FileSystem.predicates()

inputDir

public InputDir inputDir(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.

filter

public static Collection<InputFile> filter(Iterable<InputFile> target,
                                           FilePredicate predicate)

add

public DefaultFileSystem add(InputFile inputFile)
Adds InputFile to the list and registers its language, if present.


add

public DefaultFileSystem add(InputDir inputDir)
Adds InputDir to the list.


addLanguages

public DefaultFileSystem addLanguages(String language,
                                      String... others)
Adds a language to the list. To be used only for unit tests that need to use languages() without using add(org.sonar.api.batch.fs.InputFile).


languages

public SortedSet<String> languages()
Description copied from interface: FileSystem
Languages detected in all files, whatever their type (main or test)

Specified by:
languages in interface FileSystem

predicates

public FilePredicates predicates()
Description copied from interface: FileSystem
Factory of FilePredicate

Specified by:
predicates in interface FileSystem

doPreloadFiles

protected void doPreloadFiles()
This method is called before each search of files.



Copyright © 2009–2014 SonarSource. All rights reserved.