I'm developing a plugin to SonarQube in order to import rules from a .xml file. So far this is done and they really are imported into the SonarQube instance and shown under "Rules". Although the Quality Profile is being created, all the imported rules aren't being added to it and I can't understand why.
I don't want to add them one by one by hand; I'm looking for a way to add them directly to the created profile once they are imported from the .xml file. The profile is simply created with:
public class MyProfile extends ProfileDefinition {
@Override
public RulesProfile createProfile(ValidationMessages validation) {
return RulesProfile.create("QP", "Java");
}
}
Here is some code of the methods that I suspect would make that happen:
public class MyRules extends RulesDefinition {
public void define(Context context) {
List<RulePack> rulePacks = this.rulePackParser.parse();
parseXml(context);
parseRulePacks(context, rulePacks);
for (NewRepository newRepository : newRepositories.values()) {
newRepository.done();
}
}
private void parseXml(Context context) {
for (Language supportedLanguage : languages.all()) {
InputStream rulesXml = this.getClass().getResourceAsStream("/rules-TESTE.xml");
if (rulesXml != null) {
NewRepository repository = getRepository(context, supportedLanguage.getKey());
xmlLoader.load(repository, new BufferedReader(new InputStreamReader(rulesXml)));
repository.done();
}
}
}
private void parseRulePacks(Context context, List<RulePack> rulePacks) {
for (RulePack rulePack : rulePacks) {
for (AppScanRule rule : rulePack.getRules()) {
String sqLanguageKey = convertToSQ(rulePack.getRuleLanguage(rule));
if (this.languages.get(sqLanguageKey) != null && isAnInterestingRule(rule)) {
processRule(context, rulePack, rule, sqLanguageKey);
}
}
}
}
}
Thanks in advance.