From f334975c430c943984c1b23f40571b81400f1f39 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 24 Feb 2016 21:11:32 +0100 Subject: [PATCH] SONAR-7330 Remove last usage of old RuleIndex --- .../platform/platformlevel/PlatformLevel1.java | 4 ---- .../server/qualityprofile/QProfileBackuper.java | 16 ++++++++-------- .../java/org/sonar/server/rule/RuleService.java | 4 +++- .../org/sonar/server/search/EsSearchModule.java | 1 - .../platform/BackendCleanupMediumTest.java | 8 +++++++- .../sonar/server/search/EsSearchModuleTest.java | 2 +- .../src/main/java/org/sonar/db/DbSession.java | 12 ++++++++---- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 52c7f87c18f..cfbf3199350 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -43,12 +43,10 @@ import org.sonar.server.platform.ServerImpl; import org.sonar.server.platform.ServerSettings; import org.sonar.server.platform.TempFolderProvider; import org.sonar.server.qualityprofile.db.ActiveRuleDao; -import org.sonar.server.qualityprofile.index.ActiveRuleIndex; import org.sonar.server.qualityprofile.index.ActiveRuleIndex2; import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer; import org.sonar.server.ruby.PlatformRackBridge; import org.sonar.server.rule.db.RuleDao; -import org.sonar.server.rule.index.RuleIndex; import org.sonar.server.rule.index.RuleIndex2; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.search.EsSearchModule; @@ -114,8 +112,6 @@ public class PlatformLevel1 extends PlatformLevel { ActiveRuleIndex2.class, RuleNormalizer.class, ActiveRuleNormalizer.class, - RuleIndex.class, - ActiveRuleIndex.class, // issues IssueIndex.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java index bcab0c84a78..86174d38ac3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java @@ -43,25 +43,25 @@ import org.codehaus.staxmate.in.SMInputCursor; import org.sonar.api.rule.RuleKey; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.text.XmlWriter; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QualityProfileDto; -import org.sonar.db.DbClient; -import org.sonar.server.qualityprofile.index.ActiveRuleIndex; -import org.sonar.server.search.IndexClient; +import org.sonar.server.qualityprofile.index.ActiveRuleDoc; +import org.sonar.server.qualityprofile.index.ActiveRuleIndex2; @ServerSide public class QProfileBackuper { private final QProfileReset reset; private final DbClient db; - private final IndexClient index; + private final ActiveRuleIndex2 activeRuleIndex; private static final Joiner RULEKEY_JOINER = Joiner.on(", ").skipNulls(); - public QProfileBackuper(QProfileReset reset, DbClient db, IndexClient index) { + public QProfileBackuper(QProfileReset reset, DbClient db, ActiveRuleIndex2 activeRuleIndex) { this.reset = reset; this.db = db; - this.index = index; + this.activeRuleIndex = activeRuleIndex; } public void backup(String key, Writer writer) { @@ -72,12 +72,12 @@ public class QProfileBackuper { } finally { dbSession.close(); } - List activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profile.getKey())); + List activeRules = Lists.newArrayList(activeRuleIndex.findByProfile(profile.getKey())); Collections.sort(activeRules, BackupActiveRuleComparator.INSTANCE); writeXml(writer, profile, activeRules.iterator()); } - private static void writeXml(Writer writer, QualityProfileDto profile, Iterator activeRules) { + private static void writeXml(Writer writer, QualityProfileDto profile, Iterator activeRules) { XmlWriter xml = XmlWriter.of(writer).declaration(); xml.begin("profile"); xml.prop("name", profile.getName()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java index 8d8f45d6194..a409042a7e9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java @@ -75,7 +75,9 @@ public class RuleService { } public Result search(RuleQuery query, QueryContext options) { - return index.search(query, options); + // TODO replace QueryContext by SearchOptions + // return index.search(query, options); + throw new UnsupportedOperationException("Wait for replacement of QueryContext by SearchOptions "); } /** diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java b/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java index 258d31b0c63..59dc77ee2c1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java @@ -27,7 +27,6 @@ public class EsSearchModule extends Module { protected void configureModule() { add( SearchClient.class, - IndexClient.class, EsClient.class); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java index f15c7025e74..b48c0bbc64d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java @@ -25,6 +25,7 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.config.Settings; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleTesting; @@ -32,6 +33,7 @@ import org.sonar.server.es.EsTester; import org.sonar.server.issue.IssueTesting; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.rule.index.RuleDoc; +import org.sonar.server.rule.index.RuleIndexDefinition; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.search.IndexDefinition; import org.sonar.server.view.index.ViewDoc; @@ -45,7 +47,11 @@ import static org.assertj.core.api.Assertions.assertThat; public class BackendCleanupMediumTest { @ClassRule - public static EsTester esTester = new EsTester(); + public static EsTester esTester = new EsTester().addDefinitions( + new RuleIndexDefinition(new Settings()), + new IssueIndexDefinition(new Settings()), + new ViewIndexDefinition(new Settings()) + ); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java index 2f4a0835bbb..abf95a396c8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java @@ -29,7 +29,7 @@ public class EsSearchModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new EsSearchModule().configure(container); - assertThat(container.size()).isEqualTo(5); + assertThat(container.size()).isEqualTo(4); } } diff --git a/sonar-db/src/main/java/org/sonar/db/DbSession.java b/sonar-db/src/main/java/org/sonar/db/DbSession.java index a2d97d2a5f1..08e2b4ba04d 100644 --- a/sonar-db/src/main/java/org/sonar/db/DbSession.java +++ b/sonar-db/src/main/java/org/sonar/db/DbSession.java @@ -35,22 +35,28 @@ public class DbSession implements SqlSession { private List actions; - private WorkQueue queue; private SqlSession session; private int actionCount; public DbSession(WorkQueue queue, SqlSession session) { this.actionCount = 0; this.session = session; - this.queue = queue; this.actions = new ArrayList<>(); } + /** + * @deprecated since 5.5, not used anymore + */ + @Deprecated public void enqueue(ClusterAction action) { actionCount++; this.actions.add(action); } + /** + * @deprecated since 5.5, not used anymore + */ + @Deprecated public int getActionCount() { return actionCount; } @@ -58,14 +64,12 @@ public class DbSession implements SqlSession { @Override public void commit() { session.commit(); - queue.enqueue(actions); actions.clear(); } @Override public void commit(boolean force) { session.commit(force); - queue.enqueue(actions); actions.clear(); } -- 2.39.5