[jboss-cvs] JBossAS SVN: r92761 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/api and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 24 18:10:03 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-24 18:10:03 -0400 (Mon, 24 Aug 2009)
New Revision: 92761

Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/SystemPackagesPlugin.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/integration/simple/SimpleLogServiceTestCase.java
Log:
[JBOSGI-135] Cannot handle package beeing imported and exported by the same bundle
More tests and debugging

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -110,22 +110,25 @@
          {
             String packageName = packageAttribute.getPackageInfo().getName();
             
+            // [TODO] Import package requirements should probably resolve against export capabilities
+            boolean isExportPackage = exportedNames.contains(packageName);
+            
             // [TODO] Should system packages be added as capabilities?
             boolean isSystemPackage = syspackPlugin.isSystemPackage(packageName);
             
-            boolean isOptional = false;
-            Parameter resolution = packageAttribute.getParameter(Constants.RESOLUTION_DIRECTIVE);
-            if (resolution != null && Constants.RESOLUTION_OPTIONAL.equals(resolution.getValue()))
-               isOptional = true;
-
-            // [TODO] Import package requirements should probably resolve against export capabilities
-            boolean isExportPackage = exportedNames.contains(packageName);
-            
-            if (!isSystemPackage && !isExportPackage && !isOptional)
+            // [TODO] add exported package requirements
+            if (isSystemPackage == false && isExportPackage == false)
             {
                // [TODO] add version ranges
                PackageRequirement requirement = new PackageRequirement(packageName);
-               classLoadingMetaData.getRequirements().addRequirement(requirement);
+
+               Parameter resolution = packageAttribute.getParameter(Constants.RESOLUTION_DIRECTIVE);
+               if (resolution != null && Constants.RESOLUTION_OPTIONAL.equals(resolution.getValue()))
+                  requirement.setOptional(true);
+               
+               // [TODO] add optional package requirements
+               if (requirement.isOptional() == false)
+                  classLoadingMetaData.getRequirements().addRequirement(requirement);
             }
          }
       }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/SystemPackagesPlugin.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/SystemPackagesPlugin.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/SystemPackagesPlugin.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -35,7 +35,5 @@
 {
    List<String> getSystemPackages();
    
-   String getSystemPackagesAsString();
-
    boolean isSystemPackage(String name);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -349,7 +349,7 @@
          StringBuffer buffer = new StringBuffer("Cannot assign [" + className + "] comming from different exporters");
          buffer.append("\n  " + sourceLoader.toString());
          buffer.append("\n  " + otherLoader);
-         throw new ClassCastException(buffer.toString());
+         log.warn(buffer.toString());
       }
       return equals;
    }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -21,6 +21,8 @@
 */
 package org.jboss.osgi.plugins.facade.classloading;
 
+import java.util.List;
+
 import org.jboss.classloader.plugins.filter.PatternClassFilter;
 import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.classloader.spi.ClassLoaderDomain;
@@ -56,8 +58,7 @@
       ClassLoaderDomain domain = getDefaultDomain();
       
       // Initialize the configured system packages
-      SystemPackagesPlugin syspackPlugin = bundleManager.getPlugin(SystemPackagesPlugin.class);
-      String sysPackageString = syspackPlugin.getSystemPackagesAsString();
+      String sysPackageString = getSystemPackagesAsString(bundleManager);
       PatternClassFilter filter = PackageClassFilter.createPackageClassFilterFromString(sysPackageString);
       filter.setIncludeJava(true);
       
@@ -75,4 +76,21 @@
    {
       return new OSGiBundleClassLoader(policy);
    }
+
+   private String getSystemPackagesAsString(OSGiBundleManager bundleManager)
+   {
+      SystemPackagesPlugin syspackPlugin = bundleManager.getPlugin(SystemPackagesPlugin.class);
+      List<String> sysPackages = syspackPlugin.getSystemPackages();
+      StringBuffer sysPackageString = new StringBuffer();
+      for (String name : sysPackages)
+      {
+         int semiIndex = name.indexOf(';');
+         if (semiIndex > 0)
+            name = name.substring(0, semiIndex);
+         
+         sysPackageString.append(name + ",");
+      }
+      return sysPackageString.toString();
+   }
+
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -98,16 +98,6 @@
       return Collections.unmodifiableList(allPackages);
    }
    
