]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9132 don't remove template rules at every startup 2071/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 12 May 2017 13:48:15 +0000 (15:48 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 12 May 2017 15:17:42 +0000 (17:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java

index fdbb5f8f91e7f0a1c4fb0fed28aaebc3b4d769a7..a9060ea975daf3560851ce053f9f853df20c1c6c 100644 (file)
@@ -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();