[jboss-osgi-commits] JBoss-OSGI SVN: r99902 - in projects/jboss-osgi: trunk/testsuite/functional/scripts and 7 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Jan 25 09:31:12 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-25 09:31:10 -0500 (Mon, 25 Jan 2010)
New Revision: 99902

Added:
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/LocalizationTestCase.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_de.properties
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_en.properties
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-frag.bnd
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-host.bnd
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiFragmentState.java
   projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGi99TestCase.java
Log:
[JBOSGI-272] Implement bundle header localization

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-01-25 12:16:28 UTC (rev 99901)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-01-25 14:31:10 UTC (rev 99902)
@@ -267,13 +267,13 @@
          baseName = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
 
       // Get the resource bundle URL for the given base and locale
-      URL entryURL = getLocalizationEntryPath(baseName, locale);
+      URL entryURL = getLocalizationEntry(baseName, locale);
 
       // If the specified locale entry could not be found fall back to the default locale entry
       if (entryURL == null)
       {
          String defaultLocale = Locale.getDefault().toString();
-         entryURL = getLocalizationEntryPath(baseName, defaultLocale);
+         entryURL = getLocalizationEntry(baseName, defaultLocale);
       }
 
       // Read the resource bundle
@@ -317,16 +317,17 @@
       return new CaseInsensitiveDictionary(locHeaders);
    }
 
-   private URL getLocalizationEntryPath(String baseName, String locale)
+   URL getLocalizationEntry(String baseName, String locale)
    {
       // The Framework searches for localization entries by appending suffixes to
       // the localization base name according to a specified locale and finally
       // appending the .properties suffix. If a translation is not found, the locale
       // must be made more generic by first removing the variant, then the country
       // and finally the language until an entry is found that contains a valid translation.
-
+      
       String entryPath = baseName + "_" + locale + ".properties";
-      URL entryURL = getEntryInternal(entryPath);
+      
+      URL entryURL = getLocalizationEntry(entryPath);
       while (entryURL == null)
       {
          if (entryPath.equals(baseName + ".properties"))
@@ -345,11 +346,29 @@
 
          // The bundle's class loader is not used to search for localization entries. Only
          // the contents of the bundle and its attached fragments are searched.
-         entryURL = getEntryInternal(entryPath);
+         entryURL = getLocalizationEntry(entryPath);
       }
       return entryURL;
    }
 
+   /**
+   * The framework must search for localization entries using the follow-
+   * ing search rules based on the bundle type:
+   *
+   * fragment bundle - If the bundle is a resolved fragment, then the search
+   *   for localization data must delegate to the attached host bundle with the
+   *   highest version. If the fragment is not resolved, then the framework
+   *   must search the fragment's JAR for the localization entry.
+   *
+   * other bundle - The framework must first search in the bundle’s JAR for
+   *   the localization entry. If the entry is not found and the bundle has fragments, 
+   *   then the attached fragment JARs must be searched for the localization entry.
+   */
+   URL getLocalizationEntry(String entryPath)
+   {
+      return null;
+   }
+
    // Get the entry without checking permissions and bundle state. 
    URL getEntryInternal(String path)
    {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-25 12:16:28 UTC (rev 99901)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-25 14:31:10 UTC (rev 99902)
@@ -185,6 +185,25 @@
       return classLoader.getResources(name);
    }
 
+   @Override
+   URL getLocalizationEntry(String entryPath)
+   {
+      // The framework must first search in the bundle’s JAR for
+      // the localization entry. If the entry is not found and the bundle has fragments, 
+      // then the attached fragment JARs must be searched for the localization entry.
+      URL entryURL = getEntryInternal(entryPath);
+      if (entryURL == null)
+      {
+         for (OSGiFragmentState frag : getAttachedFragments())
+         {
+            entryURL = frag.getEntryInternal(entryPath);
+            if (entryURL != null)
+               break;
+         }
+      }
+      return entryURL;
+   }
+
    // [TODO] options
    public void start(int options) throws BundleException
    {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiFragmentState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiFragmentState.java	2010-01-25 12:16:28 UTC (rev 99901)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiFragmentState.java	2010-01-25 14:31:10 UTC (rev 99902)
@@ -75,6 +75,25 @@
       return null;
    }
 
