Interface SensorContext


  • public interface SensorContext
    See Sensor.execute(SensorContext) In order to write unit tests you can use SensorContextTester, available in sonar-plugin-api-impl
    Since:
    5.1
    • Method Detail

      • settings

        @Deprecated(since="6.5")
        Settings settings()
        Deprecated.
        since 6.5 use config()
      • 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 by InputFile.status() as InputFile.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. Use project() instead.
        Throws:
        java.lang.UnsupportedOperationException - for global ProjectSensors
        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 replacement
        Version of API at runtime, not at compilation time. It's a shortcut on runtime().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 is true. 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 new Measure. Don't forget to call NewMeasure.save() once all parameters are provided.
      • newIssue

        NewIssue newIssue()
        Fluent builder to create a new Issue. Don't forget to call NewIssue.save() once all parameters are provided.
      • newSymbolTable

        NewSymbolTable newSymbolTable()
        Builder to define symbol table of a file. Don't forget to call NewSymbolTable.save() once all symbols are provided.
        Since:
        5.6
      • 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()