Package org.sonar.api.batch.sensor
Interface SensorContext
-
- All Known Implementing Classes:
SensorContextTester
public interface SensorContextSeeSensor.execute(SensorContext)In order to write unit tests you can useSensorContextTester- Since:
- 5.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ActiveRulesactiveRules()Get list of active rules.voidaddContextProperty(java.lang.String key, java.lang.String value)Add a property to the scanner context.Configurationconfig()Get settings of the project.FileSystemfileSystem()Get filesystem of the project.VersiongetSonarQubeVersion()Version of API at runtime, not at compilation time.booleanisCancelled()Test if a cancellation of the analysis was requested.voidmarkForPublishing(InputFile inputFile)Indicate that a file should be published in the report sent to SonarQube.InputModulemodule()Deprecated.since 7.6 modules are deprecated.NewAdHocRulenewAdHocRule()Fluent builder to create a newAdHocRule.NewAnalysisErrornewAnalysisError()Builder to declare errors that happened while processing a source file.NewCoveragenewCoverage()Builder to define coverage in a file.NewCpdTokensnewCpdTokens()Builder to define CPD tokens in a file.NewExternalIssuenewExternalIssue()Fluent builder to create a newExternalIssue.NewHighlightingnewHighlighting()Builder to define highlighting of a file.NewIssuenewIssue()Fluent builder to create a newIssue.<G extends java.io.Serializable>
NewMeasure<G>newMeasure()Fluent builder to create a newMeasure.NewSignificantCodenewSignificantCode()Builder to declare which parts of the code is significant code.NewSymbolTablenewSymbolTable()Builder to define symbol table of a file.InputProjectproject()The current project.SonarRuntimeruntime()Runtime information, mainly: to be able to have different behaviours between SonarQube and SonarLint to enable new features depending on version of API available at runtimeSettingssettings()Deprecated.since 6.5 useconfig()
-
-
-
Method Detail
-
config
Configuration config()
Get settings of the project.- Since:
- 6.5
-
fileSystem
FileSystem fileSystem()
Get filesystem of the project.
-
activeRules
ActiveRules activeRules()
Get list of active rules.
-
module
@Deprecated InputModule module()
Deprecated.since 7.6 modules are deprecated. Useproject()instead.- Throws:
java.lang.UnsupportedOperationException- for globalProjectSensors- Since:
- 5.5
-
project
InputProject project()
The current project.- Since:
- 7.6
-
getSonarQubeVersion
Version getSonarQubeVersion()
Version of API at runtime, not at compilation time. It's a shortcut onruntime().getApiVersion()since 6.0.- Since:
- 5.5
- See Also:
since version 6.0.
-
runtime
SonarRuntime runtime()
Runtime information, mainly:- to be able to have different behaviours between SonarQube and SonarLint
- to enable new features depending on version of API available at runtime
- Since:
- 6.0
-
isCancelled
boolean isCancelled()
Test if a cancellation of the analysis was requested. Sensors should periodically test this flag and gracefully stop if value istrue. For example it could be tested between each processed file.- Since:
- 6.0
-
newMeasure
<G extends java.io.Serializable> NewMeasure<G> newMeasure()
Fluent builder to create a newMeasure. Don't forget to callNewMeasure.save()once all parameters are provided.
-
newIssue
NewIssue newIssue()
Fluent builder to create a newIssue. Don't forget to callNewIssue.save()once all parameters are provided.
-
newExternalIssue
NewExternalIssue newExternalIssue()
Fluent builder to create a newExternalIssue. Don't forget to callNewExternalIssue.save()once all parameters are provided.- Since:
- 7.2
-
newAdHocRule
NewAdHocRule newAdHocRule()
Fluent builder to create a newAdHocRule. Don't forget to callNewAdHocRule.save()once all parameters are provided.- Since:
- 7.4
-
newHighlighting
NewHighlighting newHighlighting()
Builder to define highlighting of a file. Don't forget to callNewHighlighting.save()once all elements are provided.
-
newSymbolTable
NewSymbolTable newSymbolTable()
Builder to define symbol table of a file. Don't forget to callNewSymbolTable.save()once all symbols are provided.- Since:
- 5.6
-
newCoverage
NewCoverage newCoverage()
Builder to define coverage in a file. Don't forget to callNewCoverage.save().
-
newCpdTokens
NewCpdTokens newCpdTokens()
Builder to define CPD tokens in a file. Don't forget to callNewCpdTokens.save().- Since:
- 5.5
-
newAnalysisError
NewAnalysisError newAnalysisError()
Builder to declare errors that happened while processing a source file. Don't forget to callNewAnalysisError.save().- Since:
- 6.0
-
newSignificantCode
NewSignificantCode newSignificantCode()
Builder to declare which parts of the code is significant code. Ranges that are not reported as significant code will be ignored and won't be considered when calculating which lines were modified. If the significant code is not reported for a file, it is assumed that the entire file is significant code.- Since:
- 7.2
-
addContextProperty
void addContextProperty(java.lang.String key, java.lang.String value)Add a property to the scanner context. This context is available in Compute Engine when processing the report.
The properties starting with"sonar.analysis."are included to the payload of webhooks.- Throws:
java.lang.IllegalArgumentException- if key or value parameter is null- Since:
- 6.1
- See Also:
PostProjectAnalysisTask.ProjectAnalysis.getScannerContext()
-
markForPublishing
void markForPublishing(InputFile inputFile)
Indicate that a file should be published in the report sent to SonarQube. Files are automatically marked if any data is created for it (issues, highlighting, coverage, etc.).- Since:
- 6.3
-
-