Package org.sonar.api.batch.sensor
Interface SensorContext
-
public interface SensorContext
SeeSensor.execute(SensorContext)
In order to write unit tests you can use SensorContextTester, available in sonar-plugin-api-impl- Since:
- 5.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ActiveRules
activeRules()
Get list of active rules.void
addContextProperty(java.lang.String key, java.lang.String value)
Add a property to the scanner context.boolean
canSkipUnchangedFiles()
In some situations, there is no need to analyze unchanged files, as reported byInputFile.status()
asInputFile.Status.SAME
, and analyzers can skip reporting any data for those files.Configuration
config()
Get settings of the project.FileSystem
fileSystem()
Get filesystem of the project.Version
getSonarQubeVersion()
Deprecated.since 10.0.boolean
isCacheEnabled()
Returns true if caching is enabled.boolean
isCancelled()
Test if a cancellation of the analysis was requested.void
markAsUnchanged(InputFile inputFile)
Marks a file as not having any data changed since the last analysis, including issues.void
markForPublishing(InputFile inputFile)
Indicate that a file should be published in the report sent to SonarQube.InputModule
module()
Deprecated.since 7.6 modules are deprecated.NewAdHocRule
newAdHocRule()
Fluent builder to create a newAdHocRule
.NewAnalysisError
newAnalysisError()
Builder to declare errors that happened while processing a source file.NewCoverage
newCoverage()
Builder to define coverage in a file.NewCpdTokens
newCpdTokens()
Builder to define CPD tokens in a file.NewExternalIssue
newExternalIssue()
Fluent builder to create a newExternalIssue
.NewHighlighting
newHighlighting()
Builder to define highlighting of a file.NewIssue
newIssue()
Fluent builder to create a newIssue
.<G extends java.io.Serializable>
NewMeasure<G>newMeasure()
Fluent builder to create a newMeasure
.NewSignificantCode
newSignificantCode()
Builder to declare which parts of the code is significant code.NewSymbolTable
newSymbolTable()
Builder to define symbol table of a file.WriteCache
nextCache()
Access object to write cache that will be stored and made available in a future analysis.ReadCache
previousCache()
Access object to read cached data.InputProject
project()
The current project.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 runtimeSettings
settings()
Deprecated.since 6.5 useconfig()
-
-
-
Method Detail
-
config
Configuration config()
Get settings of the project.- Since:
- 6.5
-
canSkipUnchangedFiles
boolean canSkipUnchangedFiles()
In some situations, there is no need to analyze unchanged files, as reported byInputFile.status()
asInputFile.Status.SAME
, and analyzers can skip reporting any data for those files. Plugins should be prepared for the flag to be always false in the future.- Since:
- 9.4
-
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 globalProjectSensor
s- Since:
- 5.5
-
project
InputProject project()
The current project.- Since:
- 7.6
-
getSonarQubeVersion
@Deprecated(since="10.0") Version getSonarQubeVersion()
Deprecated.since 10.0. The name is confusing: the API version is different from the SonarQube version since the extraction. Use the advised replacementVersion 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
-
markAsUnchanged
@Beta void markAsUnchanged(InputFile inputFile)
Marks a file as not having any data changed since the last analysis, including issues. The platform might perform optimizations based on this flag. The sensor is still expected to report all data for the file.- Since:
- 9.9
-
nextCache
@Beta WriteCache nextCache()
Access object to write cache that will be stored and made available in a future analysis. If cache is disabled, the methods in the returned object will have no effect. This API is experimental and can be changed or dropped at any time.- Since:
- 9.4
- See Also:
isCacheEnabled()
-
previousCache
@Beta ReadCache previousCache()
Access object to read cached data. The origin of the cached data is not specified and could come from a different branch. If cache is disabled, the methods in the returned object will have no effect. This API is experimental and can be changed or dropped at any time.- Since:
- 9.4
- See Also:
isCacheEnabled()
-
isCacheEnabled
@Beta boolean isCacheEnabled()
Returns true if caching is enabled. This API is experimental and can be changed or dropped at any time.- Since:
- 9.4
- See Also:
nextCache()
,previousCache()
-
-