-   @Override
-   public String getSystemPackagesAsString()
-   {
-      StringBuffer sysPackageString = new StringBuffer();
-      for (String name : allPackageNames)
-         sysPackageString.append(name + ",");
-      
-      return sysPackageString.toString();
-   }
-
    public boolean isSystemPackage(String name)
    {
       if(name == null)

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/integration/simple/SimpleLogServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/integration/simple/SimpleLogServiceTestCase.java	2009-08-24 21:48:06 UTC (rev 92760)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/integration/simple/SimpleLogServiceTestCase.java	2009-08-24 22:10:03 UTC (rev 92761)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import static org.junit.Assert.*;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -30,6 +31,7 @@
 import org.jboss.osgi.spi.testing.OSGiTest;
 import org.jboss.osgi.spi.util.ServiceLoader;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -50,17 +52,17 @@
    {
       System.clearProperty("simple-logservice-bundle");
    }
-   
+
    @Test
    public void testNoLogService() throws Exception
    {
       FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
       Framework framework = factory.newFramework(null);
       framework.start();
-      
+
       BundleContext sysContext = framework.getBundleContext();
       Bundle bundle = sysContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
-      
+
       try
       {
          bundle.start();
@@ -70,7 +72,7 @@
       {
          // expected
       }
-      
+
       framework.stop();
    }
 
@@ -80,21 +82,21 @@
       FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
       Framework framework = factory.newFramework(null);
       framework.start();
-      
+
       BundleContext sysContext = framework.getBundleContext();
       sysContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar")).start();
-      
+
       Bundle bundle = sysContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
       bundle.start();
 
       // The bundle activator is expected to set this property
       String result = System.getProperty(bundle.getSymbolicName());
       assertNotNull("Result property not null", result);
-      
+
       assertTrue("BundleActivator start", result.indexOf("startBundleActivator") > 0);
       assertTrue("getService", result.indexOf("getService") > 0);
       assertTrue("addingService", result.indexOf("addingService") > 0);
-      
+
       framework.stop();
    }
 
@@ -104,29 +106,56 @@
       FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
       Framework framework = factory.newFramework(null);
       framework.start();
+
+      BundleContext sysContext = framework.getBundleContext();
+      Bundle cmpd = sysContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
       
+      System.out.println("FIXME [JBOSGI-136] Cannot resolve dependency against unstarted bundle");
+      cmpd.start();
+
+      Bundle bundle = sysContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+      bundle.start();
+
+      // The bundle activator is expected to set this property
+      String result = System.getProperty(bundle.getSymbolicName());
+      assertNotNull("Result property not null", result);
+
+      assertTrue("BundleActivator start", result.indexOf("startBundleActivator") > 0);
+      assertFalse("getService", result.indexOf("getService") > 0);
+      assertFalse("addingService", result.indexOf("addingService") > 0);
+
+      framework.stop();
+   }
+
+   @Test
+   public void testLogServiceFromTwoExporters() throws Exception
+   {
+      FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+      Framework framework = factory.newFramework(null);
+      framework.start();
+
       BundleContext sysContext = framework.getBundleContext();
       sysContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar")).start();
       sysContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar")).start();
-      
+
       Bundle bundle = sysContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
-      
+
       if (true)
       {
          System.out.println("FIXME [JBOSGI-135] Cannot handle package beeing imported and exported by the same bundle");
          return;
       }
-      
+
       bundle.start();
 
       // The bundle activator is expected to set this property
       String result = System.getProperty(bundle.getSymbolicName());
       assertNotNull("Result property not null", result);
-      
+
       assertTrue("BundleActivator start", result.indexOf("startBundleActivator") > 0);
       assertTrue("getService", result.indexOf("getService") > 0);
       assertTrue("addingService", result.indexOf("addingService") > 0);
-      
+
       framework.stop();
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list