[jboss-cvs] JBossAS SVN: r95025 - in projects/jboss-osgi/trunk: reactor/deployment/src/main/java/org/jboss/osgi/deployment and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 16 06:40:49 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-16 06:40:49 -0400 (Fri, 16 Oct 2009)
New Revision: 95025

Added:
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeployment.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeploymentFactory.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeployerService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentRegistryService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentScannerService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployerServiceDelegate.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
Modified:
   projects/jboss-osgi/trunk/pom.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployersActivator.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java
   projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
[JBOSGI-183] Initial implementation of OSGi Deployers
Move deployment stuff from common to deployement project


Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml	2009-10-16 10:37:53 UTC (rev 95024)
+++ projects/jboss-osgi/trunk/pom.xml	2009-10-16 10:40:49 UTC (rev 95025)
@@ -54,6 +54,7 @@
     <version.jboss.osgi.blueprint>1.0.0.Alpha3</version.jboss.osgi.blueprint>
     <version.jboss.osgi.common>1.0.3-SNAPSHOT</version.jboss.osgi.common>
     <version.jboss.osgi.common.core>2.2.13.GA</version.jboss.osgi.common.core>
+    <version.jboss.osgi.deployment>1.0.0-SNAPSHOT</version.jboss.osgi.deployment>
     <version.jboss.osgi.framework>1.0.0.Alpha2</version.jboss.osgi.framework>
     <version.jboss.osgi.hotdeploy>1.0.3-SNAPSHOT</version.jboss.osgi.hotdeploy>
     <version.jboss.osgi.husky>1.0.1</version.jboss.osgi.husky>
@@ -109,6 +110,11 @@
       </dependency>
       <dependency>
         <groupId>org.jboss.osgi.bundles</groupId>
