]> source.dussan.org Git - sonarqube.git/commitdiff
When there's no language plugin, load core bundle
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 17 Apr 2014 15:45:24 +0000 (17:45 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 17 Apr 2014 15:45:24 +0000 (17:45 +0200)
sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java

index b987061e18ea73394810788a618c060846309c05..4bf009a9a422e0f28afb82e23423d85a9e80f9da 100644 (file)
@@ -84,21 +84,29 @@ public class DefaultI18n implements I18n, ServerExtension, BatchExtension, Start
   void doStart(ClassLoader classloader) {
     this.classloader = classloader;
     propertyToBundles = Maps.newHashMap();
-    for (PluginMetadata plugin : pluginRepository.getMetadata()) {
-      try {
-        String bundleKey = BUNDLE_PACKAGE + plugin.getKey();
-        ResourceBundle bundle = ResourceBundle.getBundle(bundleKey, Locale.ENGLISH, this.classloader, control);
-        Enumeration<String> keys = bundle.getKeys();
-        while (keys.hasMoreElements()) {
-          String key = keys.nextElement();
-          propertyToBundles.put(key, bundleKey);
-        }
-      } catch (MissingResourceException e) {
-        // ignore
+    Collection<PluginMetadata> metadata = pluginRepository.getMetadata();
+    if (metadata.isEmpty()) {
+      addPlugin("core");
+    } else {
+      for (PluginMetadata plugin : pluginRepository.getMetadata()) {
+        addPlugin(plugin.getKey());
       }
     }
     LOG.debug(String.format("Loaded %d properties from l10n bundles", propertyToBundles.size()));
   }
+  private void addPlugin(String pluginKey){
+    try {
+      String bundleKey = BUNDLE_PACKAGE + pluginKey;
+      ResourceBundle bundle = ResourceBundle.getBundle(bundleKey, Locale.ENGLISH, this.classloader, control);
+      Enumeration<String> keys = bundle.getKeys();
+      while (keys.hasMoreElements()) {
+        String key = keys.nextElement();
+        propertyToBundles.put(key, bundleKey);
+      }
+    } catch (MissingResourceException e) {
+      // ignore
+    }
+  }
 
   @Override
   public void stop() {
index f9fc70b09603d2e16596d767de8135d383c590f9..7fd150b36085a362b58e892f248638a1f1508399 100644 (file)
@@ -57,6 +57,15 @@ public class DefaultI18nTest {
     manager.doStart(getClass().getClassLoader());
   }
 
+  @Test
+  public void load_core_bundle_when_no_plugin() {
+    DefaultI18n manager = new DefaultI18n(mock(PluginRepository.class), system2);
+    manager.doStart(getClass().getClassLoader());
+
+    assertThat(manager.getPropertyKeys().contains("any")).isTrue();
+    assertThat(manager.getPropertyKeys().contains("assignee")).isTrue();
+  }
+
   @Test
   public void introspect_all_available_properties() {
     assertThat(manager.getPropertyKeys().contains("any")).isTrue();