aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-03-03 13:06:50 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-03-03 13:06:50 +0100
commit549fae5fbba5ae062565fd20269c61f408f715f1 (patch)
tree1c4b133fca697f3d2f87204a2832485324f51fda /server
parent0042d98dd66b7d12728df7a7383cd73ddcd63be5 (diff)
downloadsonarqube-549fae5fbba5ae062565fd20269c61f408f715f1.tar.gz
sonarqube-549fae5fbba5ae062565fd20269c61f408f715f1.zip
SONAR-6238 Updating only the name of a rule is not taking in account when synchronizing rules at startup
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java50
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java2
3 files changed, 57 insertions, 7 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 e2ea5e4ff98..674e9cade10 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
@@ -51,12 +51,8 @@ import org.sonar.server.startup.RegisterDebtModel;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
@@ -228,7 +224,9 @@ public class RegisterRules implements Startable {
dto.setName(def.name());
changed = true;
}
- changed = mergeDescription(def, dto);
+ if (mergeDescription(def, dto)) {
+ changed= true;
+ }
if (!dto.getSystemTags().containsAll(def.tags())) {
dto.setSystemTags(def.tags());
changed = true;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
index 292b0e3effb..2bc554247f7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
@@ -253,6 +253,56 @@ public class RegisterRulesMediumTest {
}
@Test
+ public void update_only_rule_name() {
+ register(new Rules() {
+ @Override
+ public void init(RulesDefinition.NewRepository repository) {
+ repository.createRule("x1")
+ .setName("Name1")
+ .setHtmlDescription("Desc1");
+ }
+ });
+
+ register(new Rules() {
+ @Override
+ public void init(RulesDefinition.NewRepository repository) {
+ repository.createRule(RuleTesting.XOO_X1.rule())
+ .setName("Name2")
+ .setHtmlDescription("Desc1");
+ }
+ });
+
+ Rule rule = ruleIndex.getByKey(RuleTesting.XOO_X1);
+ assertThat(rule.name()).isEqualTo("Name2");
+ assertThat(rule.htmlDescription()).isEqualTo("Desc1");
+ }
+
+ @Test
+ public void update_only_rule_description() {
+ register(new Rules() {
+ @Override
+ public void init(RulesDefinition.NewRepository repository) {
+ repository.createRule("x1")
+ .setName("Name1")
+ .setHtmlDescription("Desc1");
+ }
+ });
+
+ register(new Rules() {
+ @Override
+ public void init(RulesDefinition.NewRepository repository) {
+ repository.createRule(RuleTesting.XOO_X1.rule())
+ .setName("Name1")
+ .setHtmlDescription("Desc2");
+ }
+ });
+
+ Rule rule = ruleIndex.getByKey(RuleTesting.XOO_X1);
+ assertThat(rule.name()).isEqualTo("Name1");
+ assertThat(rule.htmlDescription()).isEqualTo("Desc2");
+ }
+
+ @Test
public void do_not_update_rules_if_no_changes() throws Exception {
Rules rules = new Rules() {
@Override
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
index 930515c1de7..7c1abbfedc7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
@@ -218,6 +218,8 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
RegisterRules task = new RegisterRules(loader, ruleActivator, dbClient, languages);
task.start();
+ // Execute a commit to refresh session state as the task is using its own session
+ dbSession.commit();
}
private RuleParamDto getParam(List<RuleParamDto> params, String key) {