[jboss-osgi-commits] JBoss-OSGI SVN: r99897 - in projects/jboss-osgi: projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal and 6 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Jan 25 06:42:39 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-25 06:42:38 -0500 (Mon, 25 Jan 2010)
New Revision: 99897

Modified:
   projects/jboss-osgi/projects/bundles/hotdeploy/trunk/pom.xml
   projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
   projects/jboss-osgi/trunk/pom.xml
   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-210] Bundle is only installed but not started in runtime

Modified: projects/jboss-osgi/projects/bundles/hotdeploy/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/hotdeploy/trunk/pom.xml	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/hotdeploy/trunk/pom.xml	2010-01-25 11:42:38 UTC (rev 99897)
@@ -40,8 +40,8 @@
   <!-- Properties -->
   <properties>
     <version.jboss.osgi.common>1.0.3</version.jboss.osgi.common>
-    <version.jboss.osgi.deployment>1.0.0</version.jboss.osgi.deployment>
-    <version.jboss.osgi.spi>1.0.3</version.jboss.osgi.spi>
+    <version.jboss.osgi.deployment>1.0.1-SNAPSHOT</version.jboss.osgi.deployment>
+    <version.jboss.osgi.spi>1.0.4-SNAPSHOT</version.jboss.osgi.spi>
     <version.osgi>4.2.0</version.osgi>
   </properties>
   

Modified: projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -39,6 +39,7 @@
 import org.jboss.osgi.hotdeploy.DeploymentScannerService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.slf4j.Logger;
@@ -167,14 +168,14 @@
             Bundle bundle = getBundle(dep);
             if (bundle == null)
             {
-               deploymentCache.remove(dep.getLocation().toExternalForm());
+               deploymentCache.remove(dep.getLocation());
             }
             else
             {
                int state = bundle.getState();
                if (state == Bundle.INSTALLED || state == Bundle.RESOLVED || state == Bundle.ACTIVE)
                {
-                  deploymentCache.remove(dep.getLocation().toExternalForm());
+                  deploymentCache.remove(dep.getLocation());
                   diff.add(dep);
                }
             }
@@ -248,10 +249,17 @@
             Deployment dep = deploymentCache.get(bundleURL.toExternalForm());
             if (dep == null)
             {
-               // hot-deploy bundles are started automatically
-               dep = deployer.createDeployment(bundleURL);
-               dep.setAutoStart(true);
-
+               try
+               {
+                  // hot-deploy bundles are started automatically
+                  dep = deployer.createDeployment(bundleURL);
+                  dep.setAutoStart(true);
+               }
+               catch (BundleException ex)
+               {
+                  log.error("Cannot create deployment from: " + bundleURL, ex);
+                  continue;
+               }
                deploymentCache.put(bundleURL.toExternalForm(), dep);
             }
             bundles.add(dep);

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/OSGiBundle.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -21,6 +21,7 @@
  */
 package org.jboss.osgi.testing;
 
+import java.io.File;
 import java.net.URL;
 import java.util.Dictionary;
 
@@ -75,6 +76,11 @@
     * Returns the value of the specified property.
     */
    public abstract String getProperty(String key);
+   
+   /**
+    * Creates a File object for a file in the persistent storage area provided for the bundle by the Framework.
+    */
+   public abstract File getDataFile(String filename);
 
    /**
     * Loads the specified class using this bundle's class loader. 

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -21,6 +21,7 @@
  */
 package org.jboss.osgi.testing.internal;
 
+import java.io.File;
 import java.net.URL;
 import java.util.Dictionary;
 
@@ -116,6 +117,12 @@
    }
 
    @Override
