Class SensorContextTester
java.lang.Object
org.sonar.api.batch.sensor.internal.SensorContextTester
- All Implemented Interfaces:
org.sonar.api.batch.sensor.SensorContext
Utility class to help testing
Sensor. This is not an API and method signature may evolve.
Usage: call create(File) to create an "in memory" implementation of SensorContext with a filesystem initialized with provided baseDir.
You have to manually register inputFiles using:
sensorContextTester.fileSystem().add(new DefaultInputFile("myProjectKey", "src/Foo.java")
.setLanguage("java")
.initMetadata("public class Foo {\n}"));
Then pass it to your Sensor. You can then query elements provided by your sensor using methods allIssues(), ...
-
Method Summary
Modifier and TypeMethodDescriptionorg.sonar.api.batch.rule.ActiveRulesvoidaddContextProperty(String key, String value) voidaddTelemetryProperty(String s, String s1) Collection<org.sonar.api.batch.sensor.rule.AdHocRule>Collection<org.sonar.api.batch.sensor.error.AnalysisError>Collection<org.sonar.api.batch.sensor.issue.ExternalIssue>Collection<org.sonar.api.batch.sensor.issue.Issue>booleanconditions(String fileKey, int line) org.sonar.api.config.Configurationconfig()coveredConditions(String fileKey, int line) List<org.sonar.api.batch.sensor.cpd.internal.TokensLine>static SensorContextTesterstatic SensorContextTesterorg.sonar.api.utils.VersionDefault value is the version of this API at compilation time.List<org.sonar.api.batch.sensor.highlighting.TypeOfText>highlightingTypeAt(String componentKey, int line, int lineOffset) Return list of syntax highlighting applied for a given position in a file.booleanbooleanvoidmarkAsUnchanged(org.sonar.api.batch.fs.InputFile inputFile) voidmarkForPublishing(org.sonar.api.batch.fs.InputFile inputFile) static Integer<G extends Serializable>
org.sonar.api.batch.sensor.measure.Measure<G><G extends Serializable>
org.sonar.api.batch.sensor.measure.Measure<G>Collection<org.sonar.api.batch.sensor.measure.Measure>org.sonar.api.batch.fs.InputModulemodule()org.sonar.api.batch.sensor.rule.NewAdHocRuleorg.sonar.api.batch.sensor.error.NewAnalysisErrororg.sonar.api.batch.sensor.coverage.NewCoverageorg.sonar.api.batch.sensor.cpd.NewCpdTokensorg.sonar.api.batch.sensor.issue.NewExternalIssueorg.sonar.api.batch.sensor.highlighting.NewHighlightingorg.sonar.api.batch.sensor.issue.NewIssuenewIssue()<G extends Serializable>
org.sonar.api.batch.sensor.measure.NewMeasure<G>org.sonar.api.batch.sensor.code.NewSignificantCodeorg.sonar.api.batch.sensor.symbol.NewSymbolTableorg.sonar.api.batch.sensor.cache.WriteCacheorg.sonar.api.batch.sensor.cache.ReadCacheorg.sonar.api.scanner.fs.InputProjectproject()Collection<org.sonar.api.batch.fs.TextRange>referencesForSymbolAt(String componentKey, int line, int lineOffset) Return list of symbol references ranges for the symbol at a given position in a file.org.sonar.api.SonarRuntimeruntime()setActiveRules(org.sonar.api.batch.rule.ActiveRules activeRules) voidsetCacheEnabled(boolean enabled) voidsetCancelled(boolean cancelled) setCanSkipUnchangedFiles(boolean canSkipUnchangedFiles) voidsetNextCache(org.sonar.api.batch.sensor.cache.WriteCache writeCache) voidsetPreviousCache(org.sonar.api.batch.sensor.cache.ReadCache cache) setRuntime(org.sonar.api.SonarRuntime runtime) setSettings(MapSettings settings) settings()org.sonar.api.batch.fs.TextRangesignificantCodeTextRange(String fileKey, int line) static Integer
-
Method Details
-
create
-
create
-
settings
- Specified by:
settingsin interfaceorg.sonar.api.batch.sensor.SensorContext
-
config
public org.sonar.api.config.Configuration config()- Specified by:
configin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setSettings
-
fileSystem
- Specified by:
fileSystemin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setFileSystem
-
activeRules
public org.sonar.api.batch.rule.ActiveRules activeRules()- Specified by:
activeRulesin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setActiveRules
-
getSonarQubeVersion
public org.sonar.api.utils.Version getSonarQubeVersion()Default value is the version of this API at compilation time. You can override it usingsetRuntime(SonarRuntime)to test your Sensor behaviour.- Specified by:
getSonarQubeVersionin interfaceorg.sonar.api.batch.sensor.SensorContext
-
runtime
public org.sonar.api.SonarRuntime runtime()- Specified by:
runtimein interfaceorg.sonar.api.batch.sensor.SensorContext- See Also:
-
setRuntime
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setCancelled
public void setCancelled(boolean cancelled) -
canSkipUnchangedFiles
public boolean canSkipUnchangedFiles()- Specified by:
canSkipUnchangedFilesin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setCanSkipUnchangedFiles
-
module
public org.sonar.api.batch.fs.InputModule module()- Specified by:
modulein interfaceorg.sonar.api.batch.sensor.SensorContext
-
project
public org.sonar.api.scanner.fs.InputProject project()- Specified by:
projectin interfaceorg.sonar.api.batch.sensor.SensorContext
-
newMeasure
- Specified by:
newMeasurein interfaceorg.sonar.api.batch.sensor.SensorContext
-
measures
-
measure
public <G extends Serializable> org.sonar.api.batch.sensor.measure.Measure<G> measure(String componentKey, org.sonar.api.measures.Metric<G> metric) -
measure
public <G extends Serializable> org.sonar.api.batch.sensor.measure.Measure<G> measure(String componentKey, String metricKey) -
newIssue
public org.sonar.api.batch.sensor.issue.NewIssue newIssue()- Specified by:
newIssuein interfaceorg.sonar.api.batch.sensor.SensorContext
-
allIssues
-
newExternalIssue
public org.sonar.api.batch.sensor.issue.NewExternalIssue newExternalIssue()- Specified by:
newExternalIssuein interfaceorg.sonar.api.batch.sensor.SensorContext
-
newAdHocRule
public org.sonar.api.batch.sensor.rule.NewAdHocRule newAdHocRule()- Specified by:
newAdHocRulein interfaceorg.sonar.api.batch.sensor.SensorContext
-
allExternalIssues
-
allAdHocRules
-
allAnalysisErrors
-
lineHits
-
sumOrNull
-
conditions
-
coveredConditions
-
significantCodeTextRange
@CheckForNull public org.sonar.api.batch.fs.TextRange significantCodeTextRange(String fileKey, int line) -
maxOrNull
-
cpdTokens
-
newHighlighting
public org.sonar.api.batch.sensor.highlighting.NewHighlighting newHighlighting()- Specified by:
newHighlightingin interfaceorg.sonar.api.batch.sensor.SensorContext
-
newCoverage
public org.sonar.api.batch.sensor.coverage.NewCoverage newCoverage()- Specified by:
newCoveragein interfaceorg.sonar.api.batch.sensor.SensorContext
-
newCpdTokens
public org.sonar.api.batch.sensor.cpd.NewCpdTokens newCpdTokens()- Specified by:
newCpdTokensin interfaceorg.sonar.api.batch.sensor.SensorContext
-
newSymbolTable
public org.sonar.api.batch.sensor.symbol.NewSymbolTable newSymbolTable()- Specified by:
newSymbolTablein interfaceorg.sonar.api.batch.sensor.SensorContext
-
newAnalysisError
public org.sonar.api.batch.sensor.error.NewAnalysisError newAnalysisError()- Specified by:
newAnalysisErrorin interfaceorg.sonar.api.batch.sensor.SensorContext
-
highlightingTypeAt
public List<org.sonar.api.batch.sensor.highlighting.TypeOfText> highlightingTypeAt(String componentKey, int line, int lineOffset) Return list of syntax highlighting applied for a given position in a file. The result is a list because in theory you can apply several styles to the same range.- Parameters:
componentKey- Key of the file like 'myProjectKey:src/foo.php'line- Line you want to querylineOffset- Offset you want to query.- Returns:
- List of styles applied to this position or empty list if there is no highlighting at this position.
-
referencesForSymbolAt
@CheckForNull public Collection<org.sonar.api.batch.fs.TextRange> referencesForSymbolAt(String componentKey, int line, int lineOffset) Return list of symbol references ranges for the symbol at a given position in a file.- Parameters:
componentKey- Key of the file like 'myProjectKey:src/foo.php'line- Line you want to querylineOffset- Offset you want to query.- Returns:
- List of references for the symbol (potentially empty) or null if there is no symbol at this position.
-
addContextProperty
- Specified by:
addContextPropertyin interfaceorg.sonar.api.batch.sensor.SensorContext
-
getContextProperties
- Returns:
- an immutable map of the context properties defined with
SensorContext.addContextProperty(String, String). - Since:
- 6.1
-
markForPublishing
public void markForPublishing(org.sonar.api.batch.fs.InputFile inputFile) - Specified by:
markForPublishingin interfaceorg.sonar.api.batch.sensor.SensorContext
-
markAsUnchanged
public void markAsUnchanged(org.sonar.api.batch.fs.InputFile inputFile) - Specified by:
markAsUnchangedin interfaceorg.sonar.api.batch.sensor.SensorContext
-
nextCache
public org.sonar.api.batch.sensor.cache.WriteCache nextCache()- Specified by:
nextCachein interfaceorg.sonar.api.batch.sensor.SensorContext
-
setNextCache
public void setNextCache(org.sonar.api.batch.sensor.cache.WriteCache writeCache) -
previousCache
public org.sonar.api.batch.sensor.cache.ReadCache previousCache()- Specified by:
previousCachein interfaceorg.sonar.api.batch.sensor.SensorContext
-
setPreviousCache
public void setPreviousCache(org.sonar.api.batch.sensor.cache.ReadCache cache) -
isCacheEnabled
public boolean isCacheEnabled()- Specified by:
isCacheEnabledin interfaceorg.sonar.api.batch.sensor.SensorContext
-
addTelemetryProperty
- Specified by:
addTelemetryPropertyin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setCacheEnabled
public void setCacheEnabled(boolean enabled) -
newSignificantCode
public org.sonar.api.batch.sensor.code.NewSignificantCode newSignificantCode()- Specified by:
newSignificantCodein interfaceorg.sonar.api.batch.sensor.SensorContext
-