From: Sébastien Lesaint Date: Fri, 12 May 2017 13:48:15 +0000 (+0200) Subject: SONAR-9132 don't remove template rules at every startup X-Git-Tag: 6.4-RC1~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2128feb694eeeada2b33fd8772e70cbeb44ed4b8;p=sonarqube.git SONAR-9132 don't remove template rules at every startup --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java index fdbb5f8f91e..a9060ea975d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -102,13 +102,20 @@ public class RegisterRules implements Startable { for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) { if (languages.get(repoDef.language()) != null) { for (RulesDefinition.Rule ruleDef : repoDef.rules()) { + RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key()); if (ruleDef.template() && orgsEnabled) { - LOG.info("Template rule {} will not be imported, because organizations are enabled.", RuleKey.of(ruleDef.repository().key(), ruleDef.key())); + RuleDefinitionDto ruleDefinition = allRules.get(ruleKey); + if (ruleDefinition != null && ruleDefinition.getStatus() == RuleStatus.REMOVED) { + LOG.debug("Template rule {} kept removed, because organizations are enabled.", ruleKey); + allRules.remove(ruleKey); + } else { + LOG.info("Template rule {} will not be imported, because organizations are enabled.", ruleKey); + } continue; } boolean relevantForIndex = registerRule(ruleDef, allRules, session); if (relevantForIndex) { - keysToIndex.add(RuleKey.of(ruleDef.repository().key(), ruleDef.key())); + keysToIndex.add(ruleKey); } } session.commit();