org.sonar.api.resources
Class DefaultProjectFileSystem

java.lang.Object
  extended by org.sonar.api.resources.DefaultProjectFileSystem
All Implemented Interfaces:
ProjectFileSystem

public class DefaultProjectFileSystem
extends Object
implements ProjectFileSystem

An implementation of ProjectFileSystem

Since:
1.10

Constructor Summary
DefaultProjectFileSystem(Project project)
          Creates a DefaultProjectFileSystem based on a project
 
Method Summary
 DefaultProjectFileSystem addFileFilter(FileFilter fileFilter)
           
 DefaultProjectFileSystem addFileFilters(List<FileFilter> l)
           
 DefaultProjectFileSystem addSourceDir(File dir)
          Adds a source directory
 DefaultProjectFileSystem addTestDir(File dir)
          Adds a test directory
 File getBasedir()
          Basedir is the project root directory.
 File getBuildDir()
          Build directory is by default "target" in maven projects.
 File getBuildOutputDir()
          Directory where classes are placed.
 File getFileFromBuildDirectory(String filename)
           
 List<File> getJavaSourceFiles()
          Gets the list of java source files
static String getRelativePath(File file, File dir)
          getRelativePath("c:/foo/src/my/package/Hello.java", "c:/foo/src") is "my/package/Hello.java"
static String getRelativePath(File file, List<File> dirs)
          getRelativePath("c:/foo/src/my/package/Hello.java", ["c:/bar", "c:/foo/src"]) is "my/package/Hello.java".
 File getReportOutputDir()
           
 File getSonarWorkingDirectory()
           
 Charset getSourceCharset()
          Source encoding.
 List<File> getSourceDirs()
          The list of directories for sources
 List<File> getSourceFiles(Language... langs)
          Gets the list of source files for given languages
 List<File> getTestDirs()
          The list of directories for tests
 List<File> getTestFiles(Language... langs)
          Gets the list of test files for given languages
 boolean hasJavaSourceFiles()
          Check if the project has Java files, excluding unit tests and files matching project exclusion patterns.
 boolean hasTestFiles(Language lang)
          Check if the project has unit test files, excluding files matching project exclusion patterns.
 File resolvePath(String path)
          Get file from path.
 Resource toResource(File file)
           
protected static File writeToFile(String content, File dir, String fileName)
           
 File writeToWorkingDirectory(String content, String fileName)
          Save data into a new file of Sonar working directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultProjectFileSystem

public DefaultProjectFileSystem(Project project)
Creates a DefaultProjectFileSystem based on a project

Parameters:
project -
Method Detail

getSourceCharset

public Charset getSourceCharset()
Source encoding. Never null, it returns the default plateform charset if it is not defined in project.

Specified by:
getSourceCharset in interface ProjectFileSystem

addFileFilters

public DefaultProjectFileSystem addFileFilters(List<FileFilter> l)

addFileFilter

public DefaultProjectFileSystem addFileFilter(FileFilter fileFilter)

getBasedir

public File getBasedir()
Basedir is the project root directory.

Specified by:
getBasedir in interface ProjectFileSystem

getBuildDir

public File getBuildDir()
Build directory is by default "target" in maven projects.

Specified by:
getBuildDir in interface ProjectFileSystem

getBuildOutputDir

public File getBuildOutputDir()
Directory where classes are placed. By default "target/classes" in maven projects.

Specified by:
getBuildOutputDir in interface ProjectFileSystem

getSourceDirs

public List<File> getSourceDirs()
The list of directories for sources

Specified by:
getSourceDirs in interface ProjectFileSystem

addSourceDir

public DefaultProjectFileSystem addSourceDir(File dir)
Adds a source directory

Specified by:
addSourceDir in interface ProjectFileSystem
Returns:
the current object

getTestDirs

public List<File> getTestDirs()
The list of directories for tests

Specified by:
getTestDirs in interface ProjectFileSystem

addTestDir

public DefaultProjectFileSystem addTestDir(File dir)
Adds a test directory

Specified by:
addTestDir in interface ProjectFileSystem
Returns:
the current object

getReportOutputDir

public File getReportOutputDir()
Specified by:
getReportOutputDir in interface ProjectFileSystem
Returns:
the directory where reporting is placed. Default is target/sites

getSonarWorkingDirectory

public File getSonarWorkingDirectory()
Specified by:
getSonarWorkingDirectory in interface ProjectFileSystem
Returns:
the Sonar working directory. Default is "target/sonar"

resolvePath

public File resolvePath(String path)
Description copied from interface: ProjectFileSystem
Get file from path. It can be absolute or relative to project basedir. For example resolvePath("pom.xml") or resolvePath("src/main/java")

Specified by:
resolvePath in interface ProjectFileSystem

getSourceFiles

public List<File> getSourceFiles(Language... langs)
Gets the list of source files for given languages

Specified by:
getSourceFiles in interface ProjectFileSystem
Parameters:
langs - language filter. If null or empty, will return empty list

getJavaSourceFiles

public List<File> getJavaSourceFiles()
Gets the list of java source files

Specified by:
getJavaSourceFiles in interface ProjectFileSystem

hasJavaSourceFiles

public boolean hasJavaSourceFiles()
Description copied from interface: ProjectFileSystem
Check if the project has Java files, excluding unit tests and files matching project exclusion patterns.

Specified by:
hasJavaSourceFiles in interface ProjectFileSystem
Returns:
whether there are java source

getTestFiles

public List<File> getTestFiles(Language... langs)
Gets the list of test files for given languages

Specified by:
getTestFiles in interface ProjectFileSystem
Parameters:
langs - language filter. If null or empty, will return empty list

hasTestFiles

public boolean hasTestFiles(Language lang)
Description copied from interface: ProjectFileSystem
Check if the project has unit test files, excluding files matching project exclusion patterns.

Specified by:
hasTestFiles in interface ProjectFileSystem
Returns:
whether there are tests files

writeToWorkingDirectory

public File writeToWorkingDirectory(String content,
                                    String fileName)
                             throws IOException
Save data into a new file of Sonar working directory.

Specified by:
writeToWorkingDirectory in interface ProjectFileSystem
Returns:
the created file
Throws:
IOException

writeToFile

protected static File writeToFile(String content,
                                  File dir,
                                  String fileName)
                           throws IOException
Throws:
IOException

getRelativePath

public static String getRelativePath(File file,
                                     File dir)
getRelativePath("c:/foo/src/my/package/Hello.java", "c:/foo/src") is "my/package/Hello.java"

Returns:
null if file is not in dir (including recursive subdirectories)

getRelativePath

public static String getRelativePath(File file,
                                     List<File> dirs)
getRelativePath("c:/foo/src/my/package/Hello.java", ["c:/bar", "c:/foo/src"]) is "my/package/Hello.java".

Relative path is composed of slashes. Windows backslaches are replaced by /

Returns:
null if file is not in dir (including recursive subdirectories)

getFileFromBuildDirectory

public File getFileFromBuildDirectory(String filename)
Specified by:
getFileFromBuildDirectory in interface ProjectFileSystem

toResource

public Resource toResource(File file)
Specified by:
toResource in interface ProjectFileSystem


Copyright © 2009-2010 SonarSource. All Rights Reserved.