[jboss-cvs] JBossAS SVN: r101113 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: main/java/org/jboss/osgi/framework/deployers and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 18 09:10:58 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-02-18 09:10:57 -0500 (Thu, 18 Feb 2010)
New Revision: 101113

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/AbstractDeployedBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.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/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
Log:
[JBOSGI-292] PackageAdmin cannot obtain classloading metadata

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-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -113,15 +113,25 @@
    }
 
    /**
+    * Create a new abstract bundle state.
+    * 
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public AbstractBundleState(OSGiBundleManager bundleManager)
+   {
+      this.bundleManager = bundleManager;
+      
+      if (bundleManager == null)
+         throw new IllegalArgumentException("Null bundle manager");
+   }
+
+   /**
     * Get the bundleManager.
     * 
     * @return the bundleManager.
     */
    public OSGiBundleManager getBundleManager()
    {
-      if (bundleManager == null)
-         throw new IllegalStateException("Bundle not installed: " + getCanonicalName());
-
       return bundleManager;
    }
 
@@ -638,19 +648,6 @@
    }
 
    /**
-    * Set the bundle manager
-    * 
-    * @param bundleManager the bundle manager or null to uninstall the bundle
-    */
-   void setBundleManager(OSGiBundleManager bundleManager)
-   {
-      if (bundleManager != null && this.bundleManager != null)
-         throw new IllegalStateException("Bundle " + this + " is already installed");
-
-      this.bundleManager = bundleManager;
-   }
-
-   /**
     * Change the state of the bundle
     * 
     * @param state the new state

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDeployedBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDeployedBundleState.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDeployedBundleState.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -69,12 +69,12 @@
 
    /**
     * Create a new BundleState.
-    * 
-    * @param unit the deployment unit
     * @throws IllegalArgumentException for a null parameter
     */
-   public AbstractDeployedBundleState(DeploymentUnit unit)
+   public AbstractDeployedBundleState(OSGiBundleManager bundleManager, DeploymentUnit unit)
    {
+      super(bundleManager);
+      
       if (unit == null)
          throw new IllegalArgumentException("Null deployment unit");
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ControllerContextPluginImpl.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -139,6 +139,7 @@
                try
                {
                   bundleState = (OSGiBundleState)bundleManager.addDeployment(unit);
+                  bundleManager.addBundle(bundleState);
                   bundleState.startInternal();
                }
                catch (Throwable t)

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -190,7 +190,7 @@
          throw new IllegalArgumentException("Null deployerClient");
       if (deployerClient instanceof MainDeployerStructure == false)
          throw new IllegalArgumentException("Deployer client does not implement " + MainDeployerStructure.class.getName());
-      
+
       this.kernel = kernel;
       this.deployerClient = deployerClient;
 
@@ -204,7 +204,7 @@
    public void start()
    {
       // Create the system Bundle
-      systemBundle = new OSGiSystemState();
+      systemBundle = new OSGiSystemState(this);
       addBundle(systemBundle);
    }
 
@@ -813,20 +813,15 @@
          if (fragmentHost != null)
          {
             // Create a new OSGiFragmentState
-            OSGiFragmentState fragmentState = new OSGiFragmentState(unit);
+            OSGiFragmentState fragmentState = new OSGiFragmentState(this, unit);
             absBundle = fragmentState;
-            addBundle(fragmentState);
          }
          else
          {
             // Create a new OSGiBundleState
-            AbstractDeployedBundleState bundleState = new OSGiBundleState(unit);
+            AbstractDeployedBundleState bundleState = new OSGiBundleState(this, unit);
             absBundle = bundleState;
-            addBundle(bundleState);
          }
-         
-         // Attach the abstract bundle state
-         unit.addAttachment(AbstractBundleState.class, absBundle);
       }
 
       // Attach the abstract bundle state
@@ -839,8 +834,12 @@
    }
 
    /**
-    * Add a bundle
+    * Add a bundle to the manager.
     * 
+    * Note, the bundle must be metadata complete when it is added to the manager.
+    * An extender might pickup the INSTALLED event and use PackageAdmin to examine the 
+    * exported packages for example.
+    * 
     * @param bundleState the bundle state
     * @throws IllegalArgumentException for a null bundle state
     */
@@ -849,21 +848,20 @@
       if (bundleState == null)
          throw new IllegalArgumentException("Null bundle state");
 
-      validateBundle(bundleState);
-
-      bundleState.setBundleManager(this);
-      allBundles.add(bundleState);
-
-      // Only fire the INSTALLED event if this is not an update
-      boolean fireEvent = true;
+      // Do nothing if this is a bundle update
       if (bundleState instanceof OSGiBundleState)
       {
          DeploymentUnit unit = ((AbstractDeployedBundleState)bundleState).getDeploymentUnit();
          Deployment dep = unit.getAttachment(Deployment.class);
-         fireEvent = (dep == null || dep.isBundleUpdate() == false);
+         if (dep != null && dep.isBundleUpdate())
+            return;
       }
 
-      bundleState.changeState(Bundle.INSTALLED, fireEvent);
+      validateBundle(bundleState);
+      
+      allBundles.add(bundleState);
+      
+      bundleState.changeState(Bundle.INSTALLED, true);
 
       // Add the bundle to the resolver
       // Note, plugins are not registered when the system bundle is added 
@@ -885,10 +883,13 @@
       if (osgiMetaData == null)
          return;
 
+      OSGiBundleValidator validator;
+      
       // Delegate to the validator for the appropriate revision
-      OSGiBundleValidator validator = new OSGiBundleValidatorR3(this);
       if (osgiMetaData.getBundleManifestVersion() > 1)
          validator = new OSGiBundleValidatorR4(this);
+      else
+         validator = new OSGiBundleValidatorR3(this);
 
       validator.validateBundle(bundleState);
    }
@@ -905,7 +906,6 @@
          throw new IllegalArgumentException("Null bundle state");
 
       bundleState.uninstallInternal();
-      bundleState.setBundleManager(null);
 
       // Remove the bundle from the resolver
       ResolverPlugin bundleResolver = getOptionalPlugin(ResolverPlugin.class);
@@ -1135,7 +1135,7 @@
       {
          deployerClient.change(unitName, DeploymentStages.CLASSLOADER);
          deployerClient.checkComplete(unitName);
-         
+
          // Advance the attached fragments to CLASSLOADER 
          for (OSGiFragmentState fragment : bundleState.getAttachedFragments())
          {
@@ -1143,11 +1143,11 @@
             deployerClient.change(fragUnitName, DeploymentStages.CLASSLOADER);
             deployerClient.checkComplete(fragUnitName);
          }
-            
+
          bundleState.changeState(Bundle.RESOLVED);
          for (OSGiFragmentState fragment : bundleState.getAttachedFragments())
             fragment.changeState(Bundle.RESOLVED);
-         
+
          return true;
       }
       catch (DeploymentException ex)

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-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -61,13 +61,10 @@
 
    /**
     * Create a new BundleState.
-    * 
-    * @param unit the deployment unit
-    * @throws IllegalArgumentException for a null parameter
     */
-   public OSGiBundleState(DeploymentUnit unit)
+   public OSGiBundleState(OSGiBundleManager bundleManager, DeploymentUnit unit)
    {
-      super(unit);
+      super(bundleManager, unit);
    }
 
    /**

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-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiFragmentState.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -42,9 +42,9 @@
    // The host that this fragment is attached to
    private OSGiBundleState fragmentHost;
    
-   public OSGiFragmentState(DeploymentUnit unit)
+   public OSGiFragmentState(OSGiBundleManager bundleManager, DeploymentUnit unit)
    {
-      super(unit);
+      super(bundleManager, unit);
    }
 
    public OSGiBundleState getFragmentHost()

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -50,8 +50,10 @@
    /**
     * Create a new OSGiSystemBundle.
     */
-   public OSGiSystemState()
+   public OSGiSystemState(OSGiBundleManager bundleManager)
    {
+      super(bundleManager);
+      
       Manifest manifest = new Manifest();
       Attributes attributes = manifest.getMainAttributes();
       attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -141,6 +141,9 @@
       }
 
       unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
+      
+      // Add the bundle to the manager when the class loading metadata is available
+      bundleManager.addBundle(bundleState);
 
       // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
       unit.addAttachment("org.jboss.deployment.annotation.metadata.complete", Boolean.TRUE);
@@ -149,4 +152,15 @@
       if (factory != null)
          unit.addAttachment(ClassLoaderFactory.class, factory);
    }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, OSGiMetaData deployment)
+   {
+      AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
+      if (bundleState != null)
+      {
+         OSGiBundleManager bundleManager = bundleState.getBundleManager();
+         bundleManager.removeBundle(bundleState);
+      }
+   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -24,6 +24,7 @@
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 
@@ -58,6 +59,8 @@
       // [TODO] look at manifest headers and persistent state for this
       unit.setRequiredStage(DeploymentStages.DESCRIBE);
       
-      bundleManager.addDeployment(unit);
+      // Attach the abstract bundle state
+      AbstractBundleState bundleState = bundleManager.addDeployment(unit);
+      unit.addAttachment(AbstractBundleState.class, bundleState);
    }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/packageadmin/PackageAdminImpl.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -146,7 +146,7 @@
          AbstractDeployedBundleState bundleState = (AbstractDeployedBundleState)absBundleState;
          ClassLoadingMetaData metaData = bundleState.getDeploymentUnit().getAttachment(ClassLoadingMetaData.class);
          if (metaData == null)
-            throw new IllegalStateException("Cannot obtain ClassLoadingMetaData");
+            throw new IllegalStateException("Cannot obtain ClassLoadingMetaData for: " + bundle);
 
          CapabilitiesMetaData capabilities = metaData.getCapabilities();
          for (Capability capability : capabilities.getCapabilities())

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java	2010-02-18 13:57:45 UTC (rev 101112)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java	2010-02-18 14:10:57 UTC (rev 101113)
@@ -44,6 +44,7 @@
  *
  * TODO test security
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class BundleUnitTestCase extends FrameworkTest




More information about the jboss-cvs-commits mailing list