org.sonar.api.resources
Class File

java.lang.Object
  extended by org.sonar.api.resources.Resource
      extended by org.sonar.api.resources.File
All Implemented Interfaces:
Serializable

public class File
extends Resource

This class is an implementation of a resource of type FILE

Since:
1.10
See Also:
Serialized Form

Field Summary
static String SCOPE
           
 
Fields inherited from class org.sonar.api.resources.Resource
QUALIFIER_CLASS, QUALIFIER_DIRECTORY, QUALIFIER_FIELD, QUALIFIER_FILE, QUALIFIER_LIB, QUALIFIER_METHOD, QUALIFIER_MODULE, QUALIFIER_PACKAGE, QUALIFIER_PROJECT, QUALIFIER_SUBVIEW, QUALIFIER_UNIT_TEST_CLASS, QUALIFIER_VIEW, SCOPE_ENTITY, SCOPE_SET, SCOPE_SPACE
 
Constructor Summary
File(Language language, String relativePathFromSourceDir)
          Deprecated. since 4.2 use fromIOFile(java.io.File, Project)
File(Language language, String relativeDirectoryPathFromSourceDir, String filename)
          Deprecated. since 4.2 use fromIOFile(java.io.File, Project)
File(String relativePathFromSourceDir)
          Deprecated. since 4.2 use fromIOFile(java.io.File, Project)
File(String relativeDirectoryPathFromSourceDir, String filename)
          Deprecated. since 4.2 use fromIOFile(java.io.File, Project)
 
Method Summary
static File create(String relativePathFromBasedir)
          Create a File that is partially initialized.
static File create(String relativePathFromBasedir, String relativePathFromSourceDir, Language language, boolean unitTest)
          Create a file that is fully initialized.
static File fromIOFile(File file, List<File> sourceDirs)
          Deprecated. since 4.2 use fromIOFile(java.io.File, Project)
static File fromIOFile(File file, Project module)
          Creates a File from an absolute File and a module.
 String getDescription()
          
 Language getLanguage()
          
 String getLongName()
          
 String getName()
          
 Directory getParent()
          The parent is used to build the resources tree, for example for relations between classes, packages and projects.
 String getQualifier()
          Returns the qualifier associated to this File.
 String getScope()
           
 boolean matchFilePattern(String antPattern)
          Check resource against an Ant pattern, like mypackag?/*Foo.java.
 void setLanguage(Language language)
          Sets the language of the file
 void setQualifier(String qualifier)
           
 String toString()
           
 
Methods inherited from class org.sonar.api.resources.Resource
equals, getDeprecatedKey, getEffectiveKey, getId, getKey, getPath, hashCode, isExcluded, normalize, setDeprecatedKey, setEffectiveKey, setExcluded, setId, setKey, setPath
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SCOPE

public static final String SCOPE
See Also:
Constant Field Values
Constructor Detail

File

@Deprecated
public File(String relativePathFromSourceDir)
Deprecated. since 4.2 use fromIOFile(java.io.File, Project)

File in project. Key is the path relative to project source directories. It is not the absolute path and it does not include the path to source directories. Example : new File("org/sonar/foo.sql"). The absolute path may be c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir is src/main/sql.


File

@Deprecated
public File(String relativeDirectoryPathFromSourceDir,
                       String filename)
Deprecated. since 4.2 use fromIOFile(java.io.File, Project)

Creates a file from its containing directory and name


File

@Deprecated
public File(Language language,
                       String relativePathFromSourceDir)
Deprecated. since 4.2 use fromIOFile(java.io.File, Project)

Creates a File from its language and its key


File

@Deprecated
public File(Language language,
                       String relativeDirectoryPathFromSourceDir,
                       String filename)
Deprecated. since 4.2 use fromIOFile(java.io.File, Project)

Creates a File from language, directory and filename

Method Detail

getParent

public Directory getParent()
The parent is used to build the resources tree, for example for relations between classes, packages and projects.

Return null if the parent is the project.

Specified by:
getParent in class Resource
See Also:
Resource.getParent()

matchFilePattern

public boolean matchFilePattern(String antPattern)
Check resource against an Ant pattern, like mypackag?/*Foo.java. It's used for example to match resource exclusions.

Specified by:
matchFilePattern in class Resource
Parameters:
antPattern - Ant-like pattern (with **, * and ?). It includes file suffixes.
Returns:
true if the resource matches the Ant pattern
See Also:
Resource.matchFilePattern(String)

fromIOFile

@Deprecated
@CheckForNull
public static File fromIOFile(File file,
                                                      List<File> sourceDirs)
Deprecated. since 4.2 use fromIOFile(java.io.File, Project)

Creates a File from an io.file and a list of sources directories


fromIOFile

@CheckForNull
public static File fromIOFile(File file,
                                           Project module)
Creates a File from an absolute File and a module. The returned File can be then passed for example to SensorContext.saveMeasure(Resource, org.sonar.api.measures.Measure).

Parameters:
file - absolute path to a file
module -
Returns:
null if the file is not under module basedir.

getName

public String getName()

Specified by:
getName in class Resource
Returns:
the resource name
See Also:
Resource.getName()

getLongName

public String getLongName()

Specified by:
getLongName in class Resource
Returns:
the resource long name
See Also:
Resource.getLongName()

getDescription

public String getDescription()

Specified by:
getDescription in class Resource
Returns:
the resource description
See Also:
Resource.getDescription()

getLanguage

public Language getLanguage()

Specified by:
getLanguage in class Resource
Returns:
the language of the resource. Only Files have a non null value.
See Also:
Resource.getLanguage()

setLanguage

public void setLanguage(Language language)
Sets the language of the file


getScope

public final String getScope()
Specified by:
getScope in class Resource
Returns:
SCOPE_ENTITY

getQualifier

public String getQualifier()
Returns the qualifier associated to this File. Should be QUALIFIER_FILE or QUALIFIER_UNIT_TEST_CLASS

Specified by:
getQualifier in class Resource
Returns:
the qualifier
See Also:
for the list of qualifiers, to find out if a resource if a class, a unit test,... from its qualifier

setQualifier

public void setQualifier(String qualifier)

create

public static File create(String relativePathFromBasedir)
Create a File that is partially initialized. But that's enough to call for example SensorContext.saveMeasure(Resource, org.sonar.api.measures.Measure) when resources are already indexed. Internal use only.

Since:
4.2

create

public static File create(String relativePathFromBasedir,
                          String relativePathFromSourceDir,
                          Language language,
                          boolean unitTest)
Create a file that is fully initialized. Use for indexing resources. Internal use only.

Since:
4.2

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2014 SonarSource. All Rights Reserved.