[jboss-cvs] JBossAS SVN: r93134 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins: facade/bundle and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 2 12:31:14 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-02 12:31:13 -0400 (Wed, 02 Sep 2009)
New Revision: 93134

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManagerLifecycle.java
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
Log:
#3 jbossas integration (wip)

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.deployers.bundle;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+
+/**
+ * OSGiBundleResolverDeployer.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleResolverDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
+{
+   /**
+    * Create a new BundleStateDeployer.
+    */
+   public OSGiBundleResolverDeployer()
+   {
+      super(OSGiBundleState.class);
+      setTopLevelOnly(true);
+      addInput(ClassLoadingMetaData.class);
+      setStage(DeploymentStages.POST_PARSE);
+   }
+
+   @Override
+   public void deploy(DeploymentUnit unit, OSGiBundleState bundleState) throws DeploymentException
+   {
+      unit.setRequiredStage(DeploymentStages.INSTALLED);
+      OSGiBundleManager bundleManager = bundleState.getBundleManager();
+      bundleManager.resolve(bundleState, false);
+   }
+}

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java	2009-09-02 15:41:55 UTC (rev 93133)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -22,11 +22,13 @@
 package org.jboss.osgi.plugins.deployers.bundle;
 
 import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
 
 /**
  * OSGiBundleStateDeployer.<p>
@@ -41,6 +43,7 @@
 {
    /** The bundle manager */
    private OSGiBundleManager bundleManager;
+   private DeploymentStage requiredStage;
    
    /**
     * Create a new BundleStateDeployer.
@@ -54,15 +57,26 @@
          throw new IllegalArgumentException("Null bundle manager");
       
       this.bundleManager = bundleManager;
+      this.requiredStage = DeploymentStages.DESCRIBE;
 
+      setInput(OSGiMetaData.class);
       setOutput(OSGiBundleState.class);
       setStage(DeploymentStages.POST_PARSE);
       setTopLevelOnly(true);
    }
+   
+   public void setAutoInstall(boolean autoInstall)
+   {
+      if (autoInstall == true)
+         requiredStage = DeploymentStages.INSTALLED;
+   }
 
    @Override
    protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
    {
+      // [TODO] look at manifest headers and persistent state for this
+      unit.setRequiredStage(requiredStage);
+      
       OSGiBundleState bundleState = bundleManager.addDeployment(unit);
       unit.addAttachment(OSGiBundleState.class, bundleState);
    }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-02 15:41:55 UTC (rev 93133)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -447,23 +447,8 @@
 
       OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
       if (osgiMetaData == null)
-      {
-         Manifest manifest = unit.getAttachment(Manifest.class);
-         // [TODO] we need a mechanism to construct an OSGiMetaData from an easier factory
-         if (manifest == null)
-            manifest = new Manifest();
-         // [TODO] populate some bundle information
-         Attributes attributes = manifest.getMainAttributes();
-         String name = generateName(unit);
-         attributes.put(new Name(Constants.BUNDLE_NAME), unit.getName());
-         attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), name);
-         osgiMetaData = new AbstractOSGiMetaData(manifest);
-      }
-      else
-      {
-         // [TODO] look at manifest headers and persistent state for this
-         unit.setRequiredStage(DeploymentStages.DESCRIBE);
-      }
+         throw new IllegalStateException("Cannot obtain OSGi metadata");
+      
       OSGiBundleState bundleState = new OSGiBundleState(osgiMetaData, unit);
       addBundle(bundleState);
       return bundleState;

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManagerLifecycle.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManagerLifecycle.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManagerLifecycle.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.facade.bundle;
+
+// $Id: $
+
+import org.osgi.framework.BundleException;
+
+/**
+ * A bean that starts/stops the bundle manager.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleManagerLifecycle
+{
+   private OSGiBundleManager bundleManager;
+
+   public OSGiBundleManagerLifecycle(OSGiBundleManager bundleManager)
+   {
+      this.bundleManager = bundleManager;
+   }
+   
+   public void start() throws BundleException
+   {
+      bundleManager.startFramework();
+   }
+   
+   public void stop() throws BundleException
+   {
+      bundleManager.stopFramework();
+   }
+   
+}

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java	2009-09-02 15:41:55 UTC (rev 93133)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -27,12 +27,8 @@
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
 import org.jboss.osgi.spi.metadata.OSGiMetaData;
 import org.jboss.virtual.VirtualFile;
@@ -52,7 +48,7 @@
 {
    /** The log */
    private static final Logger log = Logger.getLogger(OSGiBundleState.class);
-   
+
    /** Used to generate a unique id */
    private static final AtomicLong bundleIDGenerator = new AtomicLong();
 
@@ -296,33 +292,25 @@
       // Bundle extenders catch the STARTING event and might expect a valid context
       createBundleContext();
       changeState(STARTING);
