org.sonar.api.resources
Class DefaultProjectFileSystem

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

public class DefaultProjectFileSystem
extends java.lang.Object
implements ProjectFileSystem


Constructor Summary
DefaultProjectFileSystem(Project project)
           
 
Method Summary
 DefaultProjectFileSystem addSourceDir(java.io.File dir)
           
 DefaultProjectFileSystem addTestDir(java.io.File dir)
           
 java.io.File getBasedir()
          Basedir is the project root directory.
 java.io.File getBuildDir()
          Build directory is by default "target" in maven projects.
 java.io.File getBuildOutputDir()
           
 java.io.File getFileFromBuildDirectory(java.lang.String filename)
           
 java.util.List<java.io.File> getJavaSourceFiles()
           
static java.lang.String getRelativePath(java.io.File file, java.io.File dir)
          getRelativePath("c:/foo/src/my/package/Hello.java", "c:/foo/src") is "my/package/Hello.java"
static java.lang.String getRelativePath(java.io.File file, java.util.List<java.io.File> dirs)
          getRelativePath("c:/foo/src/my/package/Hello.java", ["c:/bar", "c:/foo/src"]) is "my/package/Hello.java".
 java.io.File getReportOutputDir()
           
 java.io.File getSonarWorkingDirectory()
           
 java.nio.charset.Charset getSourceCharset()
          Source encoding.
 java.util.List<java.io.File> getSourceDirs()
           
 java.util.List<java.io.File> getSourceFiles(Language... langs)
           
 java.util.List<java.io.File> getTestDirs()
           
 java.util.List<java.io.File> getTestFiles(Language... langs)
           
 boolean hasJavaSourceFiles()
           
 boolean hasTestFiles(Language lang)
           
 java.io.File resolvePath(java.lang.String path)
          Get file from path.
 Resource toResource(java.io.File file)
           
protected static java.io.File writeToFile(java.lang.String content, java.io.File dir, java.lang.String fileName)
           
 java.io.File writeToWorkingDirectory(java.lang.String content, java.lang.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 java.nio.charset.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 java.io.File getBasedir()
Basedir is the project root directory.

Specified by:
getBasedir in interface ProjectFileSystem

getBuildDir

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

Specified by:
getBuildDir in interface ProjectFileSystem

getBuildOutputDir

public java.io.File getBuildOutputDir()
Specified by:
getBuildOutputDir in interface ProjectFileSystem

getSourceDirs

public java.util.List<java.io.File> getSourceDirs()
Specified by:
getSourceDirs in interface ProjectFileSystem

addSourceDir

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

getTestDirs

public java.util.List<java.io.File> getTestDirs()
Specified by:
getTestDirs in interface ProjectFileSystem

addTestDir

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

getReportOutputDir

public java.io.File getReportOutputDir()
Specified by:
getReportOutputDir in interface ProjectFileSystem

getSonarWorkingDirectory

public java.io.File getSonarWorkingDirectory()
Specified by:
getSonarWorkingDirectory in interface ProjectFileSystem

resolvePath

public java.io.File resolvePath(java.lang.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 java.util.List<java.io.File> getSourceFiles(Language... langs)
Specified by:
getSourceFiles in interface ProjectFileSystem
Parameters:
langs - filter on languages. No filter if null.

getJavaSourceFiles

public java.util.List<java.io.File> getJavaSourceFiles()
Specified by:
getJavaSourceFiles in interface ProjectFileSystem

hasJavaSourceFiles

public boolean hasJavaSourceFiles()
Specified by:
hasJavaSourceFiles in interface ProjectFileSystem

getTestFiles

public java.util.List<java.io.File> getTestFiles(Language... langs)
Specified by:
getTestFiles in interface ProjectFileSystem

hasTestFiles

public boolean hasTestFiles(Language lang)
Specified by:
hasTestFiles in interface ProjectFileSystem

writeToWorkingDirectory

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

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

writeToFile

protected static java.io.File writeToFile(java.lang.String content,
                                          java.io.File dir,
                                          java.lang.String fileName)
                                   throws java.io.IOException
Throws:
java.io.IOException

getRelativePath

public static java.lang.String getRelativePath(java.io.File file,
                                               java.io.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 java.lang.String getRelativePath(java.io.File file,
                                               java.util.List<java.io.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 java.io.File getFileFromBuildDirectory(java.lang.String filename)
Specified by:
getFileFromBuildDirectory in interface ProjectFileSystem

toResource

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


Copyright © 2009 SonarSource SA. All Rights Reserved.