简体   繁体   English

如何在自定义的SonarQube插件中显示指标?

[英]How do I display metrics in a custom SonarQube Plugin?

I'm working on a Java SonarQube plugin, but am still new to the API and making plugins in general. 我正在开发Java SonarQube插件,但对于API和制作插件而言仍然是新手。

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. 我已经下载了Example SonarQube插件(来自https://github.com/SonarSource/sonar-examples ),并一直在尝试尝试以解决问题。

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: 在html.erb部分,我刚刚添加了一些“ Hello World”文本,如下所示:

<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. 假设您的“指标”输入与上面的问题相同,则html.erb文件中的以下代码应该可以巧妙地显示所选指标的值。

<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. 希望这对遇到同样问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM