[jboss-osgi-commits] JBoss-OSGI SVN: r93199 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/bundle and 3 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Sep 4 05:40:06 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-04 05:40:06 -0400 (Fri, 04 Sep 2009)
New Revision: 93199

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/log4j-example.xml
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java
   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/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/plugins/FrameworkEventsPluginImpl.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
Log:
[JBOSGI-148] Autostart bundles when deployed in JBossAS

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.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.spi.metadata.OSGiMetaData;
+
+/**
+ * Change required stage to reset.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleRequiredStageDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+   public BundleRequiredStageDeployer()
+   {
+      super(OSGiMetaData.class);
+      setStage(DeploymentStages.POST_CLASSLOADER);
+      setTopLevelOnly(true);
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
+   {
+      unit.setRequiredStage(BundleResolver.RESET_STAGE);
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, OSGiMetaData deployment)
+   {
+      unit.setRequiredStage(DeploymentStages.INSTALLED);   
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+
+/**
+ * Simple bundle reset deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleResetDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+   private BundleResolver resolver;
+
+   public BundleResetDeployer(BundleResolver resolver)
+   {
+      super(OSGiMetaData.class);
+
+      if (resolver == null)
+         throw new IllegalArgumentException("Null resolver");
+
+      this.resolver = resolver;
+
+      setStage(BundleResolver.RESET_STAGE);
+      setTopLevelOnly(true);
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
+   {
+      resolver.reset(unit);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.dependency.Module;
+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.spi.metadata.OSGiMetaData;
+
+/**
+ * Simple bundle resolve deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleResolveDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+   private BundleResolver resolver;
+
+   public BundleResolveDeployer(BundleResolver resolver)
+   {
+      super(OSGiMetaData.class);
+
+      if (resolver == null)
+         throw new IllegalArgumentException("Null resolver");
+
+      this.resolver = resolver;
+
+      addInput(Module.class);
+      setStage(DeploymentStages.DESCRIBE);
+      setTopLevelOnly(true);
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
+   {
+      resolver.resolve(unit);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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 java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Simple bundle resolve helper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleResolver
+{
+   static final ControllerState DESCRIBED_STATE = new ControllerState(DeploymentStages.DESCRIBE.getName());
+   static final ControllerState CLASSLOADER_STATE = new ControllerState(DeploymentStages.CLASSLOADER.getName());
+
+   static final ControllerState RESET_STATE = new ControllerState("Reset");
+   static final DeploymentStage RESET_STAGE = new DeploymentStage("Reset", "Installed");
+
+   private Set<DeploymentUnit> units = new CopyOnWriteArraySet<DeploymentUnit>();
+
+   public BundleResolver(Controller controller)
+   {
+      controller.addState(RESET_STATE, null);
+   }
+
+   void resolve(DeploymentUnit unit)
+   {
+      run(unit, new Action()
+      {
+         public void resolved(DeploymentUnit unit)
+         {
+            unit.setRequiredStage(DeploymentStages.CLASSLOADER);
+            for (DeploymentUnit unresolved : units)
+            {
+               unresolved.setRequiredStage(DeploymentStages.CLASSLOADER); // try moving
+               ControllerContext context = unresolved.getAttachment(ControllerContext.class);
+               if (context != null)
+                  context.setRequiredState(CLASSLOADER_STATE);
+            }
+         }
+
+         public void unresolved(DeploymentUnit unit)
+         {
+            units.add(unit);
+         }
+      });
+   }
+
+   void reset(DeploymentUnit unit)
+   {
+      units.remove(unit); // remove, as we're clearly resolved
+
+      Set<DeploymentUnit> copy = new HashSet<DeploymentUnit>(units);
+      for (DeploymentUnit unresolved : copy)
+      {
+         run(unresolved, new Action()
+         {
+            public void resolved(DeploymentUnit unit)
+            {
+               units.remove(unit);
+            }
+
+            public void unresolved(DeploymentUnit unit)
+            {
+               unit.setRequiredStage(DeploymentStages.DESCRIBE); // move back
+               ControllerContext context = unit.getAttachment(ControllerContext.class);
+               if (context != null)
+                  context.setRequiredState(DESCRIBED_STATE);
+            }
+         });
+      }
+   }
+
+   protected void run(DeploymentUnit unit, Action action)
+   {
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      if (context != null)
+      {
+         DependencyInfo info = context.getDependencyInfo();
+         Set<DependencyItem> unresolvedDependencies = info.getUnresolvedDependencies(CLASSLOADER_STATE);
+         if (unresolvedDependencies == null || unresolvedDependencies.isEmpty())
+            action.resolved(unit);
+         else
+            action.unresolved(unit);
+      }
+   }
+
+   private interface Action
+   {
+      void resolved(DeploymentUnit unit);
+
+      void unresolved(DeploymentUnit unit);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.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.OSGiBundleState;
+import org.osgi.framework.BundleException;
+
+/**
+ * Simple bundle start/stop deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleStartStopDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
+{
+   public BundleStartStopDeployer()
+   {
+      super(OSGiBundleState.class);
+      setStage(DeploymentStages.CLASSLOADER);
+      setTopLevelOnly(true);
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiBundleState deployment) throws DeploymentException
+   {
+      try
+      {
+         deployment.start();
+      }
+      catch (BundleException e)
+      {
+         throw DeploymentException.rethrowAsDeploymentException("Cannot start bundle.", e);
+      }
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, OSGiBundleState deployment)
+   {
+      try
+      {
+         deployment.stop();
+      }
+      catch (BundleException e)
+      {
+         log.warn("Exception stopping bundle: " + e);
+      }
+   }
+}


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java	2009-09-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -30,16 +30,15 @@
  * OSGiBundleActivatorDeployer.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiBundleActivatorDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
 {
-   /**
-    * Create a new BundleStateDeployer.
-    */
    public OSGiBundleActivatorDeployer()
    {
       super(OSGiBundleState.class);
+      setTopLevelOnly(true);
    }
 
    @Override

