[jboss-osgi-commits] JBoss-OSGI SVN: r98020 - in projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework: util and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Sat Dec 19 11:55:53 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-19 11:55:52 -0500 (Sat, 19 Dec 2009)
New Revision: 98020

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/URLHelper.java
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
Log:
Add support for Bundle.update() from original location

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 14:07:46 UTC (rev 98019)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java	2009-12-19 16:55:52 UTC (rev 98020)
@@ -213,12 +213,16 @@
       return bundles.toArray(new Bundle[bundles.size()]);
    }
 
+   /**
+    * Returns the time when this bundle was last modified. 
+    * A bundle is considered to be modified when it is installed, updated or uninstalled
+    */
    public long getLastModified()
    {
       return lastModified;
    }
 
-   void modified()
+   void updateLastModified()
    {
       lastModified = System.currentTimeMillis();
    }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-19 14:07:46 UTC (rev 98019)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-19 16:55:52 UTC (rev 98020)
@@ -90,6 +90,7 @@
 import org.jboss.osgi.framework.plugins.ResolverPlugin;
 import org.jboss.osgi.framework.plugins.ServicePlugin;
 import org.jboss.osgi.framework.util.NoFilter;
+import org.jboss.osgi.framework.util.URLHelper;
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.util.BundleInfo;
 import org.jboss.virtual.VFS;
@@ -805,13 +806,16 @@
       // If the specified InputStream is null, the Framework must create the InputStream from which to read the updated bundle by interpreting, 
       // in an implementation dependent manner, this bundle's Bundle-UpdateLocation Manifest header, if present, or this bundle's original location.
       URL updateURL = bundleState.getMetaData().getBundleUpdateLocation();
+      if (updateURL == null)
+      {
+         // This updates the bundle from its original location 
+         VirtualFile root = bundleState.getRoot();
+         updateURL = URLHelper.toURL(root);
+      }
       if (in == null)
       {
          try
          {
-            if (updateURL == null)
-               throw new IllegalStateException("Cannot obtain Bundle-UpdateLocation for: " + bundleState);
-
             in = updateURL.openStream();
          }
          catch (IOException ex)
@@ -856,6 +860,7 @@
          dep.setAutoStart(false);
 
          updatedBundleState = installBundle(dep);
+         updatedBundleState.updateLastModified();
       }
       catch (Exception ex)
       {
@@ -911,7 +916,7 @@
          try
          {
             deployerClient.undeploy(unit.getName());
-            bundleState.modified();
+            bundleState.updateLastModified();
          }
          catch (DeploymentException e)
          {
@@ -947,13 +952,8 @@
          unit.addAttachment(OSGiMetaData.class, metaData);
       }
 
-      // The bundle location is not necessarily the bundle root url
-      // The framework is expected to preserve the location passed into installBundle(String)
+      // In case of Bundle.update() the OSGiBundleState should be attached. We add the DeploymentUnit 
       Deployment dep = unit.getAttachment(Deployment.class);
-      String location = (dep != null ? dep.getLocation() : unit.getName());
-
-      // In case of Bundle.update() the OSGiBundleState should be attached
-      // we add the DeploymentUnit 
       OSGiBundleState bundleState = (dep != null ? dep.getAttachment(OSGiBundleState.class) : null);
       if (bundleState != null)
          bundleState.addDeploymentUnit(unit);
@@ -961,7 +961,7 @@
       // Create a new OSGiBundleState and add it to the manager
       if (bundleState == null)
       {
-         bundleState = new OSGiBundleState(location, unit);
+         bundleState = new OSGiBundleState(unit);
          addBundle(bundleState);
       }
       return bundleState;

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 14:07:46 UTC (rev 98019)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2009-12-19 16:55:52 UTC (rev 98020)
@@ -35,6 +35,7 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.plugins.PackageAdminPlugin;
 import org.jboss.virtual.VirtualFile;
@@ -62,6 +63,9 @@
 
    /** The bundle location */
    private String location;
+   
+   /** The bundle root file */
+   private VirtualFile rootFile;
 
    /** The list of deployment units */
    private List<DeploymentUnit> units = new ArrayList<DeploymentUnit>();
@@ -72,20 +76,21 @@
    /**
     * Create a new BundleState.
     * 
-    * @param location The string representation of this bundle's location identifier 
-    * @param osgiMetaData the osgi metadata
     * @param unit the deployment unit
     * @throws IllegalArgumentException for a null parameter
     */
-   public OSGiBundleState(String location, DeploymentUnit unit)
+   public OSGiBundleState(DeploymentUnit unit)
    {
-      if (location == null)
-         throw new IllegalArgumentException("Null bundle location");
       if (unit == null)
          throw new IllegalArgumentException("Null deployment unit");
+      
+      // The bundle location is not necessarily the bundle root url
+      // The framework is expected to preserve the location passed into installBundle(String)
+      Deployment dep = unit.getAttachment(Deployment.class);
+      location = (dep != null ? dep.getLocation() : unit.getName());
+      rootFile = (dep != null ? dep.getRoot() : ((VFSDeploymentUnit)unit).getRoot());
 
-      this.location = location;
-      this.bundleId = bundleIDGenerator.incrementAndGet();
+      bundleId = bundleIDGenerator.incrementAndGet();
       
       addDeploymentUnit(unit);
    }
@@ -103,6 +108,14 @@
       return (OSGiBundleState)bundle;
    }
    
+   /**
+    * Get the root file for this bundle 
+    */
+   public VirtualFile getRoot()
+   {
+      return rootFile;
+   }
+
    @Override
    public OSGiMetaData getMetaData()
    {

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/URLHelper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/URLHelper.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/URLHelper.java	2009-12-19 16:55:52 UTC (rev 98020)
@@ -0,0 +1,74 @@
+/*
+* 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.framework.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A helper for URL convertions that does not throw checked exceptions.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 19-Dec-2009
+ */
+public final class URLHelper
+{
+   // Hide the ctor
+   private URLHelper()
+   {
+   }
+
+   /**
+    * Get a URL from the given string
+    * @throws IllegalArgumentException if the urlstr does not represent a valid URL
+    */
+   public static URL toURL(String urlstr)
+   {
+      try
+      {
+         return new URL(urlstr);
+      }
+      catch (MalformedURLException ex)
+      {
+         throw new IllegalArgumentException("Malformed URL: " + urlstr);
+      }
+   }
+
+   /**
+    * Get a URL from the given virtual file
+    * @throws IllegalArgumentException if the file does not represent a valid URL
+    */
+   public static URL toURL(VirtualFile file)
+   {
+      try
+      {
+         return file.toURL();
+      }
+      catch (Exception ex)
+      {
+         throw new IllegalArgumentException("Cannot convert to URL: " + file, ex);
+      }
+   }
+   
+}



More information about the jboss-osgi-commits mailing list