-      
+
       try
       {
          OSGiMetaData metaData = getOSGiMetaData();
-         if (metaData != null)
+         if (metaData == null)
+            throw new IllegalStateException("Cannot obtain OSGi meta data");
+         
+         // Do we have a bundle activator
+         String bundleActivatorClassName = metaData.getBundleActivator();
+         if (bundleActivatorClassName != null)
          {
-            // Do we have a bundle activator
-            String bundleActivatorClassName = metaData.getBundleActivator();
-            if (bundleActivatorClassName != null)
-            {
-               ClassLoader classLoader = getDeploymentUnit().getClassLoader();
+            Object result = loadClass(bundleActivatorClassName).newInstance();
+            if (result instanceof BundleActivator == false)
+               throw new BundleException(bundleActivatorClassName + " is not an implementation of " + BundleActivator.class.getName());
+            
+            BundleActivator bundleActivator = (BundleActivator)result;
+            unit.addAttachment(BundleActivator.class, bundleActivator);
 
-               DeploymentControllerContext deploymentControllerContext = getDeploymentUnit().getAttachment(ControllerContext.class.getName(),
-                     DeploymentControllerContext.class);
-               if (deploymentControllerContext == null)
-                  throw new BundleException("No deployment controller context: " + getCanonicalName());
-
-               KernelController controller = (KernelController)deploymentControllerContext.getController();
-               BeanInfo beanInfo = controller.getKernel().getConfig().getBeanInfo(bundleActivatorClassName, classLoader);
-               Object result = beanInfo.newInstance();
-               if (result instanceof BundleActivator == false)
-                  throw new BundleException(bundleActivatorClassName + " is not an implementation of " + BundleActivator.class.getName());
-               BundleActivator bundleActivator = (BundleActivator)result;
-               getDeploymentUnit().addAttachment(BundleActivator.class, bundleActivator);
-
-               bundleActivator.start(getBundleContext());
-            }
+            bundleActivator.start(getBundleContext());
          }
 
          if (getState() != STARTING)

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java	2009-09-02 15:41:55 UTC (rev 93133)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -23,6 +23,8 @@
 
 import java.util.List;
 
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
 import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.classloading.spi.metadata.RequirementsMetaData;
@@ -47,17 +49,30 @@
  */
 public class OSGiBundleClassLoadingDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
 {
+   private ClassLoaderSystem classLoaderSystem;
+   
    /**
     * Create a new OSGiBundleClassLoadingDeployer.
     */
    public OSGiBundleClassLoadingDeployer()
    {
       super(OSGiMetaData.class);
-      setTopLevelOnly(true);
+      addInput(OSGiBundleState.class);
       setOutput(ClassLoadingMetaData.class);
       setStage(DeploymentStages.POST_PARSE);
+      setTopLevelOnly(true);
    }
 
+   public void setClassLoaderSystem(ClassLoaderSystem classLoaderSystem)
+   {
+      this.classLoaderSystem = classLoaderSystem;
+      for (String name : classLoaderSystem.getDomainNames())
+      {
+         ClassLoaderDomain domain = classLoaderSystem.getDomain(name);
+         System.out.println(domain.toLongString());
+      }
+   }
+
    @Override
    public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
    {
@@ -74,6 +89,12 @@
       classLoadingMetaData.setName(deployment.getBundleSymbolicName());
       classLoadingMetaData.setVersion(deployment.getBundleVersion());
 
+      if (classLoaderSystem != null)
+      {
+         ClassLoaderDomain defaultDomain = classLoaderSystem.getDefaultDomain();
+         classLoadingMetaData.setParentDomain(defaultDomain.getName());
+      }
+
       CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
       RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
       

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java	2009-09-02 15:41:55 UTC (rev 93133)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java	2009-09-02 16:31:13 UTC (rev 93134)
@@ -239,6 +239,8 @@
          BundleEvent event = new BundleEvent(type, bundle);
          String typeName = ConstantsHelper.bundleEvent(event.getType());
 
+         log.info("Bundle event: " + typeName + " for bundle " + bundle);
+         
          // Synchronous listeners first
          for (Entry<Bundle, List<BundleListener>> entry : bundleListeners.entrySet())
          {
@@ -295,6 +297,8 @@
          FrameworkEvent event = new FrameworkEvent(type, bundle, throwable);
          String typeName = ConstantsHelper.frameworkEvent(event.getType());
 
+         log.info("Framwork event: " + typeName + " for bundle " + bundle);
+         
          // Call the listeners
          for (Entry<Bundle, List<FrameworkListener>> entry : frameworkListeners.entrySet())
          {
@@ -330,10 +334,11 @@
 
          // Expose the wrapper not the state itself
          bundle = assertBundle(bundle);
-
          ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
          String typeName = ConstantsHelper.serviceEvent(event.getType());
 
+         log.info("Service event: " + typeName + " for " + service);
+         
          // Call the listeners
          for (Entry<Bundle, List<ServiceListenerRegistration>> entry : serviceListeners.entrySet())
          {




More information about the jboss-cvs-commits mailing list