Modified: 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	2009-09-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -21,13 +21,25 @@
 */
 package org.jboss.osgi.plugins.deployers.bundle;
 
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.LifecycleCallbackItem;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.main.MainDeployer;
 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.logging.Logger;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
  * OSGiBundleResolverDeployer.
@@ -37,22 +49,120 @@
  */
 public class OSGiBundleResolverDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
 {
-   /**
-    * Create a new BundleStateDeployer.
-    */
+   /** The log */
+   private static final Logger log = Logger.getLogger(OSGiBundleResolverDeployer.class);
+
+   /** The list of unresolved bundles */
+   private List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
+   
    public OSGiBundleResolverDeployer()
    {
       super(OSGiBundleState.class);
+      setStage(DeploymentStages.DESCRIBE);
       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);
+      bundleState.getBundleManager();
+
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      DependencyInfo di = context.getDependencyInfo();
+
+      LifecycleCallbackItem lifecycleCallbackItem = new LifecycleCallback(unit);
+      di.addLifecycleCallback(lifecycleCallbackItem);
    }
+
+   private class LifecycleCallback implements LifecycleCallbackItem
+   {
+      private DeploymentUnit unit;
+      private PackageAdmin packageAdmin;
+      private DeployerClient deployerClient;
+
+      public LifecycleCallback(DeploymentUnit unit)
+      {
+         this.unit = unit;
+
+         OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+         BundleContext sysContext = bundleState.getBundleManager().getSystemContext();
+         ServiceReference sref = sysContext.getServiceReference(PackageAdmin.class.getName());
+         packageAdmin = (PackageAdmin)sysContext.getService(sref);
+
+         deployerClient = unit.getAttachment(MainDeployer.class);
+      }
+
+      public void uninstall(ControllerContext ctx)
+      {
+         OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+         unresolvedBundles.remove(bundleState);
+      }
+
+      public void install(ControllerContext ctx) throws Exception
+      {
+         Runnable runnable = new Runnable()
+         {
+            public void run()
+            {
+               try
+               {
+                  // [TODO] remove this hack and find a way to trigger
+                  // PackageAdmin after the context has been deployed
+                  Thread.sleep(100);
+               }
+               catch (InterruptedException e)
+               {
+                  // ignore
+               }
+
+               OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+
+               // Add the new bundle to the list of unresolved
+               unresolvedBundles.add(0, bundleState);
+               OSGiBundleState[] unresolved = new OSGiBundleState[unresolvedBundles.size()];
+               unresolvedBundles.toArray(unresolved);
+
+               // Try to resolve all unresolved bundles
+               packageAdmin.resolveBundles(unresolved);
+               if (bundleState.getState() != Bundle.RESOLVED)
+                  log.info("Unresolved: " + bundleState);
+                  
+               for (OSGiBundleState aux : unresolved)
+               {
+                  if (aux.getState() == Bundle.RESOLVED)
+                  {
+                     unresolvedBundles.remove(aux);
+                     
+                     try
+                     {
+                        // When resolved progress to INSTALLED
+                        String name = aux.getDeploymentUnit().getName();
+                        deployerClient.change(name, DeploymentStages.INSTALLED);
+                     }
+                     catch (DeploymentException ex)
+                     {
+                        log.error(ex);
+                     }
+                  }
+               }
+            }
+         };
+         new Thread(runnable).start();
+      }
+
+      public ControllerState getWhenRequired()
+      {
+         return new ControllerState(getStage().getName());
+      }
+
+      public ControllerState getDependentState()
+      {
+         return null;
+      }
+
+      public Object getBean()
+      {
+         return null;
+      }
+   }
 }

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-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -21,6 +21,7 @@
 */
 package org.jboss.osgi.plugins.deployers.bundle;
 
