From: Sébastien Lesaint Date: Wed, 13 May 2015 11:47:14 +0000 (+0200) Subject: add Module for ElasticSearch components X-Git-Tag: 5.2-RC1~1824 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d666dab3086f7c66ca584ede46ffaf2143029ed;p=sonarqube.git add Module for ElasticSearch components --- 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 1752c5d9a79..379715cd497 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 @@ -19,6 +19,8 @@ */ package org.sonar.server.platform.platformlevel; +import java.util.Properties; +import javax.annotation.Nullable; import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.TempFolderCleaner; import org.sonar.core.config.CorePropertyDefinitions; @@ -44,7 +46,6 @@ import org.sonar.server.db.DatabaseChecker; import org.sonar.server.db.DbClient; import org.sonar.server.db.EmbeddedDatabaseFactory; import org.sonar.server.db.migrations.MigrationSteps; -import org.sonar.server.es.EsClient; import org.sonar.server.event.db.EventDao; import org.sonar.server.issue.db.IssueDao; import org.sonar.server.issue.index.IssueIndex; @@ -63,19 +64,14 @@ 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.RuleNormalizer; -import org.sonar.server.search.IndexClient; +import org.sonar.server.search.EsSearchModule; import org.sonar.server.search.IndexQueue; -import org.sonar.server.search.SearchClient; import org.sonar.server.source.db.FileSourceDao; import org.sonar.server.user.ThreadLocalUserSession; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; import org.sonar.server.user.db.UserGroupDao; -import javax.annotation.Nullable; - -import java.util.Properties; - public class PlatformLevel1 extends PlatformLevel { private final Platform platform; private final Properties properties; @@ -122,9 +118,7 @@ public class PlatformLevel1 extends PlatformLevel { DbClient.class, // Elasticsearch - SearchClient.class, - IndexClient.class, - EsClient.class, + EsSearchModule.class, // users GroupDao.class, 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 new file mode 100644 index 00000000000..f3e1b7fa7d8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java @@ -0,0 +1,33 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.search; + +import org.sonar.core.component.Module; +import org.sonar.server.es.EsClient; + +public class EsSearchModule extends Module { + @Override + protected void configureModule() { + add( + SearchClient.class, + IndexClient.class, + EsClient.class); + } +} 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 new file mode 100644 index 00000000000..0a121b2b9bb --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java @@ -0,0 +1,35 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.search; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EsSearchModuleTest { + @Test + public void verify_count_of_added_components() throws Exception { + ComponentContainer container = new ComponentContainer(); + new EsSearchModule().configure(container); + assertThat(container.size()).isEqualTo(5); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java index 028edcef284..3f06b041ec1 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java @@ -260,4 +260,8 @@ public class ComponentContainer { public MutablePicoContainer getPicoContainer() { return pico; } + + public int size() { + return pico.getComponentAdapters().size(); + } }