+   @Override
+   URL getLocalizationEntry(String entryPath)
+   {
+      // If the bundle is a resolved fragment, then the search
+      // for localization data must delegate to the attached host bundle with the
+      // highest version. If the fragment is not resolved, then the framework
+      // must search the fragment's JAR for the localization entry.
+      if (getState() == Bundle.RESOLVED)
+      {
+         OSGiBundleState host = getFragmentHost();
+         return host.getLocalizationEntry(entryPath);
+      }
+      else
+      {
+         URL entryURL = getEntryInternal(entryPath);
+         return entryURL;
+      }
+   }
+   
    @SuppressWarnings("rawtypes")
    public Class loadClass(String name) throws ClassNotFoundException
    {

Modified: projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2010-01-25 12:16:28 UTC (rev 99901)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2010-01-25 14:31:10 UTC (rev 99902)
@@ -150,6 +150,10 @@
     <!-- jbosgi214 -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi214-bundle.jar" files="${tests.resources.dir}/jbosgi214/jbosgi214-bundle.bnd" />
 
+    <!-- localization -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/localization-simple-host.jar" files="${tests.resources.dir}/localization/localization-simple-host.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/localization-simple-frag.jar" files="${tests.resources.dir}/localization/localization-simple-frag.bnd" />
+
     <!-- performance -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/performance-blueprint.jar" files="${tests.resources.dir}/performance/blueprint/performance-blueprint.bnd" />
 

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGi99TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGi99TestCase.java	2010-01-25 12:16:28 UTC (rev 99901)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGi99TestCase.java	2010-01-25 14:31:10 UTC (rev 99902)
@@ -85,9 +85,7 @@
       assertBundleState(Bundle.ACTIVE, bundle.getState());
 
       bundle.uninstall();
-
-      if (runtime.isRemoteRuntime() == false)
-         assertBundleState(Bundle.UNINSTALLED, bundle.getState());
+      assertBundleState(Bundle.UNINSTALLED, bundle.getState());
    }
 
    @Test
@@ -108,9 +106,7 @@
       }
 
       bundle.uninstall();
-
-      if (runtime.isRemoteRuntime() == false)
-         assertBundleState(Bundle.UNINSTALLED, bundle.getState());
+      assertBundleState(Bundle.UNINSTALLED, bundle.getState());
    }
 
    @Test
@@ -131,9 +127,7 @@
       }
 
       bundle.uninstall();
-
-      if (runtime.isRemoteRuntime() == false)
-         assertBundleState(Bundle.UNINSTALLED, bundle.getState());
+      assertBundleState(Bundle.UNINSTALLED, bundle.getState());
    }
 
    @Test
@@ -157,14 +151,14 @@
          bundle = runtime.getBundle("jbosgi99-allgood", null);
          if (bundle != null && bundle.getState() == Bundle.ACTIVE)
             break;
-         
+
          Thread.sleep(200);
          timeout -= 200;
       }
-      
+
       assertNotNull("Bundle not null", bundle);
       assertBundleState(Bundle.ACTIVE, bundle.getState());
-      
+
       // Delete the bundle from the deploy directory
       outFile.delete();
 
@@ -173,11 +167,11 @@
       {
          if (bundle.getState() == Bundle.UNINSTALLED)
             break;
-         
+
          Thread.sleep(200);
          timeout -= 200;
       }
-      
+
       assertBundleState(Bundle.UNINSTALLED, bundle.getState());
    }
 

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/LocalizationTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/LocalizationTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/LocalizationTestCase.java	2010-01-25 14:31:10 UTC (rev 99902)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.localization;
+
+//$Id$
+
+import static org.junit.Assert.*;
+
+import java.util.Dictionary;
+import java.util.Locale;
+
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.osgi.testing.OSGiTestHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * Test the Localization
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 25-Jan-2010
+ */
+public class LocalizationTestCase extends OSGiTest
+{
+   private static OSGiRuntime runtime;
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      runtime = new OSGiTestHelper().getDefaultRuntime();
+   }
+
+   @AfterClass
+   public static void afterClass()
+   {
+      if (runtime != null)
+      {
+         runtime.shutdown();
+         runtime = null;
+      }
+   }
+
+   @Test
+   public void testHostLocalization() throws Exception
+   {
+      OSGiBundle host = runtime.installBundle("localization-simple-host.jar");
+      assertBundleState(Bundle.INSTALLED, host.getState());
+
+      // Test default locale
+      Dictionary<String, String> headers = host.getHeaders();
+      String bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("English Bundle Name", bundleName);
+      
+      // Test explicit default locale
+      headers = host.getHeaders(null);
+      bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("English Bundle Name", bundleName);
+      
+      // Test raw headers
+      headers = host.getHeaders("");
+      bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("%bundle-name", bundleName);
+      
+      host.uninstall();
+      assertBundleState(Bundle.UNINSTALLED, host.getState());
+
+      // Test default locale after uninstall
+      headers = host.getHeaders();
+      bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("English Bundle Name", bundleName);
+   }
+
+   @Test
+   public void testFragmentLocalization() throws Exception
+   {
+      OSGiBundle host = runtime.installBundle("localization-simple-host.jar");
+      OSGiBundle frag = runtime.installBundle("localization-simple-frag.jar");
+      
+      host.start();
+      assertBundleState(Bundle.ACTIVE, host.getState());
+      assertBundleState(Bundle.RESOLVED, frag.getState());
+
+      // Test explicit locale
+      Dictionary<String, String> headers = host.getHeaders(Locale.GERMAN.toString());
+      String bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("Deutscher Bundle Name", bundleName);
+      
+      host.uninstall();
+      assertBundleState(Bundle.UNINSTALLED, host.getState());
+      
+      frag.uninstall();
+      assertBundleState(Bundle.UNINSTALLED, frag.getState());
+
+      // Test default locale after uninstall
+      headers = host.getHeaders();
+      bundleName = headers.get(Constants.BUNDLE_NAME);
+      assertEquals("English Bundle Name", bundleName);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/localization/LocalizationTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_de.properties
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_de.properties	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_de.properties	2010-01-25 14:31:10 UTC (rev 99902)
@@ -0,0 +1 @@
+bundle-name=Deutscher Bundle Name


Property changes on: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_de.properties
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_en.properties
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_en.properties	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_en.properties	2010-01-25 14:31:10 UTC (rev 99902)
@@ -0,0 +1 @@
+bundle-name=English Bundle Name


Property changes on: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/OSGI-INF/l10n/bundle_en.properties
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-frag.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-frag.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-frag.bnd	2010-01-25 14:31:10 UTC (rev 99902)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-l10n.jar src/test/resources/localization/localization-simple-frag.bnd
+
+Bundle-SymbolicName: localization-simple-frag
+Fragment-Host: localization-simple-host
+Include-Resource: OSGI-INF/l10n/bundle_de.properties=OSGI-INF/l10n/bundle_de.properties
+
+-removeheaders: Include-Resource
+

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-host.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-host.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/localization/localization-simple-host.bnd	2010-01-25 14:31:10 UTC (rev 99902)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-l10n.jar src/test/resources/localization/localization-simple-host.bnd
+
+Bundle-SymbolicName: localization-simple-host
+Bundle-Name: %bundle-name
+Include-Resource: OSGI-INF/l10n/bundle_en.properties=OSGI-INF/l10n/bundle_en.properties
+
+-removeheaders: Include-Resource
+



More information about the jboss-osgi-commits mailing list