You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2007/05/07 00:54:10 UTC

svn commit: r535670 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java SystemBundle.java SystemBundleActivator.java cache/BundleRevision.java cache/DirectoryRevision.java cache/JarRevision.java cache/SystemBundleArchive.java

Author: pauls
Date: Sun May  6 15:54:09 2007
New Revision: 535670

URL: http://svn.apache.org/viewvc?view=rev&rev=535670
Log:
Clean-up the extension bundle functionality. This removes a previously introduced hack to get access to the cached bundle jar in order to add it the system classloader. Now, the Bundle.getEntry() method is used to get the root of an extension bundle.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Sun May  6 15:54:09 2007
@@ -106,8 +106,6 @@
     // The secure action used to do privileged calls
     protected SecureAction m_secureAction = new SecureAction();
 
-    private Collection m_trustedCaCerts = null;
-
     /**
      * <p>
      * This method starts the framework instance; instances of the framework
@@ -2024,6 +2022,21 @@
             synchronized (m_installedBundleLock_Priority2)
             {
                 m_installedBundleMap.put(location, bundle);
+            }
+            
+            if (bundle.getInfo().isExtension()) 
+            {
+                BundleImpl systemBundle = (BundleImpl) getBundle(0);
+                acquireBundleLock(systemBundle);
+
+                try
+                {
+                    ((SystemBundle) getBundle(0)).startExtensionBundle(bundle);
+                }
+                finally
+                {
+                    releaseBundleLock(systemBundle);
+                }
             }
         }
         finally

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java Sun May  6 15:54:09 2007
@@ -25,7 +25,6 @@
 import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.security.cert.Certificate;
 import java.util.*;
 
 import org.apache.felix.framework.cache.*;
@@ -36,8 +35,6 @@
 
 class SystemBundle extends BundleImpl implements IModuleDefinition, PrivilegedAction
 {
-    private static final Set m_extensionLocations = new HashSet();
-
     private List m_activatorList = null;
     private SystemBundleActivator m_activator = null;
     private Thread m_shutdownThread = null;
@@ -235,7 +232,7 @@
     {
         if (m_activator == null)
         {
-            m_activator = new SystemBundleActivator(getFelix(), m_activatorList);
+            m_activator = new SystemBundleActivator(m_activatorList);
         }
         return m_activator;
     }
@@ -310,6 +307,29 @@
             _addExtensionBundle(bundle);
         }
     }
+    
+    void startExtensionBundle(BundleImpl bundle) 
+    {
+        String activatorClass = (String)
+        bundle.getInfo().getCurrentHeader().get(
+            FelixConstants.FELIX_EXTENSION_ACTIVATOR);
+        
+        if (activatorClass != null)
+        {
+            try
+            {
+                m_activator.addActivator(((BundleActivator)
+                    getClass().getClassLoader().loadClass(
+                    activatorClass.trim()).newInstance()),
+                    new BundleContextImpl(getFelix(), bundle));
+            }
+            catch (Throwable ex)
+            {
+                getFelix().getLogger().log(Logger.LOG_WARNING,
+                    "Unable to start Felix Extension Activator", ex);
+            }
+        }
+    }
 
     public Object run()
     {
@@ -319,8 +339,6 @@
 
     private void _addExtensionBundle(BundleImpl bundle)
     {
-        BundleArchive archive = bundle.getInfo().getArchive();
-
         SystemBundleArchive systemArchive =
             (SystemBundleArchive) getInfo().getArchive();
 
@@ -346,35 +364,12 @@
 
         try
         {
-            String url = archive.getRevision(
-                archive.getRevisionCount() -1).getCachedBundleURL();
-            if (url != null)
-            {
-                synchronized (getClass().getClassLoader())
-                {
-                    if (!m_extensionLocations.contains(bundle.getSymbolicName()))
-                    {
-                        Method addURL =
-                            URLClassLoader.class.getDeclaredMethod("addURL",
-                            new Class[] {URL.class});
-                        addURL.setAccessible(true);
-                        addURL.invoke(getClass().getClassLoader(),
-                            new Object[] {new URL(url)});
-                        m_extensionLocations.add(bundle.getSymbolicName());
-                    }
-                }
-            }
-            else
-            {
-                getFelix().getLogger().log(Logger.LOG_WARNING,
-                    "Unable to add extension bundle to FrameworkClassLoader - Maybe BundleCache does not support URLs?");
-                throw new UnsupportedOperationException(
-                    "Unable to add extension bundle to FrameworkClassLoader - Maybe BundleCache does not support URLs?");
-            }
-        }
-        catch (UnsupportedOperationException ex)
-        {
-            throw ex;
+            Method addURL =
+                URLClassLoader.class.getDeclaredMethod("addURL",
+                new Class[] {URL.class});
+            addURL.setAccessible(true);
+            addURL.invoke(getClass().getClassLoader(),
+                new Object[] {bundle.getEntry("/")});
         }
         catch (Exception ex)
         {
@@ -384,7 +379,7 @@
                 "Unable to add extension bundle to FrameworkClassLoader - Maybe not an URLClassLoader?");
         }
 
-                ICapability[] temp = new ICapability[m_exports.length + exports.length];
+        ICapability[] temp = new ICapability[m_exports.length + exports.length];
 
         System.arraycopy(m_exports, 0, temp, 0, m_exports.length);
         System.arraycopy(exports, 0, temp, m_exports.length, exports.length);
@@ -394,26 +389,6 @@
         parseAndAddExports(headers);
 
         systemArchive.setManifestHeader(headers);
-
-        String activatorClass = (String)
-            bundle.getInfo().getCurrentHeader().get(
-            FelixConstants.FELIX_EXTENSION_ACTIVATOR);
-
-        if (activatorClass != null)
-        {
-            try
-            {
-                m_activator.addActivator(((BundleActivator)
-                    getClass().getClassLoader().loadClass(
-                    activatorClass.trim()).newInstance()),
-                    new BundleContextImpl(getFelix(), bundle));
-            }
-            catch (Throwable ex)
-            {
-                getFelix().getLogger().log(Logger.LOG_WARNING,
-                    "Unable to start Felix Extension Activator", ex);
-            }
-        }
     }
 
     private class SystemBundleContentLoader implements IContentLoader

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java Sun May  6 15:54:09 2007
@@ -25,20 +25,18 @@
 
 class SystemBundleActivator implements BundleActivator
 {
-    private Felix m_felix = null;
     private List m_activatorList = null;
     private BundleContext m_context = null;
     private Map m_activatorContextMap = null;
 
-    SystemBundleActivator(Felix felix, List activatorList)
+    SystemBundleActivator(List activatorList)
     {
-        this.m_felix = felix;
-        this.m_activatorList = activatorList;
+        m_activatorList = activatorList;
     }
 
     public void start(BundleContext context) throws Exception
     {
-        this.m_context = context;
+        m_context = context;
 
         // Start all activators.
         if (m_activatorList != null)

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java Sun May  6 15:54:09 2007
@@ -169,11 +169,4 @@
      * @throws Exception if any error occurs.
     **/
     public abstract void dispose() throws Exception;
-
-    /**
-     * Returns the url of the cached bundle if possible.
-     *
-     * @return the url of the cached bundle as a string or null if not possible.
-     */
-    public abstract String getCachedBundleURL();
 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java Sun May  6 15:54:09 2007
@@ -183,17 +183,4 @@
         // of the revision directory, which will be automatically deleted
         // by the parent bundle archive.
     }
-
-    public String getCachedBundleURL()
-    {
-        try
-        {
-            return m_refDir.toURL().toString();
-        }
-        catch (MalformedURLException ex)
-        {
-            // This should never happen.
-            return null;
-        }
-    }
 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java Sun May  6 15:54:09 2007
@@ -252,19 +252,6 @@
         // by the parent bundle archive.
     }
 
-    public String getCachedBundleURL()
-    {
-        try
-        {
-            return m_bundleFile.toURL().toString();
-        }
-        catch (MalformedURLException ex)
-        {
-            // This should never happen.
-            return null;
-        }
-    }
-
     //
     // Private methods.
     //

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java?view=diff&rev=535670&r1=535669&r2=535670
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java Sun May  6 15:54:09 2007
@@ -69,11 +69,6 @@
             {
             }
 
-            public String getCachedBundleURL()
-            {
-                return null;
-            }
-
             protected X509Certificate[] getRevisionCertificates()
             {
                 return null;