aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-01-22 18:13:31 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-01-22 18:13:31 +0100
commit7c5723b9ec0ee585ac311a621c5515204ce49bc5 (patch)
treec88216d1771b0e490278aed8cae046daf9881f9a /sonar-server
parentfa983430b03418e321ca716e52e1bea5fac08350 (diff)
downloadsonarqube-7c5723b9ec0ee585ac311a621c5515204ce49bc5.tar.gz
sonarqube-7c5723b9ec0ee585ac311a621c5515204ce49bc5.zip
SONAR-4326 Delete unused tags at startup
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java8
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java10
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/updadeRuleFields-result.xml1
3 files changed, 12 insertions, 7 deletions
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 56501c76cb1..d8712a9a958 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
@@ -26,10 +26,10 @@ import org.apache.ibatis.session.SqlSession;
import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.server.rule.RuleDefinitions;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
+import org.sonar.api.server.rule.RuleDefinitions;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.check.Cardinality;
@@ -56,16 +56,18 @@ public class RuleRegistration implements Startable {
private final MyBatis myBatis;
private final RuleDao ruleDao;
private final RuleTagDao ruleTagDao;
+ private final RuleTagOperations ruleTagOperations;
private final ActiveRuleDao activeRuleDao;
private final System2 system = System2.INSTANCE;
public RuleRegistration(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
- RuleRegistry ruleRegistry, ESRuleTags esRuleTags,
+ RuleRegistry ruleRegistry, ESRuleTags esRuleTags, RuleTagOperations ruleTagOperations,
MyBatis myBatis, RuleDao ruleDao, RuleTagDao ruleTagDao, ActiveRuleDao activeRuleDao) {
this.defLoader = defLoader;
this.profilesManager = profilesManager;
this.ruleRegistry = ruleRegistry;
this.esRuleTags = esRuleTags;
+ this.ruleTagOperations = ruleTagOperations;
this.myBatis = myBatis;
this.ruleDao = ruleDao;
this.ruleTagDao = ruleTagDao;
@@ -82,6 +84,8 @@ public class RuleRegistration implements Startable {
enableRuleDefinitions(buffer, sqlSession);
processRemainingDbRules(buffer, sqlSession);
index(buffer);
+ ruleTagOperations.deleteUnusedTags(sqlSession);
+ sqlSession.commit();
} finally {
sqlSession.close();
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 6bb253002c3..d9ecdbb295e 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
@@ -22,8 +22,8 @@ package org.sonar.server.rule;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.server.rule.RuleDefinitions;
import org.sonar.api.rule.Severity;
+import org.sonar.api.server.rule.RuleDefinitions;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.qualityprofile.db.ActiveRuleDao;
@@ -44,6 +44,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
ProfilesManager profilesManager = mock(ProfilesManager.class);
RuleRegistry ruleRegistry = mock(RuleRegistry.class);
ESRuleTags esRuleTags = mock(ESRuleTags.class);
+ RuleTagOperations ruleTagOperations;
MyBatis myBatis;
RuleDao ruleDao;
RuleTagDao ruleTagDao;
@@ -55,8 +56,9 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
ruleDao = new RuleDao(myBatis);
ruleTagDao = new RuleTagDao(myBatis);
activeRuleDao = new ActiveRuleDao(myBatis);
+ ruleTagOperations = new RuleTagOperations(ruleTagDao, esRuleTags);
task = new RuleRegistration(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RuleDefinitions[]{new FakeRepository()}),
- profilesManager, ruleRegistry, esRuleTags, myBatis, ruleDao, ruleTagDao, activeRuleDao);
+ profilesManager, ruleRegistry, esRuleTags, ruleTagOperations, myBatis, ruleDao, ruleTagDao, activeRuleDao);
}
@Test
@@ -169,7 +171,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
@Test
public void test_high_number_of_rules() {
task = new RuleRegistration(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RuleDefinitions[]{new BigRepository()}),
- profilesManager, ruleRegistry, esRuleTags, myBatis, ruleDao, ruleTagDao, activeRuleDao);
+ profilesManager, ruleRegistry, esRuleTags, ruleTagOperations, myBatis, ruleDao, ruleTagDao, activeRuleDao);
setupData("shared");
task.start();
@@ -184,7 +186,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
public void should_insert_extended_repositories() {
task = new RuleRegistration(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RuleDefinitions[]{
new FindbugsRepository(), new FbContribRepository()}),
- profilesManager, ruleRegistry, esRuleTags, myBatis, ruleDao, ruleTagDao, activeRuleDao);
+ profilesManager, ruleRegistry, esRuleTags, ruleTagOperations, myBatis, ruleDao, ruleTagDao, activeRuleDao);
setupData("empty");
task.start();
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/updadeRuleFields-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/updadeRuleFields-result.xml
index 84830525220..6a946360271 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/updadeRuleFields-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/updadeRuleFields-result.xml
@@ -7,7 +7,6 @@
<rules_parameters id="2" rule_id="1" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
<rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag2"/>
<rule_tags id="3" tag="tag3"/>
<rule_tags id="4" tag="tag4"/>
<rule_tags id="5" tag="tag5"/>