I'm working on a Java SonarQube plugin, but am still new to the API and making plugins in general.
I've downloaded the Example SonarQube Plugin (from https://github.com/SonarSource/sonar-examples) and have been playing around with it to try get the hang of it.
For a start, I'm trying to simply show the number of Lines of Code of a selected program. In the html.erb part, I have just added some "Hello World" text as seen below:
<div> Hello World </div>
I already added the metrics option so I think I'm just missing something small.
@WidgetProperty(key = "Metric",
type = WidgetPropertyType.METRIC,
description = "Select a metric (at least one is necessary).",
optional = false )
Essentially, I just want to click the Lines of Code metric in the widget options and display its output.
Any ideas? Thank you very much in advance!
The way to solve the issue is as follows:
Assuming your "Metric" input is as in the question above, the following code in the html.erb file should do the trick in displaying the value of the selected metric.
<h3 align="center"><%= widget_properties['Metric'].description -%></h3>
<%= format_measure(widget_properties['Metric'].key, :url => url_for_drilldown(widget_properties['Metric'].key)) -%>
Hope this helps anyone with the same problem.