From 98550e39c25d24f68d454d8939e4352b820aedd2 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 10 Mar 2018 15:33:35 +0100 Subject: Clean-up ES module in sonar-server --- .../main/java/org/sonar/server/es/EsModule.java | 32 +++++++++++ .../platform/platformlevel/PlatformLevel1.java | 4 +- .../server/plugins/ServerExtensionInstaller.java | 13 ----- .../org/sonar/server/search/EsSearchModule.java | 34 ----------- .../java/org/sonar/server/search/FacetValue.java | 66 ---------------------- .../java/org/sonar/server/search/package-info.java | 23 -------- .../java/org/sonar/server/es/EsModuleTest.java | 35 ++++++++++++ .../sonar/server/search/EsSearchModuleTest.java | 35 ------------ .../org/sonar/server/search/FacetValueTest.java | 56 ------------------ 9 files changed, 69 insertions(+), 229 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java 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 create mode 100644 server/sonar-server/src/test/java/org/sonar/server/es/EsModuleTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/FacetValueTest.java (limited to 'server/sonar-server') diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java new file mode 100644 index 00000000000..bb306dc55fc --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsModule.java @@ -0,0 +1,32 @@ +/* + * 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.es; + +import org.sonar.core.platform.Module; +import org.sonar.server.permission.index.AuthorizationTypeSupport; + +public class EsModule extends Module { + @Override + protected void configureModule() { + add(AuthorizationTypeSupport.class); + add(new EsClientProvider()); + add(EsClientStopper.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/EsSearchModule.java b/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java deleted file mode 100644 index 77db6844064..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/EsSearchModule.java +++ /dev/null @@ -1,34 +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.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 { - @Override - protected void configureModule() { - add(AuthorizationTypeSupport.class); - add(new EsClientProvider()); - add(EsClientStopper.class); - } -} 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/es/EsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsModuleTest.java new file mode 100644 index 00000000000..972f8ad3ee9 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsModuleTest.java @@ -0,0 +1,35 @@ +/* + * 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.es; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EsModuleTest { + @Test + public void verify_count_of_added_components() { + ComponentContainer container = new ComponentContainer(); + new EsModule().configure(container); + assertThat(container.size()).isEqualTo(3 + 2); + } + +} 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 deleted file mode 100644 index 2bc33e5fd5f..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/EsSearchModuleTest.java +++ /dev/null @@ -1,35 +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 org.sonar.core.platform.ComponentContainer; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EsSearchModuleTest { - @Test - public void verify_count_of_added_components() { - ComponentContainer container = new ComponentContainer(); - new EsSearchModule().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}"); - } -} -- cgit v1.2.3