Sonarqube - How to exchange data with Compute Engine MeasureComputer implementation from Sensor

138 views
Skip to first unread message

cool...@gmail.com

unread,
Sep 13, 2017, 3:01:46 PM9/13/17
to SonarQube

I am working on implementing SonarQube plugin for a custom platform specific language. The documentation is very limited and any code examples I see are outdated - usage of Decorators instead of MeasureComputer etc. I went through the sample plugin but it does not have the context I am looking for. My question is - how do I exchange the data between the Sensor and MeasureComputer implementation. The plugin invokes a command-line (vendor specific and I cannot change) that writes the data to a file. I would like the data from this file displayed in the General Metrics screen. In Sensor execute method, I am able to parse the file but I cannot save the Measure as the API has changed now and requires me to save the Measure with .on method that requires an InputFile, but this data is on the entire project and not on a file. I am not able to do a simple save of Metric on the project. I tried using MeasureComputer implementation, but I understand that this runs in Background task on server side, so I thought of setting the property under context.settings.setString("propName", "value") and tried retriving it using (MeasureComputerContext) context.getSettings().getString("propName"). This is not working either.

  1. 1. Can I save a Metric on the context that can be displayed in General inside a Sensor on the project and not the resource (Resource is deprecated) in 5.6.6 version. If so how? Can I call saveMeasure on project level with a Metric?
  2. 2. If above is not possible, how can I store the file content to exchange with MeasureComputer, either add to list of files or set the property or object to be retrieved in MeasureComputer.

Thanks in Advance for your help. I have spent considerable time on this and the documentation leaves a lot to figure out.

cool...@gmail.com

unread,
Sep 14, 2017, 2:04:48 PM9/14/17
to SonarQube
Does anyone have any suggestions on this ?

Julien HENRY

unread,
Sep 15, 2017, 4:09:38 AM9/15/17
to SonarQube
Hi,

To share data between sensor and measure computer, the solution is indeed to use a custom measure, and store it on project/modules.

In your Sensor, this looks like:

@Override
public void execute(SensorContext context) {
  context.newMeasure()
     .forMetric(YourPluginMetric.YOUR_METRIC)
     .on(context.module())
     .withValue(XXXXX)
     .save();
}

Hope that help

Julien

cool...@gmail.com

unread,
Sep 22, 2017, 9:36:08 PM9/22/17
to SonarQube
Thanks a lot @Julien Henry, this worked like a charm.
Reply all
Reply to author
Forward
0 new messages