]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4641 Custom rules removed when server restarted without the related plugin
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Feb 2014 14:10:33 +0000 (15:10 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Feb 2014 14:10:33 +0000 (15:10 +0100)
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules-result.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/reactivate_disabled_template_rules.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules-result.xml [deleted file]
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/should_not_reactivate_disabled_template_rules.xml [deleted file]

index 7b6915e86a54efac6f3779c9b8b61ac73a7b5296..6b77248adf18c2dd39e28f16093b06d59b61c3c2 100644 (file)
@@ -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
-   *
+   * <p/>
    * Remove active rules on repositories that still exists.
-   *
+   * <p/>
    * 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.
-   *
+   * <p/>
    * 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<RuleDto> removedRules, RuleDefinitions.Context context) {
     List<String> repositoryKeys = newArrayList(Iterables.transform(context.repositories(), new Function<RuleDefinitions.Repository, String>() {
-        @Override
-        public String apply(RuleDefinitions.Repository input) {
-          return input.key();
-        }
+      @Override
+      public String apply(RuleDefinitions.Repository input) {
+        return input.key();
       }
+    }
     ));
 
     for (RuleDto rule : removedRules) {
index b73c177d94efd879c24c53d3f2cc515f33363ece..5ef4b39fed264a6683bdfecd63e2c885e85086c4 100644 (file)
@@ -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 (file)
index 0000000..df9a1ce
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
+         status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
+
+  <rules id="2" plugin_rule_key="user_rule" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
+         status="READY" priority="4" cardinality="SINGLE" parent_id="1" language="java"/>
+
+  <rules id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
+         status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
+
+</dataset>
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 (file)
index 0000000..17e94e9
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+
+  <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
+         status="REMOVED" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
+
+  <rules id="2" plugin_rule_key="user_rule" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
+         status="REMOVED" priority="4" cardinality="SINGLE" parent_id="1" language="java"/>
+
+</dataset>
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 (file)
index 92686cf..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-
-  <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
-         status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
-
-  <rules id="2" plugin_rule_key="user_rule" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
-         status="REMOVED" priority="4" cardinality="SINGLE" parent_id="1" language="java"/>
-
-  <rules id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
-         status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
-
-</dataset>
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 (file)
index 17e94e9..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
-  <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
-         status="REMOVED" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
-
-  <rules id="2" plugin_rule_key="user_rule" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
-         status="REMOVED" priority="4" cardinality="SINGLE" parent_id="1" language="java"/>
-
-</dataset>