+   public File getDataFile(String filename)
+   {
+      return bundle.getBundleContext().getDataFile(filename);
+   }
+
+   @Override
    public OSGiBundle loadClass(String name) throws ClassNotFoundException
    {
       Class<?> clazz = bundle.loadClass(name);
@@ -161,7 +168,6 @@
          
          OSGiRuntimeImpl runtimeImpl = (OSGiRuntimeImpl)getRuntime();
          runtimeImpl.unregisterBundle(this);
-         setUninstalled(true);
       }
       catch (RuntimeException rte)
       {

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiBundleImpl.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -25,6 +25,7 @@
 
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
+import org.osgi.framework.Bundle;
 
 /**
  * An abstract implementation of a {@link OSGiBundle}
@@ -35,7 +36,6 @@
 public abstract class OSGiBundleImpl extends OSGiBundle
 {
    private OSGiRuntimeImpl runtime;
-   private boolean uninstalled;
    
    OSGiBundleImpl(OSGiRuntimeImpl runtime)
    {
@@ -47,19 +47,9 @@
       return runtime;
    }
 
-   boolean isUninstalled()
-   {
-      return uninstalled;
-   }
-
-   void setUninstalled(boolean uninstalled)
-   {
-      this.uninstalled = uninstalled;
-   }
-
    void assertNotUninstalled()
    {
-      if (uninstalled == true)
+      if (getState() == Bundle.UNINSTALLED)
          throw new IllegalStateException("Bundle already uninstalled: " + getLocation());
    }
 }

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -23,6 +23,7 @@
 
 // $Id$
 
+import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -30,6 +31,7 @@
 import java.net.URLStreamHandler;
 import java.util.Dictionary;
 
+import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
 import org.jboss.osgi.spi.management.ManagedBundle;
@@ -60,8 +62,10 @@
 
    private long bundleId;
    private String symbolicName;
+   private ObjectName objectName;
    private Dictionary<String, String> headers;
    private Version version;
+   boolean uninstalled;
 
    public RemoteBundle(OSGiRuntimeImpl runtime, ManagedBundleMBean bundle, BundleInfo info)
    {
@@ -79,6 +83,7 @@
 
       bundleId = bundle.getBundleId();
       symbolicName = bundle.getSymbolicName();
+      objectName = bundle.getObjectName();
       location = bundle.getLocation();
       headers = bundle.getHeaders();
 
@@ -89,7 +94,20 @@
    @Override
    public int getState()
    {
-      return (isUninstalled() ? Bundle.UNINSTALLED : bundle.getState());
+      if (uninstalled == true)
+         return Bundle.UNINSTALLED;
+      
+      boolean isRegistered;
+      try
+      {
+         MBeanServerConnection server = getRuntime().getMBeanServer();
+         isRegistered = server.isRegistered(objectName);
+      }
+      catch (IOException e)
+      {
+         isRegistered = false;
+      }
+      return isRegistered ? bundle.getState() : Bundle.UNINSTALLED;
    }
 
    @Override
@@ -145,6 +163,13 @@
    }
 
    @Override
+   public File getDataFile(String filename)
+   {
+      assertNotUninstalled();
+      return bundle.getDataFile(filename);
+   }
+
+   @Override
    public OSGiBundle loadClass(String name) throws ClassNotFoundException
    {
       assertNotUninstalled();
@@ -176,7 +201,7 @@
          OSGiRuntimeImpl runtimeImpl = (OSGiRuntimeImpl)getRuntime();
          runtimeImpl.undeploy(new URL(location));
          runtimeImpl.unregisterBundle(this);
-         setUninstalled(true);
+         uninstalled = true;
       }
       catch (RuntimeException rte)
       {
@@ -195,7 +220,7 @@
 
       try
       {
-         return sh == null ? new URL(urlstr) : new URL (null, urlstr, sh);
+         return sh == null ? new URL(urlstr) : new URL(null, urlstr, sh);
       }
       catch (MalformedURLException ex)
       {

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -27,6 +27,7 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import java.lang.reflect.UndeclaredThrowableException;
 import java.util.HashMap;
 
 import javax.management.Attribute;
@@ -301,6 +302,8 @@
                result = ((RuntimeMBeanException)result).getTargetException();
             else if (result instanceof RuntimeErrorException)
                result = ((RuntimeErrorException)result).getTargetError();
+            else if (result instanceof UndeclaredThrowableException)
+               result = ((UndeclaredThrowableException)result).getUndeclaredThrowable();
             else
                // can't decode
                break;

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -25,6 +25,7 @@
 
 import static org.jboss.osgi.spi.OSGiConstants.DOMAIN_NAME;
 
+import java.io.File;
 import java.net.URL;
 import java.util.Dictionary;
 import java.util.Enumeration;
@@ -141,6 +142,12 @@
       return getObjectName(providingBundle);
    }
    
+   public File getDataFile(String filename)
+   {
+      BundleContext context = bundle.getBundleContext();
+      return context.getDataFile(filename);
+   }
+
    public void start() throws BundleException
    {
       bundle.start();

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import java.io.File;
 import java.util.Dictionary;
 
 import javax.management.ObjectName;
@@ -103,6 +104,11 @@
    String getResource(String name);
    
    /**
+    * Creates a File object for a file in the persistent storage area provided for the bundle by the Framework.
+    */
+   File getDataFile(String filename);
+
+   /**
     * Starts this bundle with no options
     */
    void start() throws BundleException;

Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml	2010-01-25 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/trunk/pom.xml	2010-01-25 11:42:38 UTC (rev 99897)
@@ -58,7 +58,7 @@
     <version.jboss.osgi.common.core>2.2.13.GA</version.jboss.osgi.common.core>
     <version.jboss.osgi.deployment>1.0.1-SNAPSHOT</version.jboss.osgi.deployment>
     <version.jboss.osgi.framework>1.0.0-SNAPSHOT</version.jboss.osgi.framework>
-    <version.jboss.osgi.hotdeploy>1.0.3</version.jboss.osgi.hotdeploy>
+    <version.jboss.osgi.hotdeploy>1.0.4-SNAPSHOT</version.jboss.osgi.hotdeploy>
     <version.jboss.osgi.husky>1.0.3-SNAPSHOT</version.jboss.osgi.husky>
     <version.jboss.osgi.jaxb>2.1.10.SP3</version.jboss.osgi.jaxb>
     <version.jboss.osgi.jmx>1.0.3-SNAPSHOT</version.jboss.osgi.jmx>

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 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2010-01-25 11:42:38 UTC (rev 99897)
@@ -23,6 +23,8 @@
  [JBOSGI-143] Investigate DynamicImport-Package
  [JBOSGI-151] Cannot resolve circular dependencies
  [JBOSGI-161] Cannot use commons logging
+ [JBOSGI-210] Bundle is only installed but not started in runtime
+ [JBOSGI-214] Cannot repeatedly register service bound to an interface from the system classpath
 
 -->
 

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 11:37:18 UTC (rev 99896)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java	2010-01-25 11:42:38 UTC (rev 99897)
@@ -23,8 +23,14 @@
 
 //$Id: OSGI39TestCase.java 87103 2009-04-09 22:18:31Z thomas.diesler at jboss.com $
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
 import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
@@ -129,4 +135,62 @@
       if (runtime.isRemoteRuntime() == false)
          assertBundleState(Bundle.UNINSTALLED, bundle.getState());
    }
