Search code examples
javasonarqubeosgiapache-felix

OSGi Declarative Services & SonarQube


I am using OSGi Declarative Services R6. As per the documentation, I created an @interface with function declarations like this:

@ObjectClassDefinition(name = "Hello World OSGi Service")
public @interface Configuration {
    @AttributeDefinition(name = "My Foo Property",
                         description = "A sample string property",
                         type = AttributeType.STRING)
    String my_foo_property() default "bar";
}

My property id gets generated to my.foo.property and the default value will be "bar". However, the problem I am having with SonarQube is that the Sonar Way quality profile doesn't like the my_foo_property function declaration because Method names should comply with a naming convention (squid:S00100) which means it wants something like myFooProperty.

So my question is: With OSGi DS R6, how can I override the generated property id so that my method declaration can be myFooProperty but the key can be my.foo.property.

If that is impossible, how can I add an exception in SonarQube. I don't want to remove this rule, its a good rule.


Solution

  • The names that rule sees as acceptable are the ones that match the regex with which it's configured, which simply makes this a question of crafting the right regex. Probably something like ([a-z][a-zA-Z0-9]*)|([a-z]+\.[a-z]+\.[a-z]+)

    However, you mention you're using the Sonar way profile. In later versions of SonarQube, this profile is not editable, so you'll need to create your own profile, set it as default, and copy the rules from Sonar way into it before you can update the regex on this rule.