OSGi 声明式服务和 SonarQube

OSGi Declarative Services & SonarQube

我正在使用 OSGi 声明式服务 R6。根据文档,我创建了一个 @interface 函数声明如下:

@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";
}

我的 属性 id 生成到 my.foo.property,默认值将是 "bar"。但是,我在使用 SonarQube 时遇到的问题是 Sonar Way 质量配置文件不喜欢 my_foo_property 函数声明,因为 Method names should comply with a naming convention (squid:S00100) 这意味着它想要 myFooProperty.

所以我的问题是:使用 OSGi DS R6,我如何覆盖生成的 属性 id,以便我的方法声明可以是 myFooProperty 但键可以是 my.foo.property

如果那不可能,我如何在 SonarQube 中添加异常。我不想删除这条规则,这是一条很好的规则。

规则认为可接受的名称是与其配置的正则表达式相匹配的名称,这只是制作正确的正则表达式的问题。可能类似于 ([a-z][a-zA-Z0-9]*)|([a-z]+\.[a-z]+\.[a-z]+)

但是,您提到您正在使用 Sonar Way 配置文件。在更高版本的 SonarQube 中,此配置文件不可编辑,因此您需要创建自己的配置文件,将其设置为默认值,然后 copy the rules from Sonar way into it 才能根据此规则更新正则表达式。