+
+   @Test
+   public void testHotDeploy() throws Exception
+   {
+      if (runtime.isRemoteRuntime() == false)
+         return;
+
+      File inFile = getTestArchiveFile("jbosgi99-allgood.jar");
+
+      // Copy the bundle to the deploy directory
+      String outPath = runtime.getBundle(0).getDataFile("dummy").getAbsolutePath();
+      outPath = outPath.substring(0, outPath.indexOf("data/osgi-store"));
+      File outFile = new File(outPath + "deploy/jbosgi99-allgood.jar");
+      copyfile(inFile, outFile);
+
+      int timeout = 5000;
+      OSGiBundle bundle = null;
+      while (timeout > 0)
+      {
+         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();
+
+      timeout = 5000;
+      while (timeout > 0)
+      {
+         if (bundle.getState() == Bundle.UNINSTALLED)
+            break;
+         
+         Thread.sleep(200);
+         timeout -= 200;
+      }
+      
+      assertBundleState(Bundle.UNINSTALLED, bundle.getState());
+   }
+
+   private void copyfile(File inFile, File outFile) throws IOException
+   {
+      FileInputStream in = new FileInputStream(inFile);
+      FileOutputStream out = new FileOutputStream(outFile);
+
+      int c;
+      while ((c = in.read()) != -1)
+         out.write(c);
+
+      in.close();
+      out.close();
+   }
 }
\ No newline at end of file



More information about the jboss-osgi-commits mailing list