1
votes

I'm trying to create a custom sonar plugin that consists of a widget on the global dashboard.

I want this to display a "global" metric. So for example, a metric showing the number of lines across all projects.

Is this possible, if so how can I go about this? I can only find example projects that run project specific metrics. They output them in the ruby template like this: format_measure('random'). I am guessing this format measure only works in project context.

The documentation is extremely light on this whole process. So if anyone knows of any good documentation or guides that would also be useful, currently trying to piece together what I want to do from about 10 other plugins.

The only documentation I have found is here: http://docs.sonarqube.org/display/SONAR/Developing+Plugins

2

2 Answers

1
votes

To my knowledge, there is no such concept as a global metric/measure in SonarQube. Aggregating metrics across projects is one of the features of the (commercial) Portfolio Management plugin.

If I were to develop such kind of plugin by myself, I would probably do the aggregation based on the result of a Measure Filter.

1
votes

You can create global widgets by annotating them with the org.sonar.api.web.WidgetScope annotation, giving WidgetScope.GLOBAL as its argument:

import org.sonar.api.web.WidgetScope;

@WidgetScope(GLOBAL)
public class ExampleWidget extends AbstractRubyTemplate implements RubyRailsWidget {
  ...

Source: http://sonarqube.15.x6.nabble.com/sonar-dev-Global-dashboards-and-plugin-widgets-in-Sonar-3-1-td4999250.html

I do not know which ruby templating functions are available for global widgets.