+        <artifactId>jboss-osgi-deployment</artifactId>
+        <version>${version.jboss.osgi.deployment}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.osgi.bundles</groupId>
         <artifactId>jboss-osgi-common-core</artifactId>
         <version>${version.jboss.osgi.common.core}</version>
       </dependency>

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeployment.java (from rev 95006, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleDeployment.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeployment.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeployment.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment;
+
+import java.io.Serializable;
+import java.net.URL;
+
+//$Id$
+
+/**
+ * An abstraction of a bundle deployment
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class BundleDeployment implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private URL location;
+   private String symbolicName;
+   private String version;
+   private int startLevel;
+   private boolean autoStart;
+   private Object metadata;
+
+   public BundleDeployment(URL location, String symbolicName, String version)
+   {
+      if (location == null)
+         throw new IllegalArgumentException("Location cannot be null");
+      if (symbolicName == null)
+         throw new IllegalArgumentException("Symbolic name cannot be null");
+      
+      if (version == null)
+         version = "0.0.0";
+      
+      this.symbolicName = symbolicName;
+      this.location = location;
+      this.version = version;
+   }
+
+   /**
+    * Get the bundle location
+    */
+   public URL getLocation()
+   {
+      return location;
+   }
+
+   /**
+    * Get the bundle symbolic name
+    */
+   public String getSymbolicName()
+   {
+      return symbolicName;
+   }
+
+   /**
+    * Get the bundle version
+    */
+   public String getVersion()
+   {
+      return version;
+   }
+
+   /**
+    * Get the start level associated with this deployment
+    */
+   public int getStartLevel()
+   {
+      return startLevel;
+   }
+
+   /**
+    * Set the start level associated with this deployment
+    */
+   public void setStartLevel(int startLevel)
+   {
+      this.startLevel = startLevel;
+   }
+
+   /**
+    * Get the autostart flag associated with this deployment
+    */
+   public boolean isAutoStart()
+   {
+      return autoStart;
+   }
+
+   /**
+    * Set the autostart flag associated with this deployment
+    */
+   public void setAutoStart(boolean autoStart)
+   {
+      this.autoStart = autoStart;
+   }
+
+   /**
+    * Get extra meta data associated with this deployment
+    */
+   public Object getMetadata()
+   {
+      return metadata;
+   }
+
+   /**
+    * Set extra meta data associated with this deployment
+    */
+   public void setMetadata(Object metadata)
+   {
+      this.metadata = metadata;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (!(obj instanceof BundleDeployment))
+         return false;
+      
+      BundleDeployment other = (BundleDeployment)obj;
+      return symbolicName.equals(other.symbolicName) && version.equals(other.version);
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return toString().hashCode();
+   }
+
+   @Override
+   public String toString()
+   {
+      return "[" + symbolicName + "-" + version + ",url=" + location + "]";
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeploymentFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeploymentFactory.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeploymentFactory.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment;
+
+//$Id$
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.deployment.BundleDeployment;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * A factory for bundle deployments.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2009
+ */
+public abstract class BundleDeploymentFactory
+{
+   public static BundleDeployment createBundleDeployment(String location) throws BundleException
+   {
+      // Try location as URL
+      URL url = null;
+      try
+      {
+         url = new URL(location);
+      }
+      catch (MalformedURLException ex)
+      {
+         // ignore
+      }
+
+      // Try location as File
+      if (url == null)
+      {
+         try
+         {
+            File file = new File(location);
+            if (file.exists())
+               url = file.toURI().toURL();
+         }
+         catch (MalformedURLException e)
+         {
+            // ignore
+         }
+      }
+      
+      if (url == null)
+         throw new IllegalArgumentException("Invalid bundle location: " + location);
+
+      return createBundleDeployment(url);
+   }
+
+   public static BundleDeployment createBundleDeployment(URL url) throws BundleException
+   {
+      Manifest manifest;
+      try
+      {
+         JarFile jarFile = new JarFile(url.getPath());
+         manifest = jarFile.getManifest();
+         jarFile.close();
+      }
+      catch (IOException ex)
+      {
+         throw new BundleException("Cannot get manifest from: " + url);
+
+      }
+
+      Attributes attribs = manifest.getMainAttributes();
+      String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
+      if (symbolicName == null)
+         throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
+
+      String version = attribs.getValue(Constants.BUNDLE_VERSION);
+      return new BundleDeployment(url, symbolicName, version);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/BundleDeploymentFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeployerService.java (from rev 95006, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeployerService.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeployerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeployerService.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment;
+
+//$Id$
+
+import java.net.URL;
+
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.BundleException;
+
+/**
+ * A Service that can be used to deploy/undeploy bundles or archives to/from the runtime.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public interface DeployerService
+{
+   /**
+    * The object name under which this is registered: 'jboss.osgi:service=DeployerService'
+    */
+   ObjectName MBEAN_DEPLOYER_SERVICE = ObjectNameFactory.create("jboss.osgi:service=DeployerService");
+
+   /**
+    * Deploy an array of bundles
+    */
+   void deploy(BundleDeployment[] bundleDeps) throws BundleException;
+
+   /**
+    * Undeploy an array of bundles
+    */
+   void undeploy(BundleDeployment[] bundleDeps) throws BundleException;
+
+   /**
+    * Deploy bundle from URL
+    */
+   void deploy(URL url) throws BundleException;
+
+   /**
+    * Undeploy bundle from URL.
+    * 
+    * Note, due to the dynamic nature of OSGi services it is 
+    * possible that a {@link DeployerService} is asked to undeploy 
+    * a bundle URL which it did not deploy itself.
+    * 
+    * In this case this method should return false, so that  
+    * another {@link DeployerService} can be tried.
+    * 
+    * @return true if this service could undeploy the bundle
+    */
+   boolean undeploy(URL url) throws BundleException;
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentRegistryService.java (from rev 95006, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentRegistryService.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentRegistryService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentRegistryService.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment;
+
+//$Id: DeployerService.java 90894 2009-07-07 11:58:40Z thomas.diesler at jboss.com $
+
+import java.net.URL;
+
+import org.osgi.framework.Version;
+
+/**
+ * A Service to register/unregister bundle deployments.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2009
+ */
+public interface DeploymentRegistryService
+{
+   /**
+    * Create a bundle deployment from the given bundle URL
+    * @return null, if this service does not maintain the bundle deployment
+    */
+   BundleDeployment getBundleDeployment(URL url);
+   
+   /**
+    * Get the bundle deployment for the given bundle symbolicName and version
+    * @return null, if this service does not maintain the bundle deployment
+    */
+   BundleDeployment getBundleDeployment(String symbolicName, Version version);
+
+   /**
+    * Register a bundle deployment
+    */
+   void registerBundleDeployment(BundleDeployment dep);
+   
+   /**
+    * Unregister a bundle deployment
+    */
+   void unregisterBundleDeployment(BundleDeployment dep);
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentScannerService.java (from rev 95006, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentScannerService.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentScannerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/DeploymentScannerService.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment;
+
+//$Id$
+
+import java.net.URL;
+
+
+/**
+ * A service that scans a directory location for new/removed bundles.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public interface DeploymentScannerService
+{
+   /**
+    * The property that names the scan location: org.jboss.osgi.hotdeploy.scandir
+    */
+   String PROPERTY_SCAN_LOCATION = "org.jboss.osgi.hotdeploy.scandir";
+   
+   /**
+    * The property to defines the scan interval: org.jboss.osgi.hotdeploy.interval
+    */
+   String PROPERTY_SCAN_INTERVAL = "org.jboss.osgi.hotdeploy.interval";
+   
+   /**
+    * Get the scan location URL.
+    *  
+    * This is can be specified by setting the {@link #PROPERTY_SCAN_LOCATION} property. 
+    */
+   URL getScanLocation();
+   
+   /**
+    * The number of scans since the service started 
+    */
+   long getScanCount();
+   
+   /**
+    * The number of milliseconds between scans
+    * Defaults to 2000ms 
+    */
+   long getScanInterval();
+   
+   /**
+    * The timestamp of the last change
+    */
+   long getLastChange();
+   
+   /**
+    * Run a directory scan
+    */
+   void scan();
+   
+   /**
+    * Returns the array of bundles currently known to the deployemtn scanner. 
+    */
+   BundleDeployment[] getBundleDeployments();
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployerServiceDelegate.java (from rev 95022, projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployerServiceDelegate.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployerServiceDelegate.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment.internal;
+
+//$Id$
+
+import java.net.URL;
+
+import org.jboss.osgi.deployment.BundleDeployment;
+import org.jboss.osgi.deployment.DeployerService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A {@link DeployerService} that delegates to the service that is tracked by the given {@link DeployerServiceTracker}
+ * 
+ * This delegate is registered as an MBean
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeployerServiceDelegate implements DeployerService
+{
+   private BundleContext context;
+
+   public DeployerServiceDelegate(BundleContext context)
+   {
+      this.context = context;
+   }
+
+   public void deploy(BundleDeployment[] bundles) throws BundleException
+   {
+      DeployerService service = getDefaultDeployerService();
+      service.deploy(bundles);
+   }
+
+   public void deploy(URL url) throws BundleException
+   {
+      DeployerService service = getDefaultDeployerService();
+      service.deploy(url);
+   }
+
+   public void undeploy(BundleDeployment[] bundles) throws BundleException
+   {
+      for (BundleDeployment info : bundles)
+         undeploy(info.getLocation());
+   }
+
+   public boolean undeploy(URL url) throws BundleException
+   {
+      boolean undeployed = false;
+      
+      DeployerService service = getMicrocontainerDeployerService();
+      if (service != null)
+         undeployed = service.undeploy(url);
+      
+      if (undeployed == false)
+      {
+         service = getSystemDeployerService();
+         undeployed = service.undeploy(url);
+      }
+      
+      return undeployed;
+   }
+
+   private DeployerService getDefaultDeployerService()
+   {
+      // First try the MC provider
+      DeployerService service = getMicrocontainerDeployerService();
+
+      // Fall back to the system provider
+      if (service == null)
+         service = getSystemDeployerService();
+
+      return service;
+   }
+
+   private DeployerService getMicrocontainerDeployerService()
+   {
+      DeployerService service = null;
+      try
+      {
+         String filter = "(provider=microcontainer)";
+         String serviceName = DeployerService.class.getName();
+         ServiceReference[] srefs = context.getServiceReferences(serviceName, filter);
+         if (srefs != null)
+            service = (DeployerService)context.getService(srefs[0]);
+      }
+      catch (InvalidSyntaxException ex)
+      {
+         throw new IllegalArgumentException(ex);
+      }
+      return service;
+   }
+
+   private DeployerService getSystemDeployerService()
+   {
+      DeployerService service = null;
+      try
+      {
+         String filter = "(provider=system)";
+         String serviceName = DeployerService.class.getName();
+         ServiceReference[] srefs = context.getServiceReferences(serviceName, filter);
+         if (srefs != null)
+            service = (DeployerService)context.getService(srefs[0]);
+      }
+      catch (InvalidSyntaxException ex)
+      {
+         throw new IllegalArgumentException(ex);
+      }
+      
+      if (service == null)
+         throw new IllegalStateException("Cannot obtain system DeployerService");
+      return service;
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployersActivator.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployersActivator.java	2009-10-16 10:37:53 UTC (rev 95024)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeployersActivator.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -23,12 +23,25 @@
 
 //$Id$
 
+import java.util.Properties;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.StandardMBean;
+
 import org.jboss.osgi.deployment.Deployer;
+import org.jboss.osgi.deployment.DeployerService;
 import org.jboss.osgi.deployment.DeployersService;
 import org.jboss.osgi.deployment.Deployment;
+import org.jboss.osgi.deployment.DeploymentRegistryService;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -39,8 +52,17 @@
  */
 public class DeployersActivator implements BundleActivator
 {
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(DeployersActivator.class);
+   
    public void start(BundleContext context) throws Exception
    {
+      // Register the system SystemDeployerService and DeployerServiceDelegate
+      DeployerService deployer = registerDeployerServices(context);
+      
+      // Track the MBeanServer and register the DeployerServiceDelegate
+      trackMBeanServer(context, deployer);
+
       DeployersService service = new DeployersService()
       {
          public void removeDeployer(Deployer deployer)
@@ -63,7 +85,80 @@
 
    public void stop(BundleContext context) throws Exception
    {
-      // TODO Auto-generated method stub
+      ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+      if (sref != null)
+      {
+         MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
+         unregisterDeployerServiceMBean(mbeanServer);
+      }
+   }
+
+   protected DeployerService registerDeployerServices(BundleContext context)
+   {
+      // Register the DeploymentRegistryService
+      DeploymentRegistryService registry = new DeploymentRegistryServiceImpl(context);
+      context.registerService(DeploymentRegistryService.class.getName(), registry, null);
       
+      // Register the SystemDeployerService
+      Properties props = new Properties();
+      props.put("provider", "system");
+      SystemDeployerService systemDeployer = new SystemDeployerService(context);
+      context.registerService(DeployerService.class.getName(), systemDeployer, props);
+      
+      // Register the DeployerServiceDelegate
+      props = new Properties();
+      props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+      DeployerService deployerDelegate = new DeployerServiceDelegate(context);
+      context.registerService(DeployerService.class.getName(), deployerDelegate, props);
+      return deployerDelegate;
    }
+
+   private void trackMBeanServer(BundleContext context, final DeployerService deployer)
+   {
+      ServiceTracker jmxTracker = new ServiceTracker(context, MBeanServer.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference reference)
+         {
+            MBeanServer mbeanServer = (MBeanServer)super.addingService(reference);
+            registerDeployerServiceMBean(mbeanServer, deployer);
+            return mbeanServer;
+         }
+
+         @Override
+         public void removedService(ServiceReference reference, Object service)
+         {
+            MBeanServer mbeanServer = (MBeanServer)service;
+            unregisterDeployerServiceMBean(mbeanServer);
+            super.removedService(reference, service);
+         }
+      };
+      jmxTracker.open();
+   }
+
+   private void registerDeployerServiceMBean(MBeanServer mbeanServer, DeployerService delegate)
+   {
+      try
+      {
+         StandardMBean mbean = new StandardMBean(delegate, DeployerService.class);
+         mbeanServer.registerMBean(mbean, DeployerService.MBEAN_DEPLOYER_SERVICE);
+      }
+      catch (JMException ex)
+      {
+         throw new IllegalStateException("Cannot register DeployerService MBean", ex);
+      }
+   }
+
+   private void unregisterDeployerServiceMBean(MBeanServer mbeanServer)
+   {
+      try
+      {
+         if (mbeanServer.isRegistered(DeployerService.MBEAN_DEPLOYER_SERVICE))
+            mbeanServer.unregisterMBean(DeployerService.MBEAN_DEPLOYER_SERVICE);
+      }
+      catch (JMException ex)
+      {
+         log.error("Cannot unregister DeployerService MBean", ex);
+      }
+   }
 }
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java (from rev 95022, projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeploymentRegistryServiceImpl.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment.internal;
+
+//$Id: SystemDeployerService.java 90894 2009-07-07 11:58:40Z thomas.diesler at jboss.com $
+
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.osgi.deployment.BundleDeployment;
+import org.jboss.osgi.deployment.DeployerService;
+import org.jboss.osgi.deployment.DeploymentRegistryService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+
+/**
+ * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeploymentRegistryServiceImpl implements DeploymentRegistryService
+{
+   private Set<BundleDeployment> deployments = new HashSet<BundleDeployment>();
+
+   public DeploymentRegistryServiceImpl(BundleContext context)
+   {
+   }
+
+   public void registerBundleDeployment(BundleDeployment dep)
+   {
+      deployments.add(dep);
+   }
+
+   public void unregisterBundleDeployment(BundleDeployment dep)
+   {
+      deployments.remove(dep);
+   }
+   
+   public BundleDeployment getBundleDeployment(String symbolicName, Version version)
+   {
+      if (symbolicName == null)
+         throw new IllegalArgumentException("Cannot obtain bundle deployment for null symbolic name");
+
+      BundleDeployment dep = null;
+      for (BundleDeployment auxDep : deployments)
+      {
+         String auxName = auxDep.getSymbolicName();
+         String auxVersion = auxDep.getVersion();
+         if (symbolicName.equals(auxName) && version.equals(auxVersion))
+         {
+            dep = auxDep;
+            break;
+         }
+      }
+
+      return dep;
+   }
+
+   public BundleDeployment getBundleDeployment(URL url)
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Cannot obtain bundle deployment for: null");
+
+      BundleDeployment dep = null;
+      for (BundleDeployment auxDep : deployments)
+      {
+         if (url.equals(auxDep.getLocation()))
+         {
+            dep = auxDep;
+            break;
+         }
+      }
+
+      return dep;
+   }
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java (from rev 95022, projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/SystemDeployerService.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.deployment.internal;
+
+//$Id$
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.jboss.osgi.deployment.BundleDeployment;
+import org.jboss.osgi.deployment.BundleDeploymentFactory;
+import org.jboss.osgi.deployment.DeployerService;
+import org.jboss.osgi.deployment.DeploymentRegistryService;
+import org.jboss.osgi.spi.logging.ExportedPackageHelper;
+import org.jboss.osgi.spi.management.ManagedBundleService;
+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.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class SystemDeployerService implements DeployerService
+{
+   // Provide logging
+   private Logger log = LoggerFactory.getLogger(SystemDeployerService.class);
+   
+   private BundleContext context;
+   private ServiceTracker registryTracker;
+   private ServiceTracker startLevelTracker;
+
+   public SystemDeployerService(BundleContext context)
+   {
+      this.context = context;
+   }
+
+   public void deploy(BundleDeployment[] depArr) throws BundleException
+   {
+      DeploymentRegistryService registry = getDeploymentRegistry();
+
+      List<Bundle> resolvableBundles = new ArrayList<Bundle>();
+      Map<BundleDeployment, Bundle> bundleMap = new HashMap<BundleDeployment, Bundle>();
+      
+      for (BundleDeployment dep : depArr)
+      {
+         try
+         {
+            String location = dep.getLocation().toExternalForm();
+            Bundle bundle = context.installBundle(location);
+            log.info("Installed: " + bundle);
+
+            registerManagedBundle(bundle);
+            
+            bundleMap.put(dep, bundle);
+            if (dep.isAutoStart())
+               resolvableBundles.add(bundle);
+
+            registry.registerBundleDeployment(dep);
+         }
+         catch (BundleException ex)
+         {
+            log.error( "Cannot install bundle: " + dep, ex);
+         }
+      }
+
+      // Resolve the installed bundles through the PackageAdmin
+      ServiceReference packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
+      if (packageAdminRef != null && resolvableBundles.isEmpty() == false)
+      {
+         PackageAdmin packageAdmin = (PackageAdmin)context.getService(packageAdminRef);
+         Bundle[] resolvableBundleArr = new Bundle[resolvableBundles.size()];
+         resolvableBundles.toArray(resolvableBundleArr);
+         packageAdmin.resolveBundles(resolvableBundleArr);
+      }
+      
+      // Start the installed bundles
+      for (Entry<BundleDeployment, Bundle> entry : bundleMap.entrySet())
+      {
+         BundleDeployment dep = entry.getKey();
+         Bundle bundle = entry.getValue();
+
+         StartLevel startLevel = getStartLevel();
+         if (dep.getStartLevel() > 0)
+         {
+            startLevel.setBundleStartLevel(bundle, dep.getStartLevel());
+         }
+
+         if (dep.isAutoStart())
+         {
+            int state = bundle.getState();
+            if (state == Bundle.RESOLVED || packageAdminRef == null)
+            {
+               try
+               {
+                  log.debug( "Start: " + bundle);
+
+                  // Added support for Bundle.START_ACTIVATION_POLICY on start
+                  // http://issues.apache.org/jira/browse/FELIX-1317
+                  // bundle.start(Bundle.START_ACTIVATION_POLICY);
+
+                  bundle.start();
+
+                  log.info("Started: " + bundle);
+                  ExportedPackageHelper packageHelper = new ExportedPackageHelper(context);
+                  packageHelper.logExportedPackages(bundle);
+               }
+               catch (BundleException ex)
+               {
+                  log.error( "Cannot start bundle: " + bundle, ex);
+               }
+            }
+         }
+      }
+   }
+
+   public void undeploy(BundleDeployment[] depArr) throws BundleException
+   {
+      DeploymentRegistryService registry = getDeploymentRegistry();
+
+      for (BundleDeployment dep : depArr)
+      {
+         Bundle bundle = getBundle(dep);
+         if (bundle != null)
+         {
+            registry.unregisterBundleDeployment(dep);
+
+            unregisterManagedBundle(bundle);
+            bundle.uninstall();
+            log.info("Uninstalled: " + bundle);
+         }
+         else
+         {
+            log.warn( "Cannot obtain bundle for: " + dep);
+         }
+      }
+   }
+
+   public void deploy(URL url) throws BundleException
+   {
+      BundleDeployment dep = BundleDeploymentFactory.createBundleDeployment(url);
+      deploy(new BundleDeployment[] { dep });
+   }
+
+   public boolean undeploy(URL url) throws BundleException
+   {
+      DeploymentRegistryService registry = getDeploymentRegistry();
+      BundleDeployment dep = registry.getBundleDeployment(url);
+      if (dep != null)
+      {
+         undeploy(new BundleDeployment[] { dep });
+         return true;
+      }
+      else
+      {
+         log.warn( "Cannot find deployment for: " + url);
+         return false;
+      }
+   }
+
+   private Bundle getBundle(BundleDeployment dep)
+   {
+      String symbolicName = dep.getSymbolicName();
+      Version version = Version.parseVersion(dep.getVersion());
+
+      Bundle bundle = null;
+      for (Bundle aux : context.getBundles())
+      {
+         if (aux.getSymbolicName().equals(symbolicName))
+         {
+            Version auxVersion = aux.getVersion();
+            if (version.equals(auxVersion))
+            {
+               bundle = aux;
+               break;
+            }
+         }
+      }
+      return bundle;
+   }
+
+   private void registerManagedBundle(Bundle bundle)
+   {
+      ServiceReference sref = context.getServiceReference(ManagedBundleService.class.getName());
+      if (sref != null)
+      {
+         ManagedBundleService service = (ManagedBundleService)context.getService(sref);
+         service.register(bundle);
+      }
+      else
+      {
+         log.debug( "No ManagedBundleService. Cannot register managed bundle: " + bundle);
+      }
+   }
+
+   private void unregisterManagedBundle(Bundle bundle)
+   {
+      ServiceReference sref = context.getServiceReference(ManagedBundleService.class.getName());
+      if (sref != null)
+      {
+         ManagedBundleService service = (ManagedBundleService)context.getService(sref);
+         service.unregister(bundle);
+      }
+      else
+      {
+         log.debug( "No ManagedBundleService. Cannot unregister managed bundle: " + bundle);
+      }
+   }
+
+   private DeploymentRegistryService getDeploymentRegistry()
+   {
+      if (registryTracker == null)
+      {
+         registryTracker = new ServiceTracker(context, DeploymentRegistryService.class.getName(), null);
+         registryTracker.open();
+      }
+      return (DeploymentRegistryService)registryTracker.getService();
+   }
+
+   private StartLevel getStartLevel()
+   {
+      if (startLevelTracker == null)
+      {
+         startLevelTracker = new ServiceTracker(context, StartLevel.class.getName(), null);
+         startLevelTracker.open();
+      }
+      return (StartLevel)startLevelTracker.getService();
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java	2009-10-16 10:37:53 UTC (rev 95024)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/service/microcontainer/MicrocontainerServiceTestCase.java	2009-10-16 10:40:49 UTC (rev 95025)
@@ -23,9 +23,9 @@
 
 //$Id$
 
+import static org.jboss.osgi.deployment.DeployerService.MBEAN_DEPLOYER_SERVICE;
 import static org.jboss.osgi.spi.management.ManagedFrameworkMBean.MBEAN_MANAGED_FRAMEWORK;
 import static org.jboss.osgi.spi.management.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
-import static org.jboss.osgi.spi.service.DeployerService.MBEAN_DEPLOYER_SERVICE;
 import static org.jboss.test.osgi.service.microcontainer.bundleB.SomeBeanMBean.MBEAN_NAME;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -36,6 +36,7 @@
 
 import javax.management.ObjectName;
 
+import org.jboss.osgi.deployment.DeployerService;
 import org.jboss.osgi.jbossxb.XMLBindingCapability;
 import org.jboss.osgi.jmx.JMXCapability;
 import org.jboss.osgi.jndi.JNDICapability;
@@ -43,7 +44,6 @@
 import org.jboss.osgi.spi.management.MBeanProxy;
 import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
 import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
-import org.jboss.osgi.spi.service.DeployerService;
 import org.jboss.osgi.spi.service.MicrocontainerService;
 import org.jboss.osgi.spi.testing.OSGiRuntime;
 import org.jboss.osgi.spi.testing.OSGiTest;

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2009-10-16 10:37:53 UTC (rev 95024)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2009-10-16 10:40:49 UTC (rev 95025)
@@ -115,6 +115,11 @@
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
+      <artifactId>jboss-osgi-deployment</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-husky</artifactId>
       <scope>provided</scope>
     </dependency>




More information about the jboss-cvs-commits mailing list