[jboss-osgi-commits] JBoss-OSGI SVN: r90200 - projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Jun 15 12:26:09 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-06-15 12:26:08 -0400 (Mon, 15 Jun 2009)
New Revision: 90200

Modified:
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java
Log:
assertNotUninstalled


Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-06-15 16:24:55 UTC (rev 90199)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java	2009-06-15 16:26:08 UTC (rev 90200)
@@ -44,6 +44,7 @@
 import org.jboss.osgi.spi.testing.OSGiRuntime;
 import org.jboss.osgi.spi.testing.OSGiServiceReference;
 import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.service.log.LogReaderService;
@@ -92,13 +93,13 @@
       registeredBundles.add(bundle);
       return bundle;
    }
-   
+
    public void addCapability(Capability capability) throws BundleException
    {
       // Add dependent capabilies
       for (Capability dependency : capability.getDependencies())
          addCapability(dependency);
-      
+
       // Check if the service provided by the capability exists already
       OSGiServiceReference sref = getServiceReference(capability.getServiceName());
       if (sref == null)
@@ -152,10 +153,10 @@
             }
          }
       }
-      
+
       List<Capability> dependencies = capability.getDependencies();
       Collections.reverse(dependencies);
-      
+
       // Remove dependent capabilities
       for (Capability dependency : dependencies)
          removeCapability(dependency);
@@ -189,14 +190,15 @@
          OSGiBundle bundle = registeredBundles.remove(0);
          try
          {
-            bundle.uninstall();
+            if (bundle.getState() != Bundle.UNINSTALLED)
+               bundle.uninstall();
          }
          catch (BundleException ex)
          {
             log.warn("Cannot uninstall: " + bundle, ex);
          }
       }
-      
+
       // Uninstall the capabilities
       Collections.reverse(capabilities);
       while (capabilities.size() > 0)
@@ -268,7 +270,7 @@
          throw new IllegalStateException("Cannot get manifest from: " + location);
 
       }
-      
+
       Attributes attribs = manifest.getMainAttributes();
       String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
       if (symbolicName == null)

Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java	2009-06-15 16:24:55 UTC (rev 90199)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteBundle.java	2009-06-15 16:26:08 UTC (rev 90200)
@@ -26,6 +26,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.osgi.spi.management.ManagedBundleMBean;
 import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
@@ -42,6 +43,7 @@
    
    private OSGiRuntimeImpl runtime;
    private ManagedBundleMBean bundle;
+   private boolean uninstalled;
    private String location;
 
    public RemoteBundle(OSGiRuntimeImpl runtime, ManagedBundleMBean bundle, String location)
@@ -54,57 +56,66 @@
    @Override
    public int getState()
    {
-      return bundle.getState();
+      return (uninstalled == true ? Bundle.UNINSTALLED : bundle.getState());
    }
 
    @Override
    public String getSymbolicName()
    {
+      assertNotUninstalled();
       return bundle.getSymbolicName();
    }
 
    @Override
    public String getVersion()
    {
+      assertNotUninstalled();
       return getHeaders().get(Constants.BUNDLE_VERSION);
    }
 
    @Override
    public Dictionary<String, String> getHeaders()
    {
+      assertNotUninstalled();
       return bundle.getHeaders();
    }
 
    @Override
    public long getBundleId()
    {
+      assertNotUninstalled();
       return bundle.getBundleId();
    }
 
    @Override
    public String getProperty(String key)
    {
+      assertNotUninstalled();
       return bundle.getProperty(key);
    }
 
    @Override
    public void start() throws BundleException
    {
+      assertNotUninstalled();
       bundle.start();
    }
 
    @Override
    public void stop() throws BundleException
    {
+      assertNotUninstalled();
       bundle.stop();
    }
 
    @Override
    public void uninstall() throws BundleException
    {
+      assertNotUninstalled();
       try
       {
          runtime.undeploy(location);
+         uninstalled = true;
       }
       catch (RuntimeException rte)
       {
@@ -115,4 +126,10 @@
          log.error("Cannot uninstall: " + location);
       }
    }
+
+   private void assertNotUninstalled()
+   {
+      if (uninstalled == true)
+         throw new IllegalStateException("Bundle already uninstalled: " + location);
+   }
 }




More information about the jboss-osgi-commits mailing list