From 4703169603e6caa2e4779037e554af521a45e3e1 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 19 Jun 2013 16:46:31 +0200 Subject: [PATCH] SONAR-3879 Template rules have to be registered after all rules have been registered --- .../java/org/sonar/server/startup/RegisterRules.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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()); -- 2.39.5