org.sonar.batch
Class DefaultSensorContext

java.lang.Object
  extended by org.sonar.batch.DefaultSensorContext
All Implemented Interfaces:
SensorContext

public class DefaultSensorContext
extends Object
implements SensorContext


Constructor Summary
DefaultSensorContext(SonarIndex index, Project project)
           
 
Method Summary
 Event createEvent(Resource resource, String name, String description, String category, Date date)
          Creates an event for a given date
 void deleteEvent(Event event)
          Deletes an event
 void deleteLink(String key)
          remove a link.
 Collection<Resource> getChildren(Resource reference)
           
 Set<Dependency> getDependencies()
           
 List<Event> getEvents(Resource resource)
           
 Collection<Dependency> getIncomingDependencies(Resource to)
           
 Measure getMeasure(Metric metric)
          Find a project measure
 Measure getMeasure(Resource resource, Metric metric)
          Find a measure for this project
<M> M
getMeasures(MeasuresFilter<M> filter)
          All measures of the project.
<M> M
getMeasures(Resource resource, MeasuresFilter<M> filter)
          Find all measures for this project.
 Collection<Dependency> getOutgoingDependencies(Resource from)
           
 Resource getParent(Resource reference)
           
 Project getProject()
           
 Resource getResource(Resource resource)
          Search for an indexed resource.
 boolean index(Resource resource)
          Indexes a resource as a direct child of project.
 boolean index(Resource resource, Resource parentReference)
          Indexes a resource.
 boolean isExcluded(Resource reference)
          Returns true if the referenced resource is indexed and excluded.
 boolean isIndexed(Resource reference, boolean acceptExcluded)
          Returns true if the referenced resource is indexed.
 Dependency saveDependency(Dependency dependency)
          Build a new dependency : from depends upon to.
 void saveLink(ProjectLink link)
          add a link to an external page like project homepage, sources (subversion, ...), continuous integration server...
 Measure saveMeasure(Measure measure)
          Add a measure on project
 Measure saveMeasure(Metric metric, Double value)
          Add a measure on project
 Measure saveMeasure(Resource resource, Measure measure)
          Add or update a measure.
 Measure saveMeasure(Resource resource, Metric metric, Double value)
          Add or update a measure.
 String saveResource(Resource resource)
          Key is updated when saving the resource.
 boolean saveResource(Resource resource, Resource parentReference)
           
 void saveSource(Resource reference, String source)
          Save the source code of a file.
 void saveViolation(Violation violation)
          Save a coding rule violation.
 void saveViolation(Violation violation, boolean force)
          Save a coding rule violation.
 void saveViolations(Collection<Violation> violations)
          Saves a list of violations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSensorContext

public DefaultSensorContext(SonarIndex index,
                            Project project)
Method Detail

getProject

public Project getProject()

index

public boolean index(Resource resource)
Description copied from interface: SensorContext
Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.

Specified by:
index in interface SensorContext
Returns:
false if the resource is excluded

index

public boolean index(Resource resource,
                     Resource parentReference)
Description copied from interface: SensorContext
Indexes a resource. This method does nothing if the resource is already indexed.

Specified by:
index in interface SensorContext
Parameters:
resource - the resource to index. Not nullable
parentReference - a reference to the parent. If null, the the resource is indexed as a direct child of project.
Returns:
false if the parent is not indexed or if the resource is excluded

isExcluded

public boolean isExcluded(Resource reference)
Description copied from interface: SensorContext
Returns true if the referenced resource is indexed and excluded.

Specified by:
isExcluded in interface SensorContext

isIndexed

public boolean isIndexed(Resource reference,
                         boolean acceptExcluded)
Description copied from interface: SensorContext
Returns true if the referenced resource is indexed.

Specified by:
isIndexed in interface SensorContext

getParent

public Resource getParent(Resource reference)
Specified by:
getParent in interface SensorContext

getChildren

public Collection<Resource> getChildren(Resource reference)
Specified by:
getChildren in interface SensorContext

getMeasure

public Measure getMeasure(Metric metric)
Description copied from interface: SensorContext
Find a project measure

Specified by:
getMeasure in interface SensorContext

getMeasures

public <M> M getMeasures(MeasuresFilter<M> filter)
Description copied from interface: SensorContext
All measures of the project. Never return null.

Specified by:
getMeasures in interface SensorContext

saveMeasure

