Hello eveybody !
I have implemented a Sonar Plugin (from Sonar version 6.7) for creating a new rule.
In a nutshell this rule should detect if a third party library has been used in some classes (e.g. importing some specific API packages). If yes AND the class using this third party API does not implement a particular interface or does not extend another abstract class, then a bug is fired.
This is working perfectly in the unit tests. The rules are working fine.
Then I deploy the plugin and restart the Sonar Server (Version 6.7.6 (build 38781)).
I can see the rules and their descriptions in the Web UI Management.
I attach them to a quality profile which inherits from the “Sonar way - java” and activate them.
I restart the server.
As a first test, I create a small java project which contains one class which is known for generating the bugs related to my new rules. This is a Class I have also tested in my plugin unit tests.
I attach also this project to my quality profile which contains my rules.
After a successful maven “mvn clean install sonar:sonar” run I get a look at the result in sonar: none of my rules has generated a bug.
I see in the sonar logs that the right quality profile was used ([INFO] Quality profile for java: fintech).
I have tried with several projects, known also for containing buggy classes: same thing. My plugin rules do not detect any problem.
So what I have missed? I have followed the following resources for creating this plugin:
- https://docs.sonarqube.org/display/DEV/Developing+a+Plugin
- https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/java-custom-rules/
- the java sonar official git repo: https://github.com/SonarSource/sonar-java.git
My Plugin is set with the sonar-packaging-maven-plugin version 1.17
I have followed the example from https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/java-custom-rules/ :
I have a Plugin entry class (com.axonivy.sonar.DocFactorySonarPlugin), which adds an extension to the context. The extension loads the rules definition which lists the JavaCheck rules list.
Is that a well known “beginner” error? Is there something special to do for activating these new rules?
Thanks a lot for your help
Emmanuel