[jboss-cvs] JBossAS SVN: r102772 - in projects/jboss-osgi/projects/runtime/framework/trunk: bundle/scripts and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 23 07:25:19 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-23 07:25:18 -0400 (Tue, 23 Mar 2010)
New Revision: 102772

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-all.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-bundles.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
   projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContext.java
   projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
[TCK] ServiceExceptions pass

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml	2010-03-23 11:25:18 UTC (rev 102772)
@@ -45,11 +45,27 @@
       <artifactId>bnd</artifactId>
     </dependency>
     
+    <dependency>
+      <groupId>org.jboss.kernel</groupId>
+      <artifactId>jboss-jmx-aop-mc-int</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.kernel</groupId>
+      <artifactId>jboss-jmx-mc-int</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
     <!-- Test bundles dependencies -->
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.configadmin</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
           <groupId>org.apache.felix</groupId>
@@ -64,7 +80,7 @@
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.log</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
           <groupId>org.apache.felix</groupId>
@@ -79,7 +95,7 @@
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.metatype</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
           <groupId>org.apache.felix</groupId>
@@ -94,52 +110,52 @@
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-apache-xerces</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-common</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-common-core</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-husky</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-jaxb</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.jmx</groupId>
       <artifactId>jboss-osgi-jmx</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.jndi</groupId>
       <artifactId>jboss-osgi-jndi</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-reflect</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-xml-binding</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-jetty-bundle</artifactId>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
 
     <!-- Test Dependencies -->
@@ -158,21 +174,6 @@
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>org.jboss.kernel</groupId>
-      <artifactId>jboss-jmx-aop-mc-int</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.kernel</groupId>
-      <artifactId>jboss-jmx-mc-int</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-all.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-all.xml	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-all.xml	2010-03-23 11:25:18 UTC (rev 102772)
@@ -35,11 +35,14 @@
         <include>*:jboss-managed:jar</include>
         <include>*:jboss-mdr:jar</include>
         <include>*:jboss-metatype:jar</include>
+        <include>*:jboss-osgi-deployers-vfs30:jar</include>
         <include>*:jboss-osgi-deployment:jar</include>
         <include>*:jboss-osgi-framework-core:jar</include>
         <include>*:jboss-osgi-framework-metadata:jar</include>
+        <include>*:jboss-osgi-framework-vfs30:jar</include>
         <include>*:jboss-osgi-spi:jar</include>
         <include>*:jboss-osgi-vfs:jar</include>
+        <include>*:jboss-osgi-vfs30:jar</include>
         <include>*:jboss-reflect:jar</include>
         <include>*:jboss-vfs:jar</include>
         <include>*:jbossxb:jar</include>
@@ -48,16 +51,13 @@
         <include>*:org.osgi.compendium:jar</include>
       </includes>
       <useStrictFiltering>true</useStrictFiltering>
-      <scope>compile</scope>
+      <scope>provided</scope>
       <unpack>true</unpack>
     </dependencySet>
     <dependencySet>
       <outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
       <includes>
         <include>*:jboss-logging-log4j:jar</include>
-        <include>*:jboss-osgi-deployers-vfs30:jar</include>
-        <include>*:jboss-osgi-framework-vfs30:jar</include>
-        <include>*:jboss-osgi-vfs30:jar</include>
         <include>*:log4j:jar</include>
       </includes>
       <useStrictFiltering>true</useStrictFiltering>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-bundles.xml	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/scripts/assembly-bundles.xml	2010-03-23 11:25:18 UTC (rev 102772)
@@ -30,7 +30,7 @@
         <include>*:pax-web-jetty-bundle:jar</include>
       </includes>
       <useStrictFiltering>true</useStrictFiltering>
