[jboss-cvs] JBossAS SVN: r85162 - in projects/jboss-osgi/trunk: runtime/deployer/src/main/resources and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 3 08:08:22 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-03-03 08:08:22 -0500 (Tue, 03 Mar 2009)
New Revision: 85162

Modified:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrapProvider.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerBootstrapProvider.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
   projects/jboss-osgi/trunk/testsuite/pom.xml
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java
   projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-beans.xml
   projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-bootstrap-beans.xml
Log:
[JBOSGI-38] Use PackageAdmin to resolve bundles

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -21,11 +21,18 @@
  */
 package org.jboss.osgi.deployer;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
  * This is the Bundle start/stop Deployer
@@ -34,22 +41,61 @@
  */
 public class BundleStartStopDeployer extends AbstractSimpleRealDeployer<Bundle>
 {
+   private BundleContext systemContext;
+   private PackageAdmin packageAdmin; 
+   private List<Bundle> unresolvedBundles = new ArrayList<Bundle>();
+   
    public BundleStartStopDeployer()
    {
       super(Bundle.class);
    }
 
+   public void setSystemContext(BundleContext systemContext)
+   {
+      this.systemContext = systemContext;
+   }
+
    public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
    {
-      try
+      if (packageAdmin == null)
       {
-         bundle.start();
-         log.info("Started: " + bundle.getSymbolicName() + ",state=" + bundle.getState());
+         ServiceReference sref = systemContext.getServiceReference(PackageAdmin.class.getName());
+         packageAdmin = (PackageAdmin)systemContext.getService(sref);
+         if (packageAdmin == null)
+            throw new IllegalStateException("Cannot obtain PackageAdmin service");
       }
-      catch (BundleException e)
+      
+      // Always add the bundle as unresolved
+      unresolvedBundles.add(bundle);
+      
+      Bundle[] bundleArr = new Bundle[unresolvedBundles.size()];
+      unresolvedBundles.toArray(bundleArr);
+      
+      // Try to resolve the bundles
+      packageAdmin.resolveBundles(bundleArr);
+      
+      Iterator<Bundle> it = unresolvedBundles.iterator();
+      while(it.hasNext())
       {
-         throw DeploymentException.rethrowAsDeploymentException("Exception starting bundle", e);
+         Bundle auxBundle = it.next();
+         int state = auxBundle.getState();
+         if (Bundle.RESOLVED == state)
+         {
+            it.remove();
+            try
+            {
+               auxBundle.start();
+               log.info("Started: " + auxBundle.getSymbolicName() + ",state=" + auxBundle.getState());
+            }
+            catch (BundleException e)
+            {
+               throw DeploymentException.rethrowAsDeploymentException("Exception starting bundle", e);
+            }
+         }
       }
+      
+      if (unresolvedBundles.size() > 0)
+         log.info("Unresolved: " + unresolvedBundles);
    }
 
    @Override

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -43,7 +43,7 @@
  */
 public class OSGiDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
 {
-   private BundleContext bundleContext;
+   private BundleContext systemContext;
    private List<URI> skipBundles;
 
    public OSGiDeployer()
@@ -53,9 +53,9 @@
       setStage(DeploymentStages.POST_PARSE);
    }
 
-   public void setBundleContext(BundleContext bundleContext)
+   public void setSystemContext(BundleContext bundleContext)
    {
-      this.bundleContext = bundleContext;
+      this.systemContext = bundleContext;
    }
 
    public void setSkipBundles(List<URI> skipBundles)
@@ -65,7 +65,7 @@
 
    public void start()
    {
-      if (bundleContext == null)
+      if (systemContext == null)
          throw new IllegalArgumentException("No system bundle context.");
 
       // TODO - add VDF bundle listener
@@ -86,7 +86,7 @@
       {
          if (skipBundles != null && skipBundles.contains(bundleUri) == false)
          {
-            Bundle bundle = bundleContext.installBundle(bundleUri.toString());
+            Bundle bundle = systemContext.installBundle(bundleUri.toString());
             unit.addAttachment(Bundle.class, bundle);
             
             log.info("Installed: " + bundle.getSymbolicName() + ",state=" + bundle.getState());

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-03-03 13:08:22 UTC (rev 85162)
@@ -68,17 +68,19 @@
 
   <!-- The OSGi Meta Data Deployer -->
   <bean name="jboss.osgi:service=MetaDataDeployer" class="org.jboss.osgi.deployer.OSGiMetaDataDeployer" />
-
+  
   <!-- The OSGi Deployer -->
   <bean name="jboss.osgi:service=Deployer" class="org.jboss.osgi.deployer.OSGiDeployer">
-    <property name="bundleContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
+    <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
     <property name="skipBundles"><inject bean="jboss.osgi:service=Framework" property="autoInstall" /></property>
   </bean>
 
-  <!-- The Bundle Deployer -->
-  <bean name="jboss.osgi:service=BundleDeployer" class="org.jboss.osgi.deployer.BundleClassLoaderDependencyDeployer"/>
+  <!-- The Bundle Class Loader Deployer -->
+  <bean name="jboss.osgi:service=BundleClassLoaderDeployer" class="org.jboss.osgi.deployer.BundleClassLoaderDependencyDeployer"/>
 
-  <!-- The Bundle start/stop Deployer -->
-  <bean name="jboss.osgi:service=BundleStartStopDeployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer"/>
+  <!-- The Bundle Start/Stop Deployer -->
+  <bean name="jboss.osgi:service=BundleStartStopDeployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer">
+    <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
+  </bean>
 
 </deployment>
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrapProvider.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrapProvider.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrapProvider.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -62,17 +62,22 @@
    OSGiFramework getFramework(String name);
 
    /*
+    * Configure this provider with the default configuration
+    */
+   void configure();
+
+   /*
     * Configure this provider from the given URL
     */
    void configure(URL urlConfig);
 
    /*
-    * Configure this provider from the resource
+    * Configure this provider from a given resource
     */
    void configure(String resourceConfig);
 
    /*
-    * Configure this provider from the resource
+    * Configure this provider from a given input stream
     */
    void configure(InputStream streamConfig);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerBootstrapProvider.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerBootstrapProvider.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerBootstrapProvider.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -62,6 +62,11 @@
       return framework;
    }
 
+   public void configure()
+   {
+      configure(DEFAULT_FRAMEWORK_BEANS);
+   }
+
    public void configure(InputStream streamConfig)
    {
       throw new NotImplementedException("Cannot bootstrap JBossMC from InputStream");

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -66,9 +66,9 @@
       return bootProvider;
    }
 
-   protected void setBootstrapProvider(OSGiBootstrapProvider configProvider)
+   protected void setBootstrapProvider(OSGiBootstrapProvider bootProvider)
    {
-      this.bootProvider = configProvider;
+      this.bootProvider = bootProvider;
    }
 
    @Override

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2009-03-03 13:08:22 UTC (rev 85162)
@@ -53,6 +53,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <scope>test</scope>

Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java	2009-03-03 13:08:22 UTC (rev 85162)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.osgi.spi.junit.IntegrationTest;
 
 /**
@@ -40,6 +41,14 @@
  */
 public class OSGI38DeployerTestCase extends IntegrationTest
 {
+   @Override
+   protected OSGiBootstrapProvider getBootstrapProvider()
+   {
+      OSGiBootstrapProvider bootProvider = super.getBootstrapProvider();
+      bootProvider.configure();
+      return bootProvider;
+   }
+
    /*
     * Install/Start the common bundle
     */
@@ -54,6 +63,11 @@
     */
    public void testInstallXBeforeB() throws Exception
    {
+      deploy("jbosgi38-bundleX.jar");
+      deploy("jbosgi38-bundleB.jar");
+      
+      undeploy("jbosgi38-bundleB.jar");
+      undeploy("jbosgi38-bundleX.jar");
    }
 
    /*
@@ -61,6 +75,13 @@
     */
    public void testInstallBBeforeA() throws Exception
    {
+      deploy("jbosgi38-bundleX.jar");
+      deploy("jbosgi38-bundleB.jar");
+      deploy("jbosgi38-bundleA.jar");
+      
+      undeploy("jbosgi38-bundleA.jar");
+      undeploy("jbosgi38-bundleB.jar");
+      undeploy("jbosgi38-bundleX.jar");
    }
 
    /*
@@ -68,6 +89,11 @@
     */
    public void testInstallBBeforeX() throws Exception
    {
+      deploy("jbosgi38-bundleB.jar");
+      deploy("jbosgi38-bundleX.jar");
+      
+      undeploy("jbosgi38-bundleX.jar");
+      undeploy("jbosgi38-bundleB.jar");
    }
 
    /*
@@ -75,5 +101,12 @@
     */
    public void testInstallABeforeB() throws Exception
    {
+      deploy("jbosgi38-bundleA.jar");
+      deploy("jbosgi38-bundleB.jar");
+      deploy("jbosgi38-bundleX.jar");
+      
+      undeploy("jbosgi38-bundleX.jar");
+      undeploy("jbosgi38-bundleB.jar");
+      undeploy("jbosgi38-bundleA.jar");
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-beans.xml	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-beans.xml	2009-03-03 13:08:22 UTC (rev 85162)
@@ -19,10 +19,21 @@
   </property>
  </bean>
 
+  <!-- The OSGi Meta Data Deployer -->
+  <bean name="jboss.osgi:service=MetaDataDeployer" class="org.jboss.osgi.deployer.OSGiMetaDataDeployer" />
+  
   <!-- The OSGi Deployer -->
   <bean name="jboss.osgi:service=Deployer" class="org.jboss.osgi.deployer.OSGiDeployer">
-    <property name="bundleContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
+    <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
     <property name="skipBundles"><inject bean="jboss.osgi:service=Framework" property="autoInstall" /></property>
   </bean>
 
+  <!-- The Bundle Class Loader Deployer -->
+  <bean name="jboss.osgi:service=BundleClassLoaderDeployer" class="org.jboss.osgi.deployer.BundleClassLoaderDependencyDeployer"/>
+
+  <!-- The Bundle Start/Stop Deployer -->
+  <bean name="jboss.osgi:service=BundleStartStopDeployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer">
+    <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
+  </bean>
+  
 </deployment>

Modified: projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-bootstrap-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-bootstrap-beans.xml	2009-03-03 13:00:41 UTC (rev 85161)
+++ projects/jboss-osgi/trunk/testsuite/src/test/resources/jboss-osgi-bootstrap-beans.xml	2009-03-03 13:08:22 UTC (rev 85162)
@@ -108,9 +108,6 @@
       <property name="system"><inject bean="ClassLoaderSystem"/></property>
    </bean>
 
-  <!-- The OSGi Meta Data Deployer -->
-  <bean name="jboss.osgi:service=MetaDataDeployer" class="org.jboss.osgi.deployer.OSGiMetaDataDeployer" />
-
   <!-- VDFBundleListener 
   <bean name="VDFBundleListener" class="org.jboss.osgi.deployer.helpers.VDFBundleListener">
     <constructor>
@@ -129,11 +126,4 @@
   </bean>
   -->
 
-  <!-- The Bundle Deployer -->
-  <bean name="jboss.osgi:service=BundleDeployer" class="org.jboss.osgi.deployer.BundleClassLoaderDependencyDeployer"/>
-
-  <!-- The Bundle start/stop Deployer - ->
-  <bean name="jboss.osgi:service=BundleStartStopDeployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer"/>
-  -->
-  
 </deployment>




More information about the jboss-cvs-commits mailing list