Class SensorContextTester
- java.lang.Object
-
- org.sonar.api.batch.sensor.internal.SensorContextTester
-
- All Implemented Interfaces:
org.sonar.api.batch.sensor.SensorContext
public class SensorContextTester extends java.lang.Object implements org.sonar.api.batch.sensor.SensorContextUtility class to help testingSensor. This is not an API and method signature may evolve.Usage: call
create(File)to create an "in memory" implementation ofSensorContextwith 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 methodsallIssues(), ...
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.sonar.api.batch.rule.ActiveRulesactiveRules()voidaddContextProperty(java.lang.String key, java.lang.String value)java.util.Collection<org.sonar.api.batch.sensor.rule.AdHocRule>allAdHocRules()java.util.Collection<org.sonar.api.batch.sensor.error.AnalysisError>allAnalysisErrors()java.util.Collection<org.sonar.api.batch.sensor.issue.ExternalIssue>allExternalIssues()java.util.Collection<org.sonar.api.batch.sensor.issue.Issue>allIssues()java.lang.Integerconditions(java.lang.String fileKey, int line)org.sonar.api.config.Configurationconfig()java.lang.IntegercoveredConditions(java.lang.String fileKey, int line)java.util.List<org.sonar.api.batch.sensor.cpd.internal.TokensLine>cpdTokens(java.lang.String componentKey)static SensorContextTestercreate(java.io.File moduleBaseDir)static SensorContextTestercreate(java.nio.file.Path moduleBaseDir)DefaultFileSystemfileSystem()java.util.Map<java.lang.String,java.lang.String>getContextProperties()org.sonar.api.utils.VersiongetSonarQubeVersion()Default value is the version of this API at compilation time.java.util.List<org.sonar.api.batch.sensor.highlighting.TypeOfText>highlightingTypeAt(java.lang.String componentKey, int line, int lineOffset)Return list of syntax highlighting applied for a given position in a file.booleanisCancelled()java.lang.IntegerlineHits(java.lang.String fileKey, int line)voidmarkForPublishing(org.sonar.api.batch.fs.InputFile inputFile)static java.lang.IntegermaxOrNull(java.lang.Integer o1, java.lang.Integer o2)<G extends java.io.Serializable>
org.sonar.api.batch.sensor.measure.Measure<G>measure(java.lang.String componentKey, java.lang.String metricKey)<G extends java.io.Serializable>
org.sonar.api.batch.sensor.measure.Measure<G>measure(java.lang.String componentKey, org.sonar.api.measures.Metric<G> metric)java.util.Collection<org.sonar.api.batch.sensor.measure.Measure>measures(java.lang.String componentKey)org.sonar.api.batch.fs.InputModulemodule()org.sonar.api.batch.sensor.rule.NewAdHocRulenewAdHocRule()org.sonar.api.batch.sensor.error.NewAnalysisErrornewAnalysisError()org.sonar.api.batch.sensor.coverage.NewCoveragenewCoverage()org.sonar.api.batch.sensor.cpd.NewCpdTokensnewCpdTokens()org.sonar.api.batch.sensor.issue.NewExternalIssuenewExternalIssue()org.sonar.api.batch.sensor.highlighting.NewHighlightingnewHighlighting()org.sonar.api.batch.sensor.issue.NewIssuenewIssue()<G extends java.io.Serializable>
org.sonar.api.batch.sensor.measure.NewMeasure<G>newMeasure()org.sonar.api.batch.sensor.code.NewSignificantCodenewSignificantCode()org.sonar.api.batch.sensor.symbol.NewSymbolTablenewSymbolTable()org.sonar.api.scanner.fs.InputProjectproject()java.util.Collection<org.sonar.api.batch.fs.TextRange>referencesForSymbolAt(java.lang.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()SensorContextTestersetActiveRules(org.sonar.api.batch.rule.ActiveRules activeRules)voidsetCancelled(boolean cancelled)SensorContextTestersetFileSystem(DefaultFileSystem fs)SensorContextTestersetRuntime(org.sonar.api.SonarRuntime runtime)SensorContextTestersetSettings(org.sonar.api.config.Settings settings)org.sonar.api.config.Settingssettings()org.sonar.api.batch.fs.TextRangesignificantCodeTextRange(java.lang.String fileKey, int line)static java.lang.IntegersumOrNull(java.lang.Integer o1, java.lang.Integer o2)
-
-
-
Method Detail
-
create
public static SensorContextTester create(java.io.File moduleBaseDir)
-
create
public static SensorContextTester create(java.nio.file.Path moduleBaseDir)
-
settings
public org.sonar.api.config.Settings 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
public SensorContextTester setSettings(org.sonar.api.config.Settings settings)
-
fileSystem
public DefaultFileSystem fileSystem()
- Specified by:
fileSystemin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setFileSystem
public SensorContextTester setFileSystem(DefaultFileSystem fs)
-
activeRules
public org.sonar.api.batch.rule.ActiveRules activeRules()
- Specified by:
activeRulesin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setActiveRules
public SensorContextTester setActiveRules(org.sonar.api.batch.rule.ActiveRules activeRules)
-
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:
to override defaults (SonarQube scanner with version of this API as used at compilation time).
-
setRuntime
public SensorContextTester setRuntime(org.sonar.api.SonarRuntime runtime)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceorg.sonar.api.batch.sensor.SensorContext
-
setCancelled
public void setCancelled(boolean cancelled)
-
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
public <G extends java.io.Serializable> org.sonar.api.batch.sensor.measure.NewMeasure<G> newMeasure()
- Specified by:
newMeasurein interfaceorg.sonar.api.batch.sensor.SensorContext
-
measures
public java.util.Collection<org.sonar.api.batch.sensor.measure.Measure> measures(java.lang.String componentKey)
-
measure
public <G extends java.io.Serializable> org.sonar.api.batch.sensor.measure.Measure<G> measure(java.lang.String componentKey, org.sonar.api.measures.Metric<G> metric)
-
measure
public <G extends java.io.Serializable> org.sonar.api.batch.sensor.measure.Measure<G> measure(java.lang.String componentKey, java.lang.String metricKey)
-
newIssue
public org.sonar.api.batch.sensor.issue.NewIssue newIssue()
- Specified by:
newIssuein interfaceorg.sonar.api.batch.sensor.SensorContext
-
allIssues
public java.util.Collection<org.sonar.api.batch.sensor.issue.Issue> 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
public java.util.Collection<org.sonar.api.batch.sensor.issue.ExternalIssue> allExternalIssues()
-
allAdHocRules
public java.util.Collection<org.sonar.api.batch.sensor.rule.AdHocRule> allAdHocRules()
-
allAnalysisErrors
public java.util.Collection<org.sonar.api.batch.sensor.error.AnalysisError> allAnalysisErrors()
-
lineHits
@CheckForNull public java.lang.Integer lineHits(java.lang.String fileKey, int line)
-
sumOrNull
@CheckForNull public static java.lang.Integer sumOrNull(@Nullable java.lang.Integer o1, @Nullable java.lang.Integer o2)
-
conditions
@CheckForNull public java.lang.Integer conditions(java.lang.String fileKey, int line)
-
coveredConditions
@CheckForNull public java.lang.Integer coveredConditions(java.lang.String fileKey, int line)
-
significantCodeTextRange
@CheckForNull public org.sonar.api.batch.fs.TextRange significantCodeTextRange(java.lang.String fileKey, int line)
-
maxOrNull
@CheckForNull public static java.lang.Integer maxOrNull(@Nullable java.lang.Integer o1, @Nullable java.lang.Integer o2)
-
cpdTokens
@CheckForNull public java.util.List<org.sonar.api.batch.sensor.cpd.internal.TokensLine> cpdTokens(java.lang.String componentKey)
-
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 java.util.List<org.sonar.api.batch.sensor.highlighting.TypeOfText> highlightingTypeAt(java.lang.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 java.util.Collection<org.sonar.api.batch.fs.TextRange> referencesForSymbolAt(java.lang.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
public void addContextProperty(java.lang.String key, java.lang.String value)- Specified by:
addContextPropertyin interfaceorg.sonar.api.batch.sensor.SensorContext
-
getContextProperties
public java.util.Map<java.lang.String,java.lang.String> 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
-
newSignificantCode
public org.sonar.api.batch.sensor.code.NewSignificantCode newSignificantCode()
- Specified by:
newSignificantCodein interfaceorg.sonar.api.batch.sensor.SensorContext
-
-