+import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
@@ -78,6 +79,10 @@
       
       OSGiBundleState bundleState = bundleManager.addDeployment(unit);
       unit.addAttachment(OSGiBundleState.class, bundleState);
+      
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      if (context == null)
+         throw new IllegalStateException("Cannot obtain ControllerContext");
    }
 
    @Override

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-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -40,8 +40,11 @@
 import java.util.jar.Manifest;
 import java.util.jar.Attributes.Name;
 
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
@@ -63,6 +66,7 @@
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -554,6 +558,16 @@
    }
 
    /**
+    * Get the system bundle context
+    * 
+    * @return the system bundle context
+    */
+   public BundleContext getSystemContext()
+   {
+      return systemBundle.getBundleContext();
+   }
+   
+   /**
     * Get a deployment
     * 
     * @param id the id of the bundle
@@ -594,18 +608,26 @@
       if (state == Bundle.RESOLVED || state == Bundle.ACTIVE)
          return true;
       
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      
+      ControllerState requiredState = context.getRequiredState();
+      DeploymentStage requiredStage = unit.getRequiredStage();
+      
       try
       {
-         String name = bundleState.getDeploymentUnit().getName();
-         deployerClient.change(name, DeploymentStages.CLASSLOADER);
-         deployerClient.checkComplete(name);
+         deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
+         deployerClient.checkComplete(unit.getName());
          bundleState.changeState(Bundle.RESOLVED);
          return true;
       }
-      catch (DeploymentException e)
+      catch (DeploymentException ex)
       {
+         unit.setRequiredStage(requiredStage);
+         context.setRequiredState(requiredState);
+         
          if (errorOnFail)
-            throw new IllegalStateException("Error resolving bundle: " + bundleState, e);
+            throw new IllegalStateException("Error resolving bundle: " + bundleState, ex);
          
          return false;
       }

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-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -226,6 +226,13 @@
    {
       synchronized (bundleListeners)
       {
+         // Expose the wrapper not the state itself
+         bundle = assertBundle(bundle);
+         BundleEvent event = new BundleEvent(type, bundle);
+         String typeName = ConstantsHelper.bundleEvent(event.getType());
+
+         log.info("Bundle " + typeName + ": " + bundle);
+         
          // Nobody is interested
          if (bundleListeners.isEmpty())
             return;
@@ -234,13 +241,6 @@
          if (getBundleManager().isActive() == false)
             return;
 
-         // Expose the wrapper not the state itself
-         bundle = assertBundle(bundle);
-         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())
          {
@@ -253,7 +253,7 @@
                }
                catch (Throwable t)
                {
-                  log.warn("Error while firing bundle event: " + typeName + " for bundle " + bundle, t);
+                  log.warn("Error while firing " + typeName + " for bundle " + bundle, t);
                }
             }
          }
@@ -272,7 +272,7 @@
                   }
                   catch (Throwable t)
                   {
-                     log.warn("Error while firing bundle event: " + typeName + " for bundle " + this, t);
+                     log.warn("Error while firing " + typeName + " for bundle " + this, t);
                   }
                }
             }
@@ -284,6 +284,13 @@
    {
       synchronized (frameworkListeners)
       {
+         // Expose the wrapper not the state itself
+         bundle = assertBundle(bundle);
+         FrameworkEvent event = new FrameworkEvent(type, bundle, throwable);
+         String typeName = ConstantsHelper.frameworkEvent(event.getType());
+
+         log.info("Framwork " + typeName);
+         
          // Nobody is interested
          if (frameworkListeners.isEmpty())
             return;
@@ -292,13 +299,6 @@
          if (getBundleManager().isActive() == false)
             return;
 
-         // Expose the wrapper not the state itself
-         bundle = assertBundle(bundle);
-         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())
          {
@@ -310,7 +310,7 @@
                }
                catch (Throwable t)
                {
-                  log.warn("Error while firing framework event: " + typeName + " for bundle " + bundle, t);
+                  log.warn("Error while firing " + typeName + " for framework", t);
                }
             }
          }
@@ -321,6 +321,13 @@
    {
       synchronized (serviceListeners)
       {
+         // 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 " + typeName + ": " + service);
+         
          // Nobody is interested
          if (serviceListeners.isEmpty())
             return;
@@ -329,16 +336,6 @@
          if (getBundleManager().isActive() == false)
             return;
 
-         if (service == null)
-            throw new IllegalArgumentException("No serviceReference");
-
-         // 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())
          {
@@ -355,7 +352,7 @@
                }
                catch (Throwable t)
                {
-                  log.warn("Error while firing service event: " + typeName + " for service " + service, t);
+                  log.warn("Error while firing " + typeName + " for service " + service, t);
                }
             }
          }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java	2009-09-04 09:32:11 UTC (rev 93198)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java	2009-09-04 09:40:06 UTC (rev 93199)
@@ -210,6 +210,7 @@
          return capability.getName();
       }
 
+      @SuppressWarnings("deprecation")
       public String getSpecificationVersion()
       {
          throw new NotImplementedException();

Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/log4j-example.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/log4j-example.xml	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/log4j-example.xml	2009-09-04 09:40:06 UTC (rev 93199)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <appender name="FILE" class="org.apache.log4j.FileAppender">
+    <param name="File" value="${log4j.output.dir}/test.log"/>
+    <param name="Append" value="false"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+    </layout>
+  </appender>
+  
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out" />
+    <param name="Threshold" value="INFO" />
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n" />
+    </layout>
+  </appender>
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+
+  <!-- Show jboss deployer traces  
+  <category name="org.jboss.deployer">
+    <priority value="TRACE" />
+  </category>
+  -->
+
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <!--appender-ref ref="CONSOLE"/-->
+    <appender-ref ref="FILE"/>
+  </root>
+
+</log4j:configuration>


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/log4j-example.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the jboss-osgi-commits mailing list