I'm trying to import rules (for Java and other languages) from a .xml file to SonarQube. I've used an exemple plugin to do so. That sample was downloaded from https://github.com/SonarSource/sonar-examples - project sonar-reference-plugin. The quality profile is indeed created but doesn't show any rules on it. (screen image SonarQube profile page)
This is the Override method where it supposedly would load the rules, by using the RulesDefinitionXmlLoader class:
private void defineRulesForLanguage(Context context, String repositoryKey, String repositoryName, String languageKey) {
NewRepository repository = context.createRepository(repositoryKey, languageKey).setName(repositoryName);
InputStream rulesXml = this.getClass().getResourceAsStream("/resources/rules-TESTE.xml");
if (rulesXml != null) {
RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader();
rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name());
}
repository.done();
}
@Override
public void define(Context context) {
String repositoryKey = FooLintRulesDefinition.getRepositoryKeyForLanguage(FooLanguage.KEY);
String repositoryName = FooLintRulesDefinition.getRepositoryNameForLanguage(FooLanguage.KEY);
defineRulesForLanguage(context, repositoryKey, repositoryName, FooLanguage.KEY);
}
I have already tried different paths to the .xml file containing the rules in order to outwit any possible issues. That .xml file looks like this right now (also it is now very simple and has only one rule to make it easier to apply):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rules>
<rule>
<key>da-rule-key</key>
<name>Nome da regra</name>
</rule>
</rules>
I'm using local SonarQube 5.3 but I've unsuccessfully tried different versions. Thanks in advance.