From 2128feb694eeeada2b33fd8772e70cbeb44ed4b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 12 May 2017 15:48:15 +0200 Subject: [PATCH] SONAR-9132 don't remove template rules at every startup --- .../java/org/sonar/server/rule/RegisterRules.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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(); -- 2.39.5