diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-26 10:18:41 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-26 10:35:54 +0200 |
commit | 1147732183f1ca1644d869655a38a7f2d951d6c1 (patch) | |
tree | 7644708e5e785334e32532a2d1523f87758c4213 /server/sonar-server | |
parent | a2a0a746a88f1b04bad94c91b3111a5b5f30b521 (diff) | |
download | sonarqube-1147732183f1ca1644d869655a38a7f2d951d6c1.tar.gz sonarqube-1147732183f1ca1644d869655a38a7f2d951d6c1.zip |
FindByProfile should not return removed rules
Diffstat (limited to 'server/sonar-server')
3 files changed, 12 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java index b12c5f8d8ca..fd7b4034fc0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java @@ -37,11 +37,7 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto; import org.sonar.core.qualityprofile.db.ActiveRuleKey; import org.sonar.server.qualityprofile.ActiveRule; import org.sonar.server.rule.index.RuleNormalizer; -import org.sonar.server.search.BaseIndex; -import org.sonar.server.search.FacetValue; -import org.sonar.server.search.IndexDefinition; -import org.sonar.server.search.IndexField; -import org.sonar.server.search.SearchClient; +import org.sonar.server.search.*; import java.io.IOException; import java.util.ArrayList; @@ -138,7 +134,11 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active public List<ActiveRule> findByProfile(String key) { SearchRequestBuilder request = getClient().prepareSearch(getIndexName()) - .setQuery(QueryBuilders.termQuery(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key)) + .setQuery(QueryBuilders.filteredQuery( + QueryBuilders.termsQuery(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key), + FilterBuilders.boolFilter() + .mustNot(FilterBuilders.hasParentFilter(this.getParentType(), + FilterBuilders.termFilter(RuleNormalizer.RuleField.STATUS.field(), RuleStatus.REMOVED.name()))))) .setRouting(key) // TODO replace by scrolling .setSize(Integer.MAX_VALUE); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java index 9c99ce8b716..db00b4efd32 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java @@ -168,11 +168,15 @@ public class ActiveRuleBackendMediumTest extends SearchMediumTest { RuleDto rule1 = RuleTesting.newXooX1().setSeverity(Severity.MAJOR); RuleDto rule2 = RuleTesting.newXooX2().setSeverity(Severity.MAJOR); - db.ruleDao().insert(dbSession, rule1, rule2); + RuleDto removedRule = RuleTesting.newDto(RuleKey.of("xoo", "removed")).setSeverity(Severity.MAJOR).setStatus(RuleStatus.REMOVED); + db.ruleDao().insert(dbSession, rule1, rule2, removedRule); db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR)); db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER)); db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL)); + // Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not removed + // because if the plugin is re-install, quality profiles using these rule are not changed. + db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, removedRule).setSeverity(Severity.MAJOR)); dbSession.commit(); // 1. find by rule key 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 22b0d2e8728..790c8c1b647 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 @@ -348,7 +348,7 @@ public class RegisterRulesMediumTest { // Restart without xoo register(null); assertThat(ruleIndex.getByKey(RuleTesting.XOO_X1).status()).isEqualTo(RuleStatus.REMOVED); - assertThat(activeRuleIndex.findByProfile(QProfileTesting.XOO_P1_KEY)).hasSize(1); + assertThat(activeRuleIndex.findByProfile(QProfileTesting.XOO_P1_KEY)).isEmpty(); // Re-install register(rules); |