[jboss-cvs] JBossAS SVN: r96190 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 9 14:22:03 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-09 14:22:02 -0500 (Mon, 09 Nov 2009)
New Revision: 96190

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
Log:
Consistently use framework launch API

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java	2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java	2009-11-09 19:22:02 UTC (rev 96190)
@@ -68,7 +68,7 @@
    {
       super(bundleManager);
    }
-   
+
    public List<Resolvable> getBundles()
    {
       List<Resolvable> values = new ArrayList<Resolvable>(resolverBundleMap.values());
@@ -93,7 +93,7 @@
       }
       return Collections.unmodifiableList(resolvedBundles);
    }
-   
+
    /**
     * Resolve the given list of bundles.
     * 
@@ -109,9 +109,10 @@
 
       // Normalize to OSGiBundleState instances
       List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
-      for (Bundle bundle : bundles)
+      for (Bundle aux : bundles)
       {
-         unresolvedBundles.add(OSGiBundleState.assertBundleState(bundle));
+         if (aux.getBundleId() != 0)
+            unresolvedBundles.add(OSGiBundleState.assertBundleState(aux));
       }
 
       int resolved = 1;
@@ -123,7 +124,7 @@
       {
          allCapabilities.addAll(list);
       }
-      
+
       List<OSGiBundleState> resolvedBundles = new ArrayList<OSGiBundleState>();
       while (resolved > 0 && unresolvedBundles.isEmpty() == false)
       {
@@ -173,9 +174,9 @@
    public Resolvable removeBundle(Bundle bundle)
    {
       OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
-      
+
       bundleCapabilitiesMap.remove(bundleState);
-      
+
       List<BundleRequirement> bundleRequirements = bundleRequirementsMap.remove(bundleState);
       if (bundleRequirements != null)
       {
@@ -184,7 +185,7 @@
             requirement.unwireCapability();
          }
       }
-      
+
       return null;
    }
 
@@ -194,7 +195,7 @@
       BundleCapability match = getMatchingCapability(bundleState, importPackage);
       if (match == null)
          return null;
-      
+
       OSGiBundleState exportingBundle = match.getExportingBundle();
       Resolvable resolverBundle = resolverBundleMap.get(exportingBundle);
       return resolverBundle.getExportPackage(importPackage);
@@ -266,7 +267,7 @@
    {
       // Log the package wiring information
       StringBuffer message = new StringBuffer("Resolved: " + bundle);
-      
+
       // Log the exports
       int nameLengthMax = 0;
       for (BundleCapability capability : bundleCapabilities)
@@ -289,7 +290,7 @@
          for (String line : lines)
             message.append(line);
       }
-      
+
       // Log the imports
       nameLengthMax = 0;
       for (BundleRequirement requirement : bundleRequirements)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java	2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java	2009-11-09 19:22:02 UTC (rev 96190)
@@ -31,9 +31,7 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
 import org.jboss.osgi.spi.util.ConstantsHelper;
@@ -98,16 +96,6 @@
    }
 
    /**
-    * Get DeployerClient from Delegate
-    * 
-    * @return The DeployerClient
-    */
-   protected DeployerClient getDeployerClient()
-   {
-      return getDelegate().getMainDeployer();
-   }
-
-   /**
     * Get BundleManager from Delegate
     * 
     * @return The BundleManager
@@ -178,16 +166,6 @@
       return getDelegate().getDeploymentUnit(bundle);
    }
 
-   /**
-    * Get MainDeployerStructure from Delegate
-    * 
-    * @return MainDeployerStructure
-    */
-   protected MainDeployerStructure getMainDeployerStructure()
-   {
-      return getDelegate().getMainDeployer();
-   }
-
    protected Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
    {
       return getDelegate().assembleBundle(name, new String[] { resources }, packages);

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java	2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java	2009-11-09 19:22:02 UTC (rev 96190)
@@ -21,19 +21,19 @@
 */
 package org.jboss.test.osgi;
 
-import java.lang.reflect.Method;
+// $Id: $
+
 import java.net.URL;
-import java.util.Collection;
 import java.util.Enumeration;
 
 import junit.framework.AssertionFailedError;
 
 import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
 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.launch.OSGiFramework;
+import org.jboss.osgi.spi.util.ServiceLoader;
 import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
 import org.jboss.virtual.AssembledDirectory;
 import org.jboss.virtual.VFS;
@@ -42,134 +42,41 @@
 import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.FrameworkFactory;
 
 /**
  * A OSGiTestDelegate
  * 
  * @author <a href="baileyje at gmail.com">John Bailey</a>
- * @version $Revision: 87848 $
+ * @author Thomas.Diesler at jboss.com
  */
 public class OSGiTestDelegate extends MicrocontainerTestDelegate
 {
-   private MainDeployerImpl mainDeployer;
    private OSGiBundleManager bundleManager;
 
-   static
-   {
-      //FIXME the vfs is not initialising itself properly
-      VFS.init();
-      try
-      {
-         VFS.getRoot(new URL("file:/"));
-      }
-      catch (Exception ignored) {}
-   }
-   
    /**
     * Create a new OSGiTestDelegate.
-    * 
-    * @param clazz
-    * @throws Exception
     */
    public OSGiTestDelegate(Class<?> clazz) throws Exception
    {
       super(clazz);
    }
    
-   /**
-    * Deploys the jboss-osgi-bootstrap.xml bean descriptor to setup OSGi deployers
-    */
-   protected void deploy() throws Exception
-   {
-      URL url = getClass().getResource("/META-INF/jboss-osgi-bootstrap.xml");
-      if (url == null)
-         throw new IllegalStateException("Cannot find: jboss-osgi-bootstrap.xml");
-      deploy(url);
-      try
-      {
-         super.deploy();
-         deployBundles();
-      }
-      catch (Throwable t)
-      {
-         undeploy();
-         if (t instanceof Exception)
-            throw (Exception) t;
-         if (t instanceof Error)
-            throw (Error) t;
-         throw new RuntimeException("Error during deploy", t);
-      }
-   }
-   
-   protected void undeploy()
-   {
-      undeployBundles();
-      super.undeploy();
-   }
-
-   protected void deployBundles() throws Exception
-   {
-      try
-      {
-         Method method = clazz.getMethod("deployBundles", new Class[] { OSGiTestDelegate.class });
-         log.debug("Deploying Bundles...");
-         method.invoke(null, this);
-      }
-      catch (NoSuchMethodException e)
-      {
-         log.debug("No deployBundles() in " + clazz.getName());
-      }
-   }
-
-   protected void undeployBundles() 
-   {
-      OSGiBundleManager bundleManager = getBundleManager();
-      Collection<AbstractBundleState> bundles = bundleManager.getBundles();
-      for (AbstractBundleState bundleState : bundles)
-      {
-         try
-         {
-            if (bundleState.getBundleId() != 0)
-               bundleManager.uninstall(bundleState);
-         }
-         catch (Throwable t)
-         {
-            getLog().warn("Error undeploying bundle: " + bundleState, t);
-         }
-      }
-   }
-   
-   /**
-    * Get the MainDeployer bean from the MC
-    * 
-    * @return MainDeployerImpl
-    */
-   protected MainDeployerImpl getMainDeployer()
-   {
-      if (mainDeployer == null)
-         mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployerImpl.class);
-      return mainDeployer;
-   }
-   
-   /**
-    * Get the BundleManager bean from the MC
-    * 
-    * @return the BundleManager
-    */
    protected OSGiBundleManager getBundleManager()
    {
       if (bundleManager == null)
       {
-         bundleManager = getBean("OSGiBundleManager", ControllerState.INSTALLED, OSGiBundleManager.class);
+         FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+         OSGiFramework framework = (OSGiFramework)factory.newFramework(null);
          try
          {
-            if (bundleManager.isActive() == false)
-               bundleManager.startFramework();
+            framework.start();
          }
          catch (BundleException ex)
          {
-            throw new IllegalStateException("Cannot start bundle manager", ex);
+            throw new IllegalStateException("Cannot start framework", ex);
          }
+         bundleManager = framework.getBundleManager();
       }
       return bundleManager;
    }
@@ -177,7 +84,7 @@
    /**
     * Create a bundle 
     * 
-    * @param root the location of the location to deploy
+    * @param root the location to deploy
     * @param child the child to deploy
     * @return Bundle for the deployment
     * @throws Exception for any error

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java	2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java	2009-11-09 19:22:02 UTC (rev 96190)
@@ -25,9 +25,7 @@
 import java.util.Hashtable;
 
 import org.jboss.test.osgi.OSGiTestCase;
-import org.jboss.test.osgi.OSGiTestDelegate;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
@@ -40,37 +38,24 @@
  */
 public class SystemBundleUnitTestCase extends OSGiTestCase
 {
-   /** The system bundle */
-   private static Bundle systemBundle = null;
-   
    public SystemBundleUnitTestCase(String name)
    {
       super(name);
    }
 
-   public static void deployBundles(OSGiTestDelegate delegate) throws Exception
-   {
-      Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
-      bundle.start();
-      BundleContext context = bundle.getBundleContext();
-      assertNotNull(context);
-      systemBundle = context.getBundle(0);
-      assertNotNull(systemBundle);
-   }
-   
    public void testBundleId() throws Exception
    {
-      assertEquals(0, systemBundle.getBundleId());
+      assertEquals(0, getSystemBundle().getBundleId());
    }
    
    public void testSymbolicName() throws Exception
    {
-      assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, systemBundle.getSymbolicName());
+      assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, getSystemBundle().getSymbolicName());
    }
    
    public void testState() throws Exception
    {
-      assertEquals(Bundle.ACTIVE, systemBundle.getState());
+      assertEquals(Bundle.ACTIVE, getSystemBundle().getState());
    }
    
    public void testStartStop() throws Exception
@@ -87,7 +72,7 @@
    {
       try
       {
-         systemBundle.uninstall();
+         getSystemBundle().uninstall();
          fail("Should not be here!");
       }
       catch (Throwable t)
@@ -106,13 +91,13 @@
       // todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
       // todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
       
-      Dictionary dictionary = systemBundle.getHeaders();
+      Dictionary dictionary = getSystemBundle().getHeaders();
       assertEquals(expected, dictionary);
    }
    
    public void testLocation() throws Exception
    {
-      assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, systemBundle.getLocation());
+      assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, getSystemBundle().getLocation());
    }
    
    public void testGetEntry()




More information about the jboss-cvs-commits mailing list