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

Since:
1.10

Constructor Summary
DefaultProjectFileSystem(Project project)
           
 
Method Summary
 DefaultProjectFileSystem addSourceDir(File dir)
           
 DefaultProjectFileSystem addTestDir(File dir)
           
 File getBasedir()
          Basedir is the project root directory.
 File getBuildDir()
          Build directory is by default "target" in maven projects.
 File getBuildOutputDir()
           
 File getFileFromBuildDirectory(String filename)
           
 List<File> getJavaSourceFiles()
          Java source files, excluding unit tests and files matching project exclusion patterns.
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()
           
 List<File> getSourceFiles(Language... langs)
          Source files, excluding unit tests and files matching project exclusion patterns.
 List<File> getTestDirs()
           
 List<File> getTestFiles(Language... langs)
          Unit test files, excluding files matching project exclusion patterns.
 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)
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

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()
Specified by:
getBuildOutputDir in interface ProjectFileSystem

getSourceDirs

public List<File> getSourceDirs()
Specified by:
getSourceDirs in interface ProjectFileSystem

addSourceDir

public DefaultProjectFileSystem addSourceDir(File dir)
Specified by:
addSourceDir in interface ProjectFileSystem

getTestDirs

public List<File> getTestDirs()
Specified by:
getTestDirs in interface ProjectFileSystem

addTestDir

public DefaultProjectFileSystem addTestDir(File dir)
Specified by:
addTestDir in interface ProjectFileSystem

getReportOutputDir

public File getReportOutputDir()
Specified by:
getReportOutputDir in interface ProjectFileSystem

getSonarWorkingDirectory

public File getSonarWorkingDirectory()
Specified by:
getSonarWorkingDirectory in interface ProjectFileSystem

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)
Description copied from interface: ProjectFileSystem
Source files, excluding unit tests and files matching project exclusion patterns.

Specified by:
getSourceFiles in interface ProjectFileSystem
Parameters:
langs - language filter. Check all files, whatever their language, if null or empty.

getJavaSourceFiles

public List<File> getJavaSourceFiles()
Description copied from interface: ProjectFileSystem
Java source files, excluding unit tests and files matching project exclusion patterns. Shortcut for getSourceFiles(Java.INSTANCE)

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

getTestFiles

public List<File> getTestFiles(Language... langs)
Description copied from interface: ProjectFileSystem
Unit test files, excluding files matching project exclusion patterns.

Specified by:
getTestFiles in interface ProjectFileSystem

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

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 SonarSource SA. All Rights Reserved.