How to create a Profile with a Parent in extension plugin

java
custom_plugin

(Jose Montoya) #1

Hey guys,

I’m currently working on creating a custom plugin with custom rules, I’ve managed that. I’m having some issues figuring out how to create a new Profile to be available in SonarQube while inheriting from the SonarWay Java Profile. I’m using the BuiltInQualityProfilesDefinition to create the profile definition and it works, but can’t seem to figure out how to also inherit from the JavaSonarWayProfile to be able to include all those rules.

Any insight is appreciated, thanks!


(Julien Henry) #2

Hi,

I don’t think there is a way to have built-in profiles inheriting from each other. You will have to repeat all the rules you want in your custom profile.


(Jose Montoya) #3

Thanks for the response Julien. Is there then a way for me to query all the rules on the SonarWay profile and add them to the new one? Thanks again.


(Julien Henry) #4

You mean at runtime right?

No, BuiltInQualityProfile extension point is evaluated during server startup to initialize the quality profiles. That’s too early to get access to other quality profiles (would create a loop).


(Jose Montoya) #5

Not at runtime. The extension plugin I’m writing has dependencies on the Java plugin so the SonarWay profile class is available, it’s just not “built” I think.


(Julien Henry) #6

You are depending on a specific version of SonarJava at compile time, but it doesn’t mean it will be the same version installed on the server. And consequently some rules may not exists.

Still if you want to automate extracting rules of SonarWay at build time, you should maybe look at the unit test:


(Jose Montoya) #7

I’m still trying to understand the best practices or what functionality I could/should provide and what should be left to the user. For example I saw that findbugs does depend on the java plugin as well, here:

So I thought that’d be an acceptable way to provide a quick way for the user to switch from the built in plugin to one that just adds a few new ones that we provide. Just trying to figure out the best way to do that.


(Julien Henry) #10

I opened a ticket with this idea of improvement:
https://jira.sonarsource.com/browse/SONAR-11939

I think it will be considered as low priority, so don’t really expect it to be implemented before a few months.

In the meantime, you’ll have to document how users should create manually a new profile, extending the build-in SonarWay and adding your rules.


(Jose Montoya) #11

Can’t ask for more than that. Thanks Julien.