aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-05-25 11:23:29 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-12 20:20:59 +0200
commitded90fa8efaec6c497b066500e1d0f4dc531e4d5 (patch)
tree76d528783f01352144fc6f4ed65076ae758b63ad /server/sonar-server-common
parent10f7f22611704b51dc9ebef153311fbd01aa7455 (diff)
downloadsonarqube-ded90fa8efaec6c497b066500e1d0f4dc531e4d5.tar.gz
sonarqube-ded90fa8efaec6c497b066500e1d0f4dc531e4d5.zip
SONAR-10690 add Core Extension support in SonarQube
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/build.gradle34
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/l18n/ServerI18n.java58
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/l18n/ServerI18nTest.java93
-rw-r--r--server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle.properties1
-rw-r--r--server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle_fr.properties1
-rw-r--r--server/sonar-server-common/src/test/resources/org/sonar/l10n/core_fr.properties2
-rw-r--r--server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext.properties1
-rw-r--r--server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext_fr.properties1
8 files changed, 191 insertions, 0 deletions
diff --git a/server/sonar-server-common/build.gradle b/server/sonar-server-common/build.gradle
new file mode 100644
index 00000000000..12184b6cdaa
--- /dev/null
+++ b/server/sonar-server-common/build.gradle
@@ -0,0 +1,34 @@
+sonarqube {
+ properties {
+ property 'sonar.projectName', "${projectTitle} :: Server :: Common"
+ }
+}
+
+dependencies {
+ // please keep the list grouped by configuration and ordered by name
+
+ compile 'com.google.guava:guava'
+ compile 'org.slf4j:slf4j-api'
+
+ compile project(':sonar-core')
+ compileOnly project(path: ':sonar-plugin-api')
+
+ compileOnly 'com.google.code.findbugs:jsr305'
+
+ testCompile 'com.google.code.findbugs:jsr305'
+ testCompile 'com.tngtech.java:junit-dataprovider'
+ testCompile 'junit:junit'
+ testCompile 'org.assertj:assertj-core'
+ testCompile 'org.mockito:mockito-core'
+}
+
+//artifactoryPublish.skip = false
+
+// Used by core plugins
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ from components.java
+ }
+ }
+}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/l18n/ServerI18n.java b/server/sonar-server-common/src/main/java/org/sonar/server/l18n/ServerI18n.java
new file mode 100644
index 00000000000..0f5c55663d6
--- /dev/null
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/l18n/ServerI18n.java
@@ -0,0 +1,58 @@
+/*
+ * 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.l18n;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.System2;
+import org.sonar.core.i18n.DefaultI18n;
+import org.sonar.core.platform.PluginRepository;
+import org.sonar.core.extension.CoreExtension;
+import org.sonar.core.extension.CoreExtensionRepository;
+
+/**
+ * Subclass of {@link DefaultI18n} which supports Core Extensions.
+ */
+@ServerSide
+@ComputeEngineSide
+public class ServerI18n extends DefaultI18n {
+ private final CoreExtensionRepository coreExtensionRepository;
+
+ public ServerI18n(PluginRepository pluginRepository, System2 system2, CoreExtensionRepository coreExtensionRepository) {
+ super(pluginRepository, system2);
+ this.coreExtensionRepository = coreExtensionRepository;
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+
+ coreExtensionRepository.loadedCoreExtensions()
+ .map(CoreExtension::getName)
+ .forEach(this::initPlugin);
+ }
+
+ @VisibleForTesting
+ @Override
+ protected void doStart(ClassLoader classloader) {
+ super.doStart(classloader);
+ }
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/l18n/ServerI18nTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/l18n/ServerI18nTest.java
new file mode 100644
index 00000000000..608b2f3fde7
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/l18n/ServerI18nTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.l18n;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Stream;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.utils.internal.TestSystem2;
+import org.sonar.core.extension.CoreExtension;
+import org.sonar.core.extension.CoreExtensionRepository;
+import org.sonar.core.platform.PluginInfo;
+import org.sonar.core.platform.PluginRepository;
+
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ServerI18nTest {
+
+ private TestSystem2 system2 = new TestSystem2();
+ private ServerI18n underTest;
+
+ @Before
+ public void before() {
+ PluginRepository pluginRepository = mock(PluginRepository.class);
+ List<PluginInfo> plugins = singletonList(newPlugin("checkstyle"));
+ when(pluginRepository.getPluginInfos()).thenReturn(plugins);
+
+ CoreExtensionRepository coreExtensionRepository = mock(CoreExtensionRepository.class);
+ Stream<CoreExtension> coreExtensions = Stream.of(newCoreExtension("coreext"), newCoreExtension("othercorext"));
+ when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(coreExtensions);
+
+ underTest = new ServerI18n(pluginRepository, system2, coreExtensionRepository);
+ underTest.doStart(getClass().getClassLoader());
+ }
+
+ @Test
+ public void get_english_labels() {
+ assertThat(underTest.message(Locale.ENGLISH, "any", null)).isEqualTo("Any");
+ assertThat(underTest.message(Locale.ENGLISH, "coreext.rule1.name", null)).isEqualTo("Rule one");
+ }
+
+ @Test
+ public void get_english_labels_when_default_locale_is_not_english() {
+ Locale defaultLocale = Locale.getDefault();
+ try {
+ Locale.setDefault(Locale.FRENCH);
+ assertThat(underTest.message(Locale.ENGLISH, "any", null)).isEqualTo("Any");
+ assertThat(underTest.message(Locale.ENGLISH, "coreext.rule1.name", null)).isEqualTo("Rule one");
+ } finally {
+ Locale.setDefault(defaultLocale);
+ }
+ }
+
+ @Test
+ public void get_labels_from_french_pack() {
+ assertThat(underTest.message(Locale.FRENCH, "coreext.rule1.name", null)).isEqualTo("Rule un");
+ assertThat(underTest.message(Locale.FRENCH, "any", null)).isEqualTo("Tous");
+ }
+
+ private static PluginInfo newPlugin(String key) {
+ PluginInfo plugin = mock(PluginInfo.class);
+ when(plugin.getKey()).thenReturn(key);
+ return plugin;
+ }
+
+ private static CoreExtension newCoreExtension(String name) {
+ CoreExtension res = mock(CoreExtension.class);
+ when(res.getName()).thenReturn(name);
+ return res;
+ }
+
+}
diff --git a/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle.properties b/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle.properties
new file mode 100644
index 00000000000..10fa9295c44
--- /dev/null
+++ b/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle.properties
@@ -0,0 +1 @@
+checkstyle.rule1.name=Rule one
diff --git a/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle_fr.properties b/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle_fr.properties
new file mode 100644
index 00000000000..b2fc8f9651f
--- /dev/null
+++ b/server/sonar-server-common/src/test/resources/org/sonar/l10n/checkstyle_fr.properties
@@ -0,0 +1 @@
+checkstyle.rule1.name=Rule un \ No newline at end of file
diff --git a/server/sonar-server-common/src/test/resources/org/sonar/l10n/core_fr.properties b/server/sonar-server-common/src/test/resources/org/sonar/l10n/core_fr.properties
new file mode 100644
index 00000000000..9b473d07f5c
--- /dev/null
+++ b/server/sonar-server-common/src/test/resources/org/sonar/l10n/core_fr.properties
@@ -0,0 +1,2 @@
+any=Tous
+empty=
diff --git a/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext.properties b/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext.properties
new file mode 100644
index 00000000000..e84fc7ce875
--- /dev/null
+++ b/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext.properties
@@ -0,0 +1 @@
+coreext.rule1.name=Rule one
diff --git a/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext_fr.properties b/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext_fr.properties
new file mode 100644
index 00000000000..0cd4598e2fb
--- /dev/null
+++ b/server/sonar-server-common/src/test/resources/org/sonar/l10n/coreext_fr.properties
@@ -0,0 +1 @@
+coreext.rule1.name=Rule un