2

I'm working on a Sonar project and I have to make a plugin in order to get metrics and to compute them.

In order to understand how it works, I'd like to try to do the following examples:

  • Get the value (complexity) and to compute it as a double or a float value.
  • Take the complexity value (MetricsCore.COMPLEXITY) and if it's more than 200, write a message to say that it's too complex.
  • Take the number of comments lines and multiply it by 10.

I know that in these examples what I want to do is useless, but it's just to understand how to get the Metrics Core value and take their value, and to create new Metrics. I don't find a lot of documentation....

Thank you very much

For information, I will use Sonar-reference-plugin.

James Dunn
  • 8,064
  • 13
  • 53
  • 87
FlorianR
  • 23
  • 4

1 Answers1

2

You can find our sample plugins here: https://github.com/SonarSource/sonar-examples/tree/master/plugins. "sonar-reference-plugin" should give you lots of information.

This should help you to better understand how things work.

  • 1
    Yes, I work with this example, but on this project, they have to display the RANDOM value but it doesn't work... So I really don't know how to do it. And moreover they doesn't use the metric as a value in order to compute it or to modify it. – FlorianR Mar 29 '13 at 08:25
  • Ok :) I want to get the value of complexity (complexity), compare it with a reference value(ref_complex) that I'll choose, and if complexity > ref_complex, I want to display a warning message :) Thank you :) – FlorianR Mar 29 '13 at 08:37
  • And the problem is when I want to compare the complexity value with a number, it never works :( – FlorianR Mar 29 '13 at 08:39
  • 1
    To get the metric: context.getMeasure(...).getValue() – Fabrice - SonarSource Team Mar 29 '13 at 08:49
  • To create a violation: context.saveViolation(...) – Fabrice - SonarSource Team Mar 29 '13 at 08:53
  • Thank you very much I'll try with those functions – FlorianR Mar 29 '13 at 09:11
  • I have tried this method to get the number of code lines: Measure test_value = context.getMeasure(CoreMetrics.NCLOC); if (test_value != null) { context.saveMeasure(CodeQualityMetrics.TEST, test_value.getValue()); } else { double value2 = 8000; context.saveMeasure(CodeQualityMetrics.TEST, value2); } but everytime i show on Sonar 8000 :( I don't understand why.... – FlorianR Mar 29 '13 at 15:39
  • Please come on sonar DEV mailing list to discuss this. This will be easier than here. – Fabrice - SonarSource Team Mar 29 '13 at 15:47