diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-07-13 18:08:34 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-07-13 18:08:34 +0200 |
commit | 868c0dfe9c18db210ddb9043ef53d69b0e59c4ca (patch) | |
tree | acd82072b510ff1da7c7e577837574b3bd9688e0 | |
parent | dff9de8cb6b737135050e29bde0c558dee88424a (diff) | |
download | sonarqube-868c0dfe9c18db210ddb9043ef53d69b0e59c4ca.tar.gz sonarqube-868c0dfe9c18db210ddb9043ef53d69b0e59c4ca.zip |
SONAR-2589 Creation of a I18n English Pack
- Creation of the plugin
- Modification the I18nManager to read keys from this plugin in the
first place
21 files changed, 225 insertions, 10 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java index 50df7fc5dfd..b8a4c4e5472 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java @@ -76,12 +76,31 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension void doStart(List<InstalledPlugin> installedPlugins) { Logs.INFO.info("Loading i18n bundles"); Set<URI> alreadyLoadedResources = Sets.newHashSet(); + LanguagePack englishPack = findEnglishPack(); + for (InstalledPlugin plugin : installedPlugins) { - searchAndStoreBundleNames(plugin.key, plugin.classloader, alreadyLoadedResources); + searchAndStoreBundleNames(plugin.key, englishPack.getClass().getClassLoader(), alreadyLoadedResources); } + for (LanguagePack pack : languagePacks) { - addLanguagePack(pack); + if ( !pack.equals(englishPack)) { + addLanguagePack(pack); + } + } + } + + private LanguagePack findEnglishPack() { + LanguagePack englishPack = null; + for (LanguagePack pack : languagePacks) { + if (pack.getLocales().contains(Locale.ENGLISH)) { + englishPack = pack; + break; + } + } + if (englishPack == null) { + throw new SonarException("The I18n English Pack was not found."); } + return englishPack; } private void addLanguagePack(LanguagePack languagePack) { @@ -102,6 +121,7 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension return packagePathToSearchIn + "/" + pluginKey; } + @SuppressWarnings("unchecked") private void searchAndStoreBundleNames(String pluginKey, ClassLoader classloader, Set<URI> alreadyLoadedResources) { String bundleBaseName = buildBundleBaseName(pluginKey); String bundleDefaultPropertiesFile = bundleBaseName + ".properties"; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/EnglishLanguagePack.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/EnglishLanguagePack.java new file mode 100644 index 00000000000..0660fd60527 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/EnglishLanguagePack.java @@ -0,0 +1,39 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.i18n; + +import org.sonar.api.i18n.LanguagePack; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +public class EnglishLanguagePack extends LanguagePack { + + @Override + public List<String> getPluginKeys() { + return Arrays.asList("test"); + } + + @Override + public List<Locale> getLocales() { + return Arrays.asList(Locale.ENGLISH); + } +}
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java index be700a32015..f8b8a299975 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java @@ -38,7 +38,7 @@ import com.google.common.collect.Lists; public class I18nManagerTest { - public static String TEST_PLUGIN_CLASS_NAME = "org.sonar.plugins.core.i18n.StandardPlugin"; + public static String ENGLISH_PACK_CLASS_NAME = "org.sonar.plugins.core.i18n.EnglishLanguagePack"; public static String FRENCH_PACK_CLASS_NAME = "org.sonar.plugins.core.i18n.FrenchLanguagePack"; public static String QUEBEC_PACK_CLASS_NAME = "org.sonar.plugins.core.i18n.QuebecLanguagePack"; @@ -47,17 +47,19 @@ public class I18nManagerTest { @Before public void createManager() throws Exception { - List<InstalledPlugin> plugins = Lists.newArrayList(new InstalledPlugin("test", new TestClassLoader(getClass().getClassLoader() - .getResource("StandardPlugin.jar"))), new InstalledPlugin("fake1", getClass().getClassLoader()), new InstalledPlugin("fake2", - getClass().getClassLoader())); + List<InstalledPlugin> plugins = Lists.newArrayList(new InstalledPlugin("test", getClass().getClassLoader()), new InstalledPlugin( + "fake1", getClass().getClassLoader()), new InstalledPlugin("fake2", getClass().getClassLoader())); - TestClassLoader frenchPackClassLoader = new TestClassLoader(getClass().getClassLoader().getResource("FrenchPlugin.jar")); + TestClassLoader englishPackClassLoader = new TestClassLoader(getClass().getClassLoader().getResource("I18n/EnglishPlugin.jar")); + LanguagePack englishPack = (LanguagePack) englishPackClassLoader.loadClass(ENGLISH_PACK_CLASS_NAME).newInstance(); + + TestClassLoader frenchPackClassLoader = new TestClassLoader(getClass().getClassLoader().getResource("I18n/FrenchPlugin.jar")); LanguagePack frenchPack = (LanguagePack) frenchPackClassLoader.loadClass(FRENCH_PACK_CLASS_NAME).newInstance(); - TestClassLoader quebecPackClassLoader = new TestClassLoader(getClass().getClassLoader().getResource("QuebecPlugin.jar")); + TestClassLoader quebecPackClassLoader = new TestClassLoader(getClass().getClassLoader().getResource("I18n/QuebecPlugin.jar")); LanguagePack quebecPack = (LanguagePack) quebecPackClassLoader.loadClass(QUEBEC_PACK_CLASS_NAME).newInstance(); - manager = new I18nManager(mock(PluginRepository.class), new LanguagePack[] { frenchPack, quebecPack }); + manager = new I18nManager(mock(PluginRepository.class), new LanguagePack[] { frenchPack, quebecPack, englishPack }); manager.doStart(plugins); } @@ -113,7 +115,7 @@ public class I18nManagerTest { protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class c = findLoadedClass(name); if (c == null) { - if (name.equals(TEST_PLUGIN_CLASS_NAME) || name.equals(QUEBEC_PACK_CLASS_NAME) || name.equals(FRENCH_PACK_CLASS_NAME)) { + if (name.equals(ENGLISH_PACK_CLASS_NAME) || name.equals(QUEBEC_PACK_CLASS_NAME) || name.equals(FRENCH_PACK_CLASS_NAME)) { c = findClass(name); } else { return super.loadClass(name, resolve); diff --git a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar Binary files differnew file mode 100755 index 00000000000..a0398457179 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar diff --git a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin/META-INF/MANIFEST.MF b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/META-INF/MANIFEST.MF index a45029d3531..a45029d3531 100644 --- a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin/META-INF/MANIFEST.MF +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/META-INF/MANIFEST.MF diff --git a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin/org/sonar/i18n/test.properties b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties index 88aabfe61a2..88aabfe61a2 100644 --- a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin/org/sonar/i18n/test.properties +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties diff --git a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin.jar b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin.jar Binary files differindex ab61bd88697..ab61bd88697 100644 --- a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin.jar +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin.jar diff --git a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin/META-INF/MANIFEST.MF b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin/META-INF/MANIFEST.MF index a45029d3531..a45029d3531 100644 --- a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin/META-INF/MANIFEST.MF +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin/META-INF/MANIFEST.MF diff --git a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin/org/sonar/i18n/test_fr.properties b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin/org/sonar/i18n/test_fr.properties index cc8efa7afc3..cc8efa7afc3 100644 --- a/plugins/sonar-core-plugin/src/test/resources/FrenchPlugin/org/sonar/i18n/test_fr.properties +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/FrenchPlugin/org/sonar/i18n/test_fr.properties diff --git a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin.jar b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin.jar Binary files differindex 101df34ba6d..101df34ba6d 100644 --- a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin.jar +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin.jar diff --git a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin/META-INF/MANIFEST.MF b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin/META-INF/MANIFEST.MF index a45029d3531..a45029d3531 100644 --- a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin/META-INF/MANIFEST.MF +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin/META-INF/MANIFEST.MF diff --git a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin/org/sonar/i18n/test_fr_CA.properties b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin/org/sonar/i18n/test_fr_CA.properties index 38b5b84ccdf..38b5b84ccdf 100644 --- a/plugins/sonar-core-plugin/src/test/resources/QuebecPlugin/org/sonar/i18n/test_fr_CA.properties +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/QuebecPlugin/org/sonar/i18n/test_fr_CA.properties diff --git a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin.jar b/plugins/sonar-core-plugin/src/test/resources/StandardPlugin.jar Binary files differdeleted file mode 100644 index 73deac7e8b6..00000000000 --- a/plugins/sonar-core-plugin/src/test/resources/StandardPlugin.jar +++ /dev/null diff --git a/plugins/sonar-i18n-en-plugin/pom.xml b/plugins/sonar-i18n-en-plugin/pom.xml new file mode 100755 index 00000000000..57e98d1efba --- /dev/null +++ b/plugins/sonar-i18n-en-plugin/pom.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar</artifactId> + <version>2.10-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + <groupId>org.codehaus.sonar.plugins</groupId> + <artifactId>sonar-i18n-en-plugin</artifactId> + <packaging>sonar-plugin</packaging> + <name>Sonar :: Plugins :: I18n English Pack</name> + + <dependencies> + <dependency> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-plugin-api</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>native2ascii-maven-plugin</artifactId> + <version>1.0-alpha-1</version> + <executions> + <execution> + <goals> + <goal>native2ascii</goal> + </goals> + <!-- specific configurations --> + <configuration> + <encoding>UTF8</encoding> + <src>${basedir}/src/main/resources</src> + <dest>${project.build.outputDirectory}</dest> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-packaging-maven-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <pluginKey>i18nen</pluginKey> + <pluginName>I18n English Pack</pluginName> + <pluginClass>org.sonar.plugins.i18n.en.EnglishPackPlugin</pluginClass> + <pluginDescription> + <![CDATA[Language pack for English.]]></pluginDescription> + </configuration> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPack.java b/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPack.java new file mode 100644 index 00000000000..6332bf1fce1 --- /dev/null +++ b/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPack.java @@ -0,0 +1,38 @@ +/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.plugins.i18n.en;
+
+import org.sonar.api.i18n.LanguagePack;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+public class EnglishPack extends LanguagePack {
+
+ public List<String> getPluginKeys() {
+ return Arrays.asList("core", "design");
+ }
+
+ public List<Locale> getLocales() {
+ return Arrays.asList(Locale.ENGLISH);
+ }
+}
diff --git a/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPackPlugin.java b/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPackPlugin.java new file mode 100755 index 00000000000..4d02f0fcd94 --- /dev/null +++ b/plugins/sonar-i18n-en-plugin/src/main/java/org/sonar/plugins/i18n/en/EnglishPackPlugin.java @@ -0,0 +1,33 @@ +/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.plugins.i18n.en;
+
+import org.sonar.api.SonarPlugin;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class EnglishPackPlugin extends SonarPlugin {
+
+ public List getExtensions() {
+ return Arrays.asList(EnglishPack.class);
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/i18n/core.properties b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties index f3f0233862e..f3f0233862e 100755 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/i18n/core.properties +++ b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties diff --git a/plugins/sonar-design-plugin/src/main/resources/org/sonar/i18n/design.properties b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/design.properties index e6356b6e141..e6356b6e141 100755 --- a/plugins/sonar-design-plugin/src/main/resources/org/sonar/i18n/design.properties +++ b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/design.properties @@ -48,6 +48,7 @@ <module>plugins/sonar-cpd-plugin</module> <module>plugins/sonar-squid-java-plugin</module> <module>plugins/sonar-design-plugin</module> + <module>plugins/sonar-i18n-en-plugin</module> </modules> <organization> @@ -1153,6 +1154,19 @@ <ignore></ignore> </action> </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.codehaus.mojo</groupId> + <artifactId>native2ascii-maven-plugin</artifactId> + <versionRange>[1.0-alpha-1,)</versionRange> + <goals> + <goal>native2ascii</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore></ignore> + </action> + </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 444f7a1479e..77e45c68e3c 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -204,6 +204,12 @@ <scope>runtime</scope> </dependency> <dependency> + <groupId>org.codehaus.sonar.plugins</groupId> + <artifactId>sonar-i18n-en-plugin</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> <groupId>org.sonatype.jsw-binaries</groupId> <artifactId>jsw-binaries</artifactId> <version>3.2.3.6</version> diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 8def231a492..4b3842e9f02 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -449,6 +449,12 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.codehaus.sonar.plugins</groupId> + <artifactId>sonar-i18n-en-plugin</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> </dependencies> </profile> |