diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-05 17:05:57 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-05 17:05:57 +0100 |
commit | c54486801fd213196cb7a9f7d19fa95775403926 (patch) | |
tree | 06bcd9192fc99c37c776c709af76fbd56782bf09 | |
parent | 6fcc40818bc6e92b642e7e3aa36726233da24e95 (diff) | |
download | sonarqube-c54486801fd213196cb7a9f7d19fa95775403926.tar.gz sonarqube-c54486801fd213196cb7a9f7d19fa95775403926.zip |
SONAR-1974 do not disable the rules of the repository "review" at startup
3 files changed, 44 insertions, 24 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index 9f07e2e2118..005775ea877 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -36,7 +36,7 @@ import java.util.*; public final class RegisterRules { private DatabaseSessionFactory sessionFactory; - private List<RuleRepository> repositories = new ArrayList<RuleRepository>(); + private List<RuleRepository> repositories = Lists.newArrayList(); public RegisterRules(DatabaseSessionFactory sessionFactory, RuleRepository[] repos) { this.sessionFactory = sessionFactory; @@ -68,12 +68,12 @@ public final class RegisterRules { private void disableDeprecatedUserRules(DatabaseSession session) { List<Integer> deprecatedUserRuleIds = Lists.newLinkedList(); deprecatedUserRuleIds.addAll(session.createQuery( - "SELECT r.id FROM " + Rule.class.getSimpleName() + - " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList()); + "SELECT r.id FROM " + Rule.class.getSimpleName() + + " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList()); deprecatedUserRuleIds.addAll(session.createQuery( - "SELECT r.id FROM " + Rule.class.getSimpleName() + - " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList()); + "SELECT r.id FROM " + Rule.class.getSimpleName() + + " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList()); for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) { Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId); @@ -84,7 +84,8 @@ public final class RegisterRules { } private void disableAllRules(DatabaseSession session) { - session.createQuery("UPDATE " + Rule.class.getSimpleName() + " SET enabled=false WHERE parent IS NULL").executeUpdate(); + // the hardcoded repository "review" is used for manual violations + session.createQuery("UPDATE " + Rule.class.getSimpleName() + " SET enabled=false WHERE parent IS NULL AND pluginName<>'review'").executeUpdate(); } private void registerRepository(RuleRepository repository, DatabaseSession session) { @@ -145,9 +146,9 @@ public final class RegisterRules { if (rule.getParam(persistedParam.getKey()) == null) { it.remove(); session - .createQuery("delete from " + ActiveRuleParam.class.getSimpleName() + " where ruleParam=:param") - .setParameter("param", persistedParam) - .executeUpdate(); + .createQuery("delete from " + ActiveRuleParam.class.getSimpleName() + " where ruleParam=:param") + .setParameter("param", persistedParam) + .executeUpdate(); } } } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java index efa3e00e037..226e382556d 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java @@ -29,16 +29,14 @@ import java.util.List; import static org.hamcrest.Matchers.is; import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void saveNewRepositories() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake"); @@ -54,12 +52,12 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedRepositories() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); List<Rule> rules = (List<Rule>) getSession() - .createQuery("from " + Rule.class.getSimpleName() + " where pluginName<>'fake'") - .getResultList(); + .createQuery("from " + Rule.class.getSimpleName() + " where pluginName<>'fake'") + .getResultList(); assertThat(rules.size(), greaterThan(0)); for (Rule rule : rules) { assertThat(rule.isEnabled(), is(false)); @@ -69,7 +67,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedActiveRules() { setupData("disableDeprecatedActiveRules"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake"); @@ -86,7 +84,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedActiveRuleParameters() { setupData("disableDeprecatedActiveRuleParameters"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); ActiveRule arule = getSession().getSingleResult(ActiveRule.class, "id", 1); @@ -97,7 +95,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedRules() { setupData("disableDeprecatedRules"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 1); @@ -110,7 +108,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void updateRuleFields() { setupData("updadeRuleFields"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); // fields have been updated with new values @@ -124,7 +122,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void updateRuleParameters() { setupData("updateRuleParameters"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 1); @@ -148,7 +146,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void doNotDisableUserRulesIfParentIsEnabled() { setupData("doNotDisableUserRulesIfParentIsEnabled"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 2); @@ -158,7 +156,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableUserRulesIfParentIsDisabled() { setupData("disableUserRulesIfParentIsDisabled"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new FakeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 2); @@ -166,9 +164,21 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { } @Test + public void shouldNotDisableReviewRules() { + // the hardcoded repository "review" is used for manual violations + setupData("shouldNotDisableReviewRules"); + + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new FakeRepository()}); + task.start(); + + assertThat(getSession().getSingleResult(Rule.class, "id", 1).isEnabled(), is(true)); + assertThat(getSession().getSingleResult(Rule.class, "id", 2).isEnabled(), is(false)); + } + + @Test public void volumeTesting() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[] { new VolumeRepository() }); + RegisterRules task = new RegisterRules(getSessionFactory(), new RuleRepository[]{new VolumeRepository()}); task.start(); List<Rule> result = getSession().getResults(Rule.class, "enabled", true); diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/shouldNotDisableReviewRules.xml b/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/shouldNotDisableReviewRules.xml new file mode 100644 index 00000000000..2f279b4d3a7 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/shouldNotDisableReviewRules.xml @@ -0,0 +1,9 @@ +<dataset> + + <rules id="1" plugin_rule_key="PerformanceIssue" plugin_name="review" plugin_config_key="[null]" name="Performance Issue" description="[null]" + enabled="true" priority="[null]" cardinality="SINGLE" parent_id="[null]"/> + + <rules id="2" plugin_rule_key="IllegalExceptionCheck" plugin_name="checkstyle" plugin_config_key="[null]" name="Illegal Exception" description="[null]" + enabled="true" priority="4" cardinality="SINGLE" parent_id="[null]"/> + +</dataset>
\ No newline at end of file |