From 255898f341a9d44b8fb98d145ccb916ae02318f8 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 4 Feb 2014 15:10:33 +0100 Subject: [PATCH] SONAR-4641 Custom rules removed when server restarted without the related plugin --- .../sonar/server/rule/RuleRegistration.java | 19 ++++++++++--------- .../server/rule/RuleRegistrationTest.java | 6 +++--- ...tivate_disabled_template_rules-result.xml} | 2 +- ...=> reactivate_disabled_template_rules.xml} | 0 4 files changed, 14 insertions(+), 13 deletions(-) rename sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/{should_not_reactivate_disabled_template_rules-result.xml => reactivate_disabled_template_rules-result.xml} (86%) rename sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/{should_not_reactivate_disabled_template_rules.xml => reactivate_disabled_template_rules.xml} (100%) 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/should_not_reactivate_disabled_template_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml similarity index 86% rename from sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules-result.xml rename to sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml index 92686cf2fac..df9a1cef966 100644 --- 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/reactivate_disabled_template_rules-result.xml @@ -4,7 +4,7 @@ status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/> + status="READY" priority="4" cardinality="SINGLE" parent_id="1" language="java"/> 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/reactivate_disabled_template_rules.xml similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules.xml rename to sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules.xml -- 2.39.5