From: Julien Lancelot Date: Tue, 4 Feb 2014 14:10:33 +0000 (+0100) Subject: SONAR-4641 Custom rules removed when server restarted without the related plugin X-Git-Tag: 4.2~268 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=255898f341a9d44b8fb98d145ccb916ae02318f8;p=sonarqube.git SONAR-4641 Custom rules removed when server restarted without the related plugin --- diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java index 7b6915e86a5..6b77248adf1 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java @@ -338,9 +338,10 @@ public class RuleRegistration implements Startable { for (Integer unprocessedRuleId : buffer.unprocessedRuleIds) { RuleDto ruleDto = buffer.rulesById.get(unprocessedRuleId); boolean toBeRemoved = true; - if (ruleDto.getParentId() != null && !ruleDto.getStatus().equals(Rule.STATUS_REMOVED)) { + // Update copy of template rules from template + if (ruleDto.getParentId() != null) { RuleDto parent = buffer.rulesById.get(ruleDto.getParentId()); - if (parent != null) { + if (parent != null && !parent.getStatus().equals(Rule.STATUS_REMOVED)) { // TODO merge params and tags ? ruleDto.setLanguage(parent.getLanguage()); ruleDto.setStatus(parent.getStatus()); @@ -371,22 +372,22 @@ public class RuleRegistration implements Startable { /** * SONAR-4642 - * + *

* Remove active rules on repositories that still exists. - * + *

* For instance, if the javascript repository do not provide anymore some rules, active rules related to this rules will be removed. * But if the javascript repository do not exists anymore, then related active rules will not be removed. - * + *

* The side effect of this approach is that extended repositories will not be managed the same way. * If an extended repository do not exists anymore, then related active rules will be removed. */ private void removeActiveRulesOnStillExistingRepositories(List removedRules, RuleDefinitions.Context context) { List repositoryKeys = newArrayList(Iterables.transform(context.repositories(), new Function() { - @Override - public String apply(RuleDefinitions.Repository input) { - return input.key(); - } + @Override + public String apply(RuleDefinitions.Repository input) { + return input.key(); } + } )); for (RuleDto rule : removedRules) { diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java index b73c177d94e..5ef4b39fed2 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java @@ -110,11 +110,11 @@ public class RuleRegistrationTest extends AbstractDaoTestCase { } @Test - public void should_not_reactivate_disabled_template_rules() { - setupData("should_not_reactivate_disabled_template_rules"); + public void reactivate_disabled_template_rules() { + setupData("reactivate_disabled_template_rules"); task.start(); - checkTables("should_not_reactivate_disabled_template_rules", EXCLUDED_COLUMN_NAMES, "rules"); + checkTables("reactivate_disabled_template_rules", EXCLUDED_COLUMN_NAMES, "rules"); } @Test diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml new file mode 100644 index 00000000000..df9a1cef966 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules.xml new file mode 100644 index 00000000000..17e94e974ca --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules-result.xml deleted file mode 100644 index 92686cf2fac..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules-result.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules.xml deleted file mode 100644 index 17e94e974ca..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -