mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-08-08 03:05:57 +02:00
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
This commit is contained in:
parent
dff9de8cb6
commit
868c0dfe9c
@ -76,14 +76,33 @@ 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) {
|
||||
LOG.debug("Search for bundles in language pack : {}", languagePack);
|
||||
for (String pluginKey : languagePack.getPluginKeys()) {
|
||||
@ -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";
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
BIN
plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar
Executable file
BIN
plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar
Executable file
Binary file not shown.
Binary file not shown.
57
plugins/sonar-i18n-en-plugin/pom.xml
Executable file
57
plugins/sonar-i18n-en-plugin/pom.xml
Executable file
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
14
pom.xml
14
pom.xml
@ -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>
|
||||
|
@ -203,6 +203,12 @@
|
||||
<version>${project.version}</version>
|
||||
<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>
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user