SensorContext getMeasure and saveMeasure


I’ve been using below features of sonarqube 4.5:

  1. org.sonar.api.issue.Issuable class
  2. getMeasure and saveMeasure methods in SensorContext interface

Now I’m moving to sonarqube 8.9.2 LTS, I couldn’t find a replacement for the Issuable class, and I don’t know if there’s actually an alternative for this class.
I’ve found a replacement for saveMeasure which is the SensorContext.newMeasure method but for the getMeasure method I couldn’t get any, is there an alternative?

Thanks for your help!

Hi @radwane

This will be a bit difficult to tell you if there is a replacement without knowing your use case.

The “new” API is much more restrictive (for good reasons :slight_smile: ). A Sensor can only “save” measures, using the SensorContext.newMeasure API as you already discovered.
Then if you need to aggregate measure in a later stage, you should have a look at the MeasureComputer extension point that allows to read other measures. Please have a look at sonar-custom-plugin-example/src/main/java/org/sonarsource/plugins/example/measures at 8.x · Sonar for examples.

1 Like

Hi @Julien_HENRY

Thanks for your reply!

For the Issuable class, I was using it to save issues on a given InputFile. Now, I’m no more using this method, since I execute the SensorContext.newMeasure method whithin the rule itself.
For the measure reading part, I’m going to get a look at the MeasureComputer extension.

Thank you again! your reply turned out to be really helpful.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.