public Measure saveMeasure(Measure measure)
Description copied from interface: SensorContext
Add a measure on project

Specified by:
saveMeasure in interface SensorContext

saveMeasure

public Measure saveMeasure(Metric metric,
                           Double value)
Description copied from interface: SensorContext
Add a measure on project

Specified by:
saveMeasure in interface SensorContext

getMeasure

public Measure getMeasure(Resource resource,
                          Metric metric)
Description copied from interface: SensorContext
Find a measure for this project

Specified by:
getMeasure in interface SensorContext

saveResource

public String saveResource(Resource resource)
Description copied from interface: SensorContext
Key is updated when saving the resource.

Specified by:
saveResource in interface SensorContext
Returns:
the key as saved in database. Null if the resource is set as excluded.

saveResource

public boolean saveResource(Resource resource,
                            Resource parentReference)

getResource

public Resource getResource(Resource resource)
Description copied from interface: SensorContext
Search for an indexed resource.

Specified by:
getResource in interface SensorContext
Parameters:
resource - the resource reference
Returns:
the indexed resource, null if it's not indexed

getMeasures

public <M> M getMeasures(Resource resource,
                         MeasuresFilter<M> filter)
Description copied from interface: SensorContext
Find all measures for this project. Never return null.

Specified by:
getMeasures in interface SensorContext

saveMeasure

public Measure saveMeasure(Resource resource,
                           Metric metric,
                           Double value)
Description copied from interface: SensorContext
Add or update a measure.

The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as excluded.

Specified by:
saveMeasure in interface SensorContext

saveMeasure

public Measure saveMeasure(Resource resource,
                           Measure measure)
Description copied from interface: SensorContext
Add or update a measure.

The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as excluded.

Specified by:
saveMeasure in interface SensorContext

saveViolation

public void saveViolation(Violation violation,
                          boolean force)
Description copied from interface: SensorContext
Save a coding rule violation.

Specified by:
saveViolation in interface SensorContext
force - allows to force creation of violation even if it was supressed by ViolationFilter

saveViolation

public void saveViolation(Violation violation)
Description copied from interface: SensorContext
Save a coding rule violation.

Specified by:
saveViolation in interface SensorContext

saveViolations

public void saveViolations(Collection<Violation> violations)
Description copied from interface: SensorContext
Saves a list of violations.

Specified by:
saveViolations in interface SensorContext

saveDependency

public Dependency saveDependency(Dependency dependency)
Description copied from interface: SensorContext
Build a new dependency : from depends upon to. The dependency is NOT saved. The method saveDependency() must still be executed.

Specified by:
saveDependency in interface SensorContext

getDependencies

public Set<Dependency> getDependencies()
Specified by:
getDependencies in interface SensorContext

getIncomingDependencies

public Collection<Dependency> getIncomingDependencies(Resource to)
Specified by:
getIncomingDependencies in interface SensorContext

getOutgoingDependencies

public Collection<Dependency> getOutgoingDependencies(Resource from)
Specified by:
getOutgoingDependencies in interface SensorContext

saveSource

public void saveSource(Resource reference,
                       String source)
Description copied from interface: SensorContext
Save the source code of a file. The file must be have been indexed before.

Specified by:
saveSource in interface SensorContext

saveLink

public void saveLink(ProjectLink link)
Description copied from interface: SensorContext
add a link to an external page like project homepage, sources (subversion, ...), continuous integration server... Example : context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com)

Specified by:
saveLink in interface SensorContext

deleteLink

public void deleteLink(String key)
Description copied from interface: SensorContext
remove a link. It does not fail if key is unknown.

Specified by:
deleteLink in interface SensorContext

getEvents

public List<Event> getEvents(Resource resource)
Specified by:
getEvents in interface SensorContext
Parameters:
resource - set null for project events

createEvent

public Event createEvent(Resource resource,
                         String name,
                         String description,
                         String category,
                         Date date)
Description copied from interface: SensorContext
Creates an event for a given date

Specified by:
createEvent in interface SensorContext
name - the event name
description - the event description
category - the event category
date - the event date
Returns:
the created event

deleteEvent

public void deleteEvent(Event event)
Description copied from interface: SensorContext
Deletes an event

Specified by:
deleteEvent in interface SensorContext
Parameters:
event - the event to delete


Copyright © 2009-2012 SonarSource. All Rights Reserved.