From: Julien Lancelot Date: Wed, 19 Jun 2013 14:46:31 +0000 (+0200) Subject: SONAR-3879 Template rules have to be registered after all rules have been registered X-Git-Tag: 3.7~436 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4703169603e6caa2e4779037e554af521a45e3e1;p=sonarqube.git SONAR-3879 Template rules have to be registered after all rules have been registered --- diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index 2cd9f57b4fb..5a06588e1b9 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -90,9 +90,10 @@ public final class RegisterRules { for (RuleRepository repository : repositories) { profiler.start("Register rules [" + repository.getKey() + "/" + StringUtils.defaultString(repository.getLanguage(), "-") + "]"); registeredRules.addAll(registerRepositoryRules(repository, existingRules, session)); - registeredRules.addAll(registerTemplateRules(repository, existingRules, registeredRules, session)); profiler.stop(); } + // Template rules have to be registered after all rules in order for their parent to be updated. + registeredRules.addAll(registerTemplateRules(registeredRules, existingRules, session)); return registeredRules; } @@ -120,11 +121,11 @@ public final class RegisterRules { } /** - * Template rules do not exists in the rule repository, only in database, but have to be updated. + * Template rules do not exists in the rule repository, only in database, but have to be updated from their parent rule. */ - private List registerTemplateRules(RuleRepository repository, RulesByRepository existingRules, List registeredRules, DatabaseSession session) { + private List registerTemplateRules(List registeredRules, RulesByRepository existingRules, DatabaseSession session) { List templateRules = newArrayList(); - for (Rule persistedRule : existingRules.get(repository.getKey())) { + for (Rule persistedRule : existingRules.rules()) { Rule parent = persistedRule.getParent(); if (parent != null && registeredRules.contains(parent)) { persistedRule.setRepositoryKey(parent.getRepositoryKey());