Add Tag to built-in rule within a custom plugin

Hello,

On SonarQube website, it’s possible to add a tag to an existing built-in rule (and create tag if needed).

Thus, is it possible to do it programmatically within a custom plugin like followed process :

  • get tag list of a specific built-in rule
  • check if desired tag is present on this tag list of this specific rule
  • if tag is not present in rule then
    • if tag not exists on all tags list, then create new tag
    • add tag to specific rule

I hope I’m clear on my question (sorry for my poor english, I’m french :stuck_out_tongue: ).

Thank you.
David

Hey there.

Are you sure a custom plugin is the right way to go, rather than using the Web API (documentation linked in the footer of your instance).

Hi,

thank you for answer, but our goal is to create a new plugin to add some rules or tag existing rules as “eco-conception”. The main goal is to add some “greenIT” environment to SonarQube. This is a lack for us.
So, to avoid rewrite existing rules, we want to tag them with our new custom tag “eco-conception”.
The great solution for us is to add automatically our tag to existing rules when plugin is installed. We wouldn’t create a new system (like batch scripting) to do an initialization phase after plugin installation (using API calls for example).

thank you.

Hi @dedece35 ,
this doesn’t seem to be achievable with current Plugin API. You can do what you want with the rules your plugin define but not with the rules other plugins define.

The work-around would be to call SonarQube Web API from inside your plugin, to achieve what you want, but this doesn’t seem in general as a clean, good practice.

Hi,

thank you for answer.
I understand it but I find it unfortunate that we can’t do it programmatically in a clean way whereas we can do it with SonarQube API.

To stay in a clean way, I think we will create a script that install our plugin and then call SonarQube API to add our custom tag to all rules that we want.
Do you think, this is a good way int order to release our opensource plugin in SonarQube marketplace ?

Thank you.

I wouldn’t say is super clean way, but with the current state of the things I don’t see any better way.

Ok, thank you.
But, If I call Sonar Api in my plugin, do you think this will be OK ? Does SonarQube API is already available when plugins system intialize itself ?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.