-      <scope>test</scope>
+      <scope>provided</scope>
       <unpack>false</unpack>
     </dependencySet>
     

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java	2010-03-23 11:25:18 UTC (rev 102772)
@@ -112,8 +112,6 @@
    @Test
    public void testGetServiceFactory() throws Exception
    {
-      String OBJCLASS = BundleContext.class.getName();
-
       VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
       Bundle bundle = installBundle(assembly);
       try
@@ -137,7 +135,7 @@
 
          sreg.unregister();
          actual = context.getService(sref);
-         assertNull("" + actual, actual);
+         assertNull("Service null", actual);
       }
       finally
       {
@@ -184,6 +182,7 @@
    @Test
    public void testGetWrongInterfacesForServiceFactory() throws Exception
    {
+      String[] OBJCLASS = { String.class.getName() };
       String[] OBJCLASSES = { String.class.getName(), BundleContext.class.getName() };
 
       VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
@@ -196,17 +195,23 @@
 
          context.addFrameworkListener(this);
 
-         ServiceRegistration sreg = context.registerService(String.class.getName(), new SimpleServiceFactory(context), null);
+         SimpleServiceFactory factory = new SimpleServiceFactory(context);
+         ServiceRegistration sreg = context.registerService(OBJCLASS, factory, null);
          ServiceReference sref = sreg.getReference();
          Object actual = context.getService(sref);
-         assertNull("" + actual, actual);
+         assertNull("Service null", actual);
+         assertFalse(context.ungetService(sref));
+         assertEquals("ungetService() not called", 0, factory.ungetCount);
 
          assertFrameworkEvent(FrameworkEvent.ERROR, bundle, ServiceException.class);
 
-         sreg = context.registerService(OBJCLASSES, new SimpleServiceFactory(context), null);
+         factory = new SimpleServiceFactory(context);
+         sreg = context.registerService(OBJCLASSES, factory, null);
          sref = sreg.getReference();
          actual = context.getService(sref);
-         assertNull("" + actual, actual);
+         assertNull("Service null", actual);
+         assertFalse(context.ungetService(sref));
+         assertEquals("ungetService() not called", 0, factory.ungetCount);
 
          assertFrameworkEvent(FrameworkEvent.ERROR, bundle, ServiceException.class);
       }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java	2010-03-23 11:25:18 UTC (rev 102772)
@@ -33,7 +33,7 @@
  */
 public class SimpleServiceFactory implements ServiceFactory
 {
-   public Object service;
+   Object service;
 
    public Bundle getBundle;
    public int getCount;
@@ -55,11 +55,11 @@
       return service;
    }
 
-   public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+   public void ungetService(Bundle bundle, ServiceRegistration registration, Object unget)
    {
       ungetBundle = bundle;
       ungetRegistration = registration;
-      ungetService = service;
+      ungetService = unget;
       ungetCount++;
    }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContext.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContext.java	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContext.java	2010-03-23 11:25:18 UTC (rev 102772)
@@ -57,17 +57,29 @@
       // The reason is that the OSGi {@link ServiceFactory} getService() method
       // is called with a {@link ServiceReference} that expects the given tracker 
       // (i.e. the using bundle) already be included in getUsingBundles.  
-      
+
       if (tracker != null)
       {
          ContextTracker myTracker = getContextTracker();
          if (myTracker != null && myTracker != tracker)
             myTracker.incrementUsedBy(this, tracker);
-         
+
          tracker.incrementUsedBy(this, tracker);
       }
+
+      // Get the service object
+      Object result = getTargetForActualUser(tracker);
       
-      Object result = getTargetForActualUser(tracker);
+      // In case the ServiceFactory.getService() returns null decrement the usage count again
+      if (result == null)
+      {
+         ContextTracker myTracker = getContextTracker();
+         if (myTracker != null && myTracker != tracker)
+            myTracker.decrementUsedBy(this, tracker);
+
+         tracker.decrementUsedBy(this, tracker);
+      }
+
       return result;
    }
 
@@ -81,7 +93,7 @@
       // The reason is that the OSGi {@link ServiceFactory} ungetService() method
       // is called with a {@link ServiceReference} that expects the given tracker 
       // (i.e. the using bundle) already be included in getUsingBundles.
-      
+
       Object result = ungetTargetForActualUser(tracker);
       if (tracker != null)
       {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2010-03-23 10:59:55 UTC (rev 102771)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2010-03-23 11:25:18 UTC (rev 102772)
@@ -377,7 +377,6 @@
          if (service == null)
          {
             ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
-            boolean gotService = false;
             
             // If the service object returned by the ServiceFactory object is not an instanceof all the classes named when 
             // the service was registered or the ServiceFactory object throws an exception, null is returned and a Framework 
@@ -385,22 +384,26 @@
             try
             {
                service = serviceFactory.getService(bundleState.getBundle(), getRegistration());
-               gotService = true;
-               
+            }
+            catch (Throwable t)
+            {
+               String msg = "Cannot get service from: " + serviceFactory;
+               ServiceException serviceException = new ServiceException(msg, ServiceException.FACTORY_EXCEPTION, t);
+               log.error("Exception in ServiceFactory.getService()", serviceException);
+               FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+               plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, serviceException);
+               return null;
+            }
+            try
+            {
                service = checkObjClass(service);
                serviceCache.put(bundleState, service);
             }
             catch (Throwable t)
             {
-               Throwable cause = t;
-               String message = "Cannot get service from: " + serviceFactory;
-               if (gotService == true)
-               {
-                  message += "." + t.getMessage();
-                  cause = null;
-               }
-               ServiceException serviceException = new ServiceException(message, cause);
-               log.error("Cannot getService from ServiceFactory", serviceException);
+               String msg = "Cannot get service from: " + serviceFactory;
+               ServiceException serviceException = new ServiceException(msg, ServiceException.FACTORY_ERROR);
+               log.error("Invalid type from ServiceFactory.getService()", serviceException);
                FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
                plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, serviceException);
                return null;




More information about the jboss-cvs-commits mailing list