From 98550e39c25d24f68d454d8939e4352b820aedd2 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 10 Mar 2018 15:33:35 +0100 Subject: [PATCH] Clean-up ES module in sonar-server --- .../container/ComputeEngineContainerImpl.java | 4 +- .../ComputeEngineContainerImplTest.java | 2 +- .../EsSearchModule.java => es/EsModule.java} | 6 +- .../platformlevel/PlatformLevel1.java | 4 +- .../plugins/ServerExtensionInstaller.java | 13 ---- .../org/sonar/server/search/FacetValue.java | 66 ------------------- .../org/sonar/server/search/package-info.java | 23 ------- .../EsModuleTest.java} | 6 +- .../sonar/server/search/FacetValueTest.java | 56 ---------------- 9 files changed, 10 insertions(+), 170 deletions(-) rename server/sonar-server/src/main/java/org/sonar/server/{search/EsSearchModule.java => es/EsModule.java} (86%) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/package-info.java rename server/sonar-server/src/test/java/org/sonar/server/{search/EsSearchModuleTest.java => es/EsModuleTest.java} (91%) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/FacetValueTest.java diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 80ea989fe53..eb3f3c9e353 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -143,7 +143,7 @@ import org.sonar.server.rule.DefaultRuleFinder; import org.sonar.server.rule.DeprecatedRulesDefinitionLoader; import org.sonar.server.rule.RuleDefinitionsLoader; import org.sonar.server.rule.index.RuleIndex; -import org.sonar.server.search.EsSearchModule; +import org.sonar.server.es.EsModule; import org.sonar.server.setting.DatabaseSettingLoader; import org.sonar.server.setting.DatabaseSettingsEnabler; import org.sonar.server.setting.ThreadLocalSettings; @@ -265,7 +265,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { DbClient.class, // Elasticsearch - EsSearchModule.class, + EsModule.class, // rules/qprofiles RuleIndex.class, diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index bf87bddc653..64ed2a4a89b 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -119,7 +119,7 @@ public class ComputeEngineContainerImplTest { COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION + 26 // level 1 + 53 // content of DaoModule - + 3 // content of EsSearchModule + + 3 // content of EsModule + 57 // content of CorePropertyDefinitions + 1 // StopFlagContainer ); 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/es/EsModule.java similarity index 86% rename from server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java rename to server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java index 77db6844064..bb306dc55fc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java @@ -17,14 +17,12 @@ * 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; +package org.sonar.server.es; import org.sonar.core.platform.Module; -import org.sonar.server.es.EsClientProvider; -import org.sonar.server.es.EsClientStopper; import org.sonar.server.permission.index.AuthorizationTypeSupport; -public class EsSearchModule extends Module { +public class EsModule extends Module { @Override protected void configureModule() { add(AuthorizationTypeSupport.class); 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 f86edc0e288..5dc9e5b92f7 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,6 +43,7 @@ import org.sonar.process.logging.LogbackHelper; import org.sonar.server.app.ProcessCommandWrapperImpl; import org.sonar.server.app.RestartFlagHolderImpl; import org.sonar.server.app.WebServerProcessLogging; +import org.sonar.server.es.EsModule; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.platform.LogServerVersion; import org.sonar.server.platform.Platform; @@ -52,7 +53,6 @@ import org.sonar.server.platform.UrlSettings; import org.sonar.server.platform.WebServerImpl; import org.sonar.server.platform.db.EmbeddedDatabaseFactory; import org.sonar.server.rule.index.RuleIndex; -import org.sonar.server.search.EsSearchModule; import org.sonar.server.setting.ThreadLocalSettings; import org.sonar.server.user.SystemPasscodeImpl; import org.sonar.server.user.ThreadLocalUserSession; @@ -112,7 +112,7 @@ public class PlatformLevel1 extends PlatformLevel { DaoModule.class, // Elasticsearch - EsSearchModule.class, + EsModule.class, // rules/qprofiles RuleIndex.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java index f6fe4d1dadd..ae94ead30eb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java @@ -23,10 +23,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ListMultimap; import java.lang.annotation.Annotation; -import java.util.Collection; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; import org.sonar.api.ExtensionProvider; import org.sonar.api.Plugin; import org.sonar.api.SonarRuntime; @@ -37,7 +35,6 @@ import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; -import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; /** @@ -49,16 +46,6 @@ public abstract class ServerExtensionInstaller { private final PluginRepository pluginRepository; private final Set> supportedAnnotationTypes; - protected ServerExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, - @Nullable Collection> supportedAnnotationTypes) { - checkArgument(supportedAnnotationTypes != null && !supportedAnnotationTypes.isEmpty(), - "At least one supported annotation type must be specified"); - this.sonarRuntime = sonarRuntime; - this.pluginRepository = pluginRepository; - this.supportedAnnotationTypes = ImmutableSet.copyOf(supportedAnnotationTypes); - - } - protected ServerExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, Class... supportedAnnotationTypes) { requireNonNull(supportedAnnotationTypes, "At least one supported annotation type must be specified"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java b/server/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java deleted file mode 100644 index 06c3b722212..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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; - -public class FacetValue { - - private final String key; - private final long value; - - public FacetValue(String key, long value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public long getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - FacetValue that = (FacetValue) o; - if (key == null) { - return that.key == null; - } else { - return key.equals(that.key); - } - } - - @Override - public int hashCode() { - return key != null ? key.hashCode() : 0; - } - - @Override - public String toString() { - return String.format("{%s=%d}", getKey(), getValue()); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/search/package-info.java deleted file mode 100644 index 1ab46781f8e..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.search; - -import javax.annotation.ParametersAreNonnullByDefault; 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/es/EsModuleTest.java similarity index 91% rename from server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java rename to server/sonar-server/src/test/java/org/sonar/server/es/EsModuleTest.java index 2bc33e5fd5f..972f8ad3ee9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsModuleTest.java @@ -17,18 +17,18 @@ * 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; +package org.sonar.server.es; import org.junit.Test; import org.sonar.core.platform.ComponentContainer; import static org.assertj.core.api.Assertions.assertThat; -public class EsSearchModuleTest { +public class EsModuleTest { @Test public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); - new EsSearchModule().configure(container); + new EsModule().configure(container); assertThat(container.size()).isEqualTo(3 + 2); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/FacetValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/FacetValueTest.java deleted file mode 100644 index 4b42d0d9d85..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/FacetValueTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 static org.assertj.core.api.Assertions.assertThat; - -public class FacetValueTest { - - @Test - public void should_check_for_equality_on_key() { - FacetValue facetValue = new FacetValue("polop", 42); - assertThat(facetValue.equals(facetValue)).isTrue(); - assertThat(facetValue.equals(null)).isFalse(); - assertThat(facetValue.equals(new Object())).isFalse(); - - assertThat(facetValue.equals(new FacetValue("polop", 666))).isTrue(); - assertThat(facetValue.equals(new FacetValue("palap", 42))).isFalse(); - - FacetValue withNullKey = new FacetValue(null, 42); - assertThat(facetValue.equals(withNullKey)).isFalse(); - assertThat(withNullKey.equals(withNullKey)).isTrue(); - assertThat(withNullKey.equals(facetValue)).isFalse(); - assertThat(withNullKey.equals(new FacetValue(null, 666))).isTrue(); - } - - @Test - public void should_use_key_hashcode() { - assertThat(new FacetValue(null, 42).hashCode()).isZero(); - String key = "polop"; - assertThat(new FacetValue(key, 666).hashCode()).isEqualTo(key.hashCode()); - } - - @Test - public void test_toString() { - assertThat(new FacetValue("polop", 42).toString()).isEqualTo("{polop=42}"); - } -} -- 2.39.5