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.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@535670 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 71e6f25..b6b7321 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -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
@@ -2025,6 +2023,21 @@
             {
                 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
         {
diff --git a/framework/src/main/java/org/apache/felix/framework/SystemBundle.java b/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
index 5719640..4884019 100644
--- a/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
+++ b/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
@@ -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
diff --git a/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java b/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java
index 94d74ed..dfb9c7e 100644
--- a/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java
+++ b/framework/src/main/java/org/apache/felix/framework/SystemBundleActivator.java
@@ -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)
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java b/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java
index 608592b..d907dbd 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/BundleRevision.java
@@ -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();
 }
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
index a686feb..52a4a43 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
@@ -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;
-        }
-    }
 }
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java b/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
index c7306af..ced4faf 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
@@ -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.
     //
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java b/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java
index d3ebc81..de060c9 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/SystemBundleArchive.java
@@ -69,11 +69,6 @@
             {
             }
 
-            public String getCachedBundleURL()
-            {
-                return null;
-            }
-
             protected X509Certificate[] getRevisionCertificates()
             {
                 return null;