felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r1650249 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: ./ util/
Date Thu, 08 Jan 2015 11:03:41 GMT
Author: pauls
Date: Thu Jan  8 11:03:40 2015
New Revision: 1650249

URL: http://svn.apache.org/r1650249
Log:
Support Framework Extension Bundle Activators and make the security part of the OSGi 6 CT
tests pass (FELIX-4579,FELIX-4583).

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
Thu Jan  8 11:03:40 2015
@@ -529,6 +529,14 @@ class BundleContextImpl implements Felix
     public <S> ServiceObjects<S> getServiceObjects(final ServiceReference<S>
ref)
     {
     	checkValidity();
+
+        Object sm = System.getSecurityManager();
+
+        if (sm != null)
+        {
+           ((SecurityManager) sm).checkPermission(new ServicePermission(ref, ServicePermission.GET));
+        }
+
         ServiceRegistrationImpl reg =
                 ((ServiceRegistrationImpl.ServiceReferenceImpl) ref).getRegistration();
         if ( reg.isValid() )
@@ -546,7 +554,7 @@ class BundleContextImpl implements Felix
         private final ServiceReference<S> m_ref;
 
         private final List<S> srvObjects = new ArrayList<S>();
-        
+
         public ServiceObjectsImpl(final ServiceReference<S> ref)
         {
             this.m_ref = ref;
@@ -572,21 +580,21 @@ class BundleContextImpl implements Felix
                 }
 
                 srvObj = m_felix.getService(m_bundle, m_ref, true);
-            } 
-            else 
+            }
+            else
             {
             	// getService handles singleton and bundle scope
             	srvObj = BundleContextImpl.this.getService(m_ref);
             }
-            
+
             if ( srvObj != null )
             {
             	synchronized ( srvObjects )
             	{
             		srvObjects.add(srvObj);
             	}
-            } 
-            
+            }
+
             return srvObj;
         }
 
@@ -595,22 +603,22 @@ class BundleContextImpl implements Felix
         	if ( srvObj != null )
         	{
                 // check if this object was returned by this service objects
-                synchronized ( srvObjects ) 
+                synchronized ( srvObjects )
                 {
 	                boolean found = false;
 	                int i = 0;
-	                while ( !found && i < srvObjects.size() ) 
+	                while ( !found && i < srvObjects.size() )
 	                {
 	                	found = srvObjects.get(i) == srvObj;
 	                	i++;
 	                }
-	                if ( !found ) 
+	                if ( !found )
 	                {
-	                	throw new IllegalArgumentException();	                	
+	                	throw new IllegalArgumentException();
 	                }
 	                srvObjects.remove(i-1);
                 }
-        		
+
         	}
             // special handling for prototype scope
             if ( m_ref.getProperty(Constants.SERVICE_SCOPE) == Constants.SCOPE_PROTOTYPE
)
@@ -618,7 +626,7 @@ class BundleContextImpl implements Felix
                 checkValidity();
 
                 // Unget the specified service.
-                if ( !m_felix.ungetService(m_bundle, m_ref, srvObj) ) 
+                if ( !m_felix.ungetService(m_bundle, m_ref, srvObj) )
                 {
                 	throw new IllegalArgumentException();
                 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
Thu Jan  8 11:03:40 2015
@@ -33,6 +33,8 @@ import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.security.CodeSource;
 import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
 import java.security.ProtectionDomain;
 import java.security.cert.Certificate;
 import java.util.ArrayList;
@@ -44,6 +46,7 @@ import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 import org.apache.felix.framework.cache.Content;
 import org.apache.felix.framework.cache.JarContent;
+import org.osgi.framework.PackagePermission;
 
 import org.osgi.framework.wiring.BundleRevision;
 
@@ -372,6 +375,7 @@ public class BundleProtectionDomain exte
     private final int m_hashCode;
     private final String m_toString;
     private final WeakReference m_revision;
+    private volatile PermissionCollection m_woven;
 
     BundleProtectionDomain(Felix felix, BundleImpl bundle, Object certificates)
         throws MalformedURLException
@@ -412,6 +416,20 @@ public class BundleProtectionDomain exte
             felix.impliesBundlePermission(this, permission, true) : false;
     }
 
+    boolean impliesWoven(Permission permission)
+    {
+        return m_woven != null && m_woven.implies(permission);
+    }
+
+    synchronized void addWoven(String s)
+    {
+        if (m_woven == null)
+        {
+            m_woven = new Permissions();
+        }
+        m_woven.add(new PackagePermission(s, PackagePermission.IMPORT));
+    }
+
     BundleImpl getBundle()
     {
         return (BundleImpl) m_bundle.get();

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Thu
Jan  8 11:03:40 2015
@@ -2075,23 +2075,23 @@ public class BundleWiringImpl implements
                     // as a race condition, doing any necessary clean up in
                     // the error handling.
                     Felix felix = ((BundleImpl) m_wiring.m_revision.getBundle()).getFramework();
-                    
+
                     Set<ServiceReference<WeavingHook>> hooks =
                         felix.getHooks(WeavingHook.class);
-                    
-                    Set<ServiceReference<WovenClassListener>> wovenClassListeners
= 
+
+                    Set<ServiceReference<WovenClassListener>> wovenClassListeners
=
                         felix.getHooks(WovenClassListener.class);
-                    
+
                     WovenClassImpl wci = null;
                     if (!hooks.isEmpty())
                     {
                         // Create woven class to be used for hooks.
                         wci = new WovenClassImpl(name, m_wiring, bytes);
-                        try 
+                        try
                         {
                             transformClass(felix, wci, hooks, wovenClassListeners,
                                     name, bytes);
-                        } 
+                        }
                         catch (Error e)
                         {
                             // Mark the woven class as incomplete.
@@ -2129,12 +2129,12 @@ public class BundleWiringImpl implements
                         }
                     }
 
-                    try 
+                    try
                     {
                         clazz = defineClass(felix, wovenClassListeners, wci, name,
                                 clazz, bytes, content, pkgName, lock);
-                    } 
-                    catch (ClassFormatError e) 
+                    }
+                    catch (ClassFormatError e)
                     {
                         if(wci != null)
                         {
@@ -2182,7 +2182,7 @@ public class BundleWiringImpl implements
                 Set<ServiceReference<WovenClassListener>> wovenClassListeners,
                 WovenClassImpl wci, String name, Class clazz, byte[] bytes,
                 Content content, String pkgName, Object lock)
-                        throws ClassFormatError 
+                        throws ClassFormatError
         {
 
             try
@@ -2385,7 +2385,7 @@ public class BundleWiringImpl implements
                 Set<ServiceReference<WeavingHook>> hooks,
                 Set<ServiceReference<WovenClassListener>> wovenClassListeners,
                 String name, byte[] bytes) throws Error {
-      
+
             // Loop through hooks in service ranking order.
             for (ServiceReference<WeavingHook> sr : hooks)
             {
@@ -2430,7 +2430,7 @@ public class BundleWiringImpl implements
             wci.setState(WovenClass.TRANSFORMED);
             callWovenClassListeners(felix, wovenClassListeners, wci);
         }
-        
+
         protected void callWovenClassListeners(Felix felix, Set<ServiceReference<WovenClassListener>>
wovenClassListeners, WovenClass wovenClass)
         {
             if(wovenClassListeners != null)
@@ -2438,15 +2438,15 @@ public class BundleWiringImpl implements
                 for(ServiceReference<WovenClassListener> currentWovenClassListenerRef
: wovenClassListeners)
                 {
                     WovenClassListener currentWovenClassListner = felix.getService(felix,
currentWovenClassListenerRef, false);
-                    try 
+                    try
                     {
                         BundleRevisionImpl.getSecureAction().invokeWovenClassListener(currentWovenClassListner,
wovenClass);
-                    } 
-                    catch (Exception e) 
+                    }
+                    catch (Exception e)
                     {
                         m_logger.log(Logger.LOG_ERROR, "Woven Class Listner failed.", e);
-                    } 
-                    finally 
+                    }
+                    finally
                     {
                         felix.ungetService(felix, currentWovenClassListenerRef, null);
                     }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java Thu
Jan  8 11:03:40 2015
@@ -54,6 +54,7 @@ import org.osgi.framework.BundleActivato
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.Version;
 import org.osgi.framework.namespace.NativeNamespace;
 import org.osgi.framework.wiring.BundleCapability;
@@ -141,6 +142,22 @@ class ExtensionManager extends URLStream
     private volatile Bundle[] m_extensionsCache;
     private final Set m_names;
     private final Map m_sourceToExtensions;
+    private final List<ExtensionTuple> m_extensionTuples = Collections.synchronizedList(new
ArrayList<ExtensionTuple>());
+
+    private static class ExtensionTuple
+    {
+        private final BundleActivator m_activator;
+        private final Bundle m_bundle;
+        private volatile boolean m_failed;
+        private volatile boolean m_started;
+
+        public ExtensionTuple(BundleActivator activator, Bundle bundle)
+        {
+            m_activator = activator;
+            m_bundle = bundle;
+        }
+
+    }
 
     // This constructor is only used for the private instance added to the parent
     // classloader.
@@ -406,7 +423,7 @@ class ExtensionManager extends URLStream
             {
                 exports = ManifestParser.parseExportHeader(
                     m_logger, m_systemBundleRevision,
-                    (String) ((BundleRevisionImpl) bundle.adapt(BundleRevision.class))
+                    (String) ((BundleRevisionImpl) bundle.adapt(BundleRevisionImpl.class))
                         .getHeaders().get(Constants.EXPORT_PACKAGE),
                     m_systemBundleRevision.getSymbolicName(), m_systemBundleRevision.getVersion());
                 exports = aliasSymbolicName(exports);
@@ -417,7 +434,7 @@ class ExtensionManager extends URLStream
                     bundle,
                     Logger.LOG_ERROR,
                     "Error parsing extension bundle export statement: "
-                    + ((BundleRevisionImpl) bundle.adapt(BundleRevision.class))
+                    + ((BundleRevisionImpl) bundle.adapt(BundleRevisionImpl.class))
                         .getHeaders().get(Constants.EXPORT_PACKAGE), ex);
                 return;
             }
@@ -443,7 +460,7 @@ class ExtensionManager extends URLStream
             throw ex;
         }
 
-        BundleRevisionImpl bri = (BundleRevisionImpl) bundle.adapt(BundleRevision.class);
+        BundleRevisionImpl bri = (BundleRevisionImpl) bundle.adapt(BundleRevisionImpl.class);
         List<BundleRequirement> reqs = bri.getDeclaredRequirements(BundleRevision.HOST_NAMESPACE);
         List<BundleCapability> caps = getCapabilities(BundleRevision.HOST_NAMESPACE);
         BundleWire bw = new BundleWireImpl(bri, reqs.get(0), m_systemBundleRevision, caps.get(0));
@@ -470,13 +487,18 @@ class ExtensionManager extends URLStream
      */
     void startExtensionBundle(Felix felix, BundleImpl bundle)
     {
-        Dictionary<?,?> headers = bundle.getHeaders();
+        Map<?,?> headers = bundle.adapt(BundleRevisionImpl.class).getHeaders();
         String activatorClass = (String) headers.get(Constants.EXTENSION_BUNDLE_ACTIVATOR);
+        boolean felixExtension = false;
         if (activatorClass == null)
+        {
+            felixExtension = true;
             activatorClass = (String) headers.get(FelixConstants.FELIX_EXTENSION_ACTIVATOR);
+        }
 
         if (activatorClass != null)
         {
+            ExtensionTuple tuple = null;
             try
             {
 // TODO: SECURITY - Should this consider security?
@@ -484,26 +506,93 @@ class ExtensionManager extends URLStream
                     felix.getClass().getClassLoader().loadClass(
                         activatorClass.trim()).newInstance();
 
-// TODO: EXTENSIONMANAGER - This is kind of hacky, can we improve it?
-                felix.m_activatorList.add(activator);
-
                 BundleContext context = felix._getBundleContext();
 
                 bundle.setBundleContext(context);
 
+// TODO: EXTENSIONMANAGER - This is kind of hacky, can we improve it?
+                if (!felixExtension)
+                {
+                    tuple = new ExtensionTuple(activator, bundle);
+                    m_extensionTuples.add(tuple);
+                }
+                else
+                {
+                    felix.m_activatorList.add(activator);
+                }
+
                 if ((felix.getState() == Bundle.ACTIVE) || (felix.getState() == Bundle.STARTING))
                 {
+                    if (tuple != null)
+                    {
+                        tuple.m_started = true;
+                    }
                     Felix.m_secureAction.startActivator(activator, context);
                 }
             }
             catch (Throwable ex)
             {
+                if (tuple != null)
+                {
+                    tuple.m_failed = true;
+                }
+                felix.fireFrameworkEvent(FrameworkEvent.ERROR, bundle,
+                            new BundleException("Unable to start Bundle", ex));
+
                 m_logger.log(bundle, Logger.LOG_WARNING,
                     "Unable to start Extension Activator", ex);
             }
         }
     }
 
+    void startPendingExtensionBundles(Felix felix)
+    {
+        for (int i = 0;i < m_extensionTuples.size();i++)
+        {
+            if (!m_extensionTuples.get(i).m_started)
+            {
+                m_extensionTuples.get(i).m_started = true;
+                try
+                {
+                    Felix.m_secureAction.startActivator(m_extensionTuples.get(i).m_activator,
felix._getBundleContext());
+                }
+                catch (Throwable ex)
+                {
+                    m_extensionTuples.get(i).m_failed = true;
+
+                    felix.fireFrameworkEvent(FrameworkEvent.ERROR, m_extensionTuples.get(i).m_bundle,
+                                new BundleException("Unable to start Bundle", BundleException.ACTIVATOR_ERROR,
ex));
+
+                    m_logger.log(m_extensionTuples.get(i).m_bundle, Logger.LOG_WARNING,
+                        "Unable to start Extension Activator", ex);
+                }
+            }
+        }
+    }
+
+    void stopExtensionBundles(Felix felix)
+    {
+        for (int i = m_extensionTuples.size() - 1; i >= 0;i--)
+        {
+            if (m_extensionTuples.get(i).m_started && !m_extensionTuples.get(i).m_failed)
+            {
+                try
+                {
+                    Felix.m_secureAction.stopActivator(m_extensionTuples.get(i).m_activator,
felix._getBundleContext());
+                }
+                catch (Throwable ex)
+                {
+                    felix.fireFrameworkEvent(FrameworkEvent.ERROR, m_extensionTuples.get(i).m_bundle,
+                                new BundleException("Unable to stop Bundle", BundleException.ACTIVATOR_ERROR,
ex));
+
+                    m_logger.log(m_extensionTuples.get(i).m_bundle, Logger.LOG_WARNING,
+                        "Unable to stop Extension Activator", ex);
+                }
+            }
+        }
+        m_extensionTuples.clear();
+    }
+
     /**
      * Remove all extension registered by the given framework instance. Note, it
      * is not possible to unregister allready loaded classes form those extensions.

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?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- 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 Thu Jan  8 11:03:40
2015
@@ -83,6 +83,7 @@ import org.osgi.framework.FrameworkEvent
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.PackagePermission;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceException;
 import org.osgi.framework.ServiceFactory;
@@ -617,19 +618,16 @@ public class Felix extends BundleImpl im
         return true;
     }
 
-    /**
-     * This method initializes the framework, which is comprised of resolving
-     * the system bundle, reloading any cached bundles, and activating the system
-     * bundle. The framework is left in the <tt>Bundle.STARTING</tt> state and
-     * reloaded bundles are in the <tt>Bundle.INSTALLED</tt> state. After
-     * successfully invoking this method, <tt>getBundleContext()</tt> will
-     * return a valid <tt>BundleContext</tt> for the system bundle. To finish
-     * starting the framework, invoke the <tt>start()</tt> method.
-     *
-     * @throws org.osgi.framework.BundleException if any error occurs.
-    **/
+
     public void init() throws BundleException
     {
+        init((FrameworkListener[]) null);
+    }
+    /**
+     * @see org.osgi.framework.launch.Framework#init(org.osgi.framework.FrameworkListener[])
+     */
+    public void init(final FrameworkListener... listeners) throws BundleException
+    {
         // The system bundle can only be initialized if it currently isn't started.
         acquireBundleLock(this,
             Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE);
@@ -825,6 +823,15 @@ public class Felix extends BundleImpl im
                 // so create a gate for that purpose.
                 m_shutdownGate = new ThreadGate();
 
+                // add framework listeners
+                if ( listeners != null )
+                {
+                    for(final FrameworkListener fl : listeners)
+                    {
+                        addFrameworkListener(this, fl);
+                    }
+                }
+
                 // Start services
                 m_fwkWiring.start();
                 m_fwkStartLevel.start();
@@ -892,6 +899,9 @@ public class Felix extends BundleImpl im
                     }
                 }
 
+                m_extensionManager.startPendingExtensionBundles(Felix.this);
+                m_fwkWiring.refreshBundles(null);
+
                 // Clear the cache of classes coming from the system bundle.
                 // This is only used for Felix.getBundle(Class clazz) to speed
                 // up class lookup for the system bundle.
@@ -904,6 +914,14 @@ public class Felix extends BundleImpl im
         finally
         {
             releaseBundleLock(this);
+
+            if ( listeners != null )
+            {
+                for(final FrameworkListener fl : listeners)
+                {
+                    removeFrameworkListener(this, fl);
+                }
+            }
         }
     }
 
@@ -4398,6 +4416,13 @@ public class Felix extends BundleImpl im
 
     boolean impliesBundlePermission(BundleProtectionDomain bundleProtectionDomain, Permission
permission, boolean direct)
     {
+        if (direct && permission instanceof PackagePermission)
+        {
+            if (bundleProtectionDomain.impliesWoven(permission))
+            {
+                return true;
+            }
+        }
         if (m_securityProvider != null)
         {
             return m_securityProvider.hasBundlePermission(bundleProtectionDomain, permission,
direct);
@@ -4782,10 +4807,23 @@ public class Felix extends BundleImpl im
             m_activatorList.add(0, new URLHandlersActivator(m_configMap, Felix.this));
 
             // Start all activators.
-            for (int i = 0; i < m_activatorList.size(); i++)
+            for (Iterator<BundleActivator> iter = m_activatorList.iterator(); iter.hasNext();
)
             {
-                Felix.m_secureAction.startActivator(
-                    (BundleActivator) m_activatorList.get(i), context);
+                try
+                {
+                    Felix.m_secureAction.startActivator(
+                        iter.next(), context);
+                }
+                catch (Throwable throwable)
+                {
+                    iter.remove();
+                    fireFrameworkEvent(FrameworkEvent.ERROR, context.getBundle(),
+                            new BundleException("Unable to start Bundle", throwable));
+                    m_logger.log(
+                        Logger.LOG_WARNING,
+                        "Exception starting a system bundle activator.",
+                        throwable);
+                }
             }
         }
 
@@ -4860,6 +4898,7 @@ public class Felix extends BundleImpl im
                 ((BundleImpl) bundles[i]).close();
             }
 
+            m_extensionManager.stopExtensionBundles(Felix.this);
             // Stop all system bundle activators.
             for (int i = 0; i < m_activatorList.size(); i++)
             {
@@ -4870,13 +4909,14 @@ public class Felix extends BundleImpl im
                 }
                 catch (Throwable throwable)
                 {
+                    fireFrameworkEvent(FrameworkEvent.ERROR, context.getBundle(),
+                        new BundleException("Unable to stop Bundle", throwable));
                     m_logger.log(
                         Logger.LOG_WARNING,
                         "Exception stopping a system bundle activator.",
                         throwable);
                 }
             }
-
             if (m_securityManager != null)
             {
                 System.setSecurityManager(null);
@@ -5336,39 +5376,6 @@ public class Felix extends BundleImpl im
         return m_urlHandlersActivator.getContentHandlerService(mimeType);
     }
 
-    /**
-     * @see org.osgi.framework.launch.Framework#init(org.osgi.framework.FrameworkListener[])
-     */
-    public void init(final FrameworkListener... listeners) throws BundleException
-    {
-        // add framework listeners
-        if ( listeners != null )
-        {
-            for(final FrameworkListener fl : listeners)
-            {
-                addFrameworkListener(this, fl);
-            }
-        }
-
-        // call init
-        try
-        {
-            this.init();
-        }
-
-        // remove framework listeners
-        finally
-        {
-            if ( listeners != null )
-            {
-                for(final FrameworkListener fl : listeners)
-                {
-                    removeFrameworkListener(this, fl);
-                }
-            }
-        }
-    }
-
     Collection<BundleCapability> findProviders(final Requirement requirement)
     {
         return m_resolver.findProvidersInternal(null, requirement, true, false);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
Thu Jan  8 11:03:40 2015
@@ -126,8 +126,10 @@ class FrameworkStartLevelImpl implements
 
         synchronized (m_requests)
         {
-            // Start thread if necessary.
-            startThread();
+            if (m_thread == null)
+            {
+                throw new IllegalStateException("No inital startlevel yet");
+            }
             // Queue request.
             m_requestListeners.add(listeners);
             m_requests.add(new Integer(startlevel));

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
Thu Jan  8 11:03:40 2015
@@ -125,6 +125,11 @@ class FrameworkWiringImpl implements Fra
                 new AdminPermission(m_felix, AdminPermission.RESOLVE));
         }
 
+        if (m_thread == null)
+        {
+            return false;
+        }
+
         return m_felix.resolveBundles(bundles);
     }
 

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java Thu
Jan  8 11:03:40 2015
@@ -28,8 +28,10 @@ import java.util.ListIterator;
 import org.apache.felix.framework.util.ImmutableList;
 import org.apache.felix.framework.util.manifestparser.ManifestParser;
 import org.osgi.framework.AdminPermission;
+import org.osgi.framework.PackagePermission;
 import org.osgi.framework.hooks.weaving.WovenClass;
 import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWiring;
 
 class WovenClassImpl implements WovenClass, List<String>
@@ -58,13 +60,13 @@ class WovenClassImpl implements WovenCla
         m_bytes = (bytes == null) ? m_bytes : bytes;
         completeImports(imports);
     }
-    
+
     synchronized void completeImports(List<String> imports)
     {
         m_imports = (imports == null) ? ImmutableList.newInstance(m_imports)
                 : ImmutableList.newInstance(imports);
     }
-    
+
     synchronized void completeDefine(Class definedClass)
     {
         m_definedClass = definedClass;
@@ -199,11 +201,22 @@ class WovenClassImpl implements WovenCla
                 re.initCause(ex);
                 throw re;
             }
+            checkImport(s);
             return m_imports.add(s);
         }
         return false;
     }
 
+    private void checkImport(String s)
+    {
+        SecurityManager sm = System.getSecurityManager();
+
+        if (sm != null)
+        {
+            sm.checkPermission(new PackagePermission(s, PackagePermission.IMPORT));
+        }
+    }
+
     public synchronized boolean remove(Object o)
     {
         SecurityManager sm = System.getSecurityManager();
@@ -241,6 +254,7 @@ class WovenClassImpl implements WovenCla
                 re.initCause(ex);
                 throw re;
             }
+            checkImport(s);
         }
         return m_imports.addAll(collection);
     }
@@ -267,6 +281,7 @@ class WovenClassImpl implements WovenCla
                 re.initCause(ex);
                 throw re;
             }
+            checkImport(s);
         }
         return m_imports.addAll(i, collection);
     }
@@ -295,6 +310,12 @@ class WovenClassImpl implements WovenCla
 
     public synchronized void clear()
     {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null)
+        {
+            sm.checkPermission(new AdminPermission(m_wiring.getBundle(),
+                    AdminPermission.WEAVE));
+        }
         m_imports.clear();
     }
 
@@ -322,6 +343,7 @@ class WovenClassImpl implements WovenCla
             re.initCause(ex);
             throw re;
         }
+        checkImport(s);
         return m_imports.set(i, s);
     }
 
@@ -344,6 +366,7 @@ class WovenClassImpl implements WovenCla
             re.initCause(ex);
             throw re;
         }
+        checkImport(s);
         m_imports.add(i, s);
     }
 
@@ -396,7 +419,7 @@ class WovenClassImpl implements WovenCla
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.osgi.framework.hooks.weaving.WovenClass#getState()
      */
     public synchronized int getState()
@@ -412,6 +435,15 @@ class WovenClassImpl implements WovenCla
                 && (state == DEFINED || state == DEFINE_FAILED || state == TRANSFORMING_FAILED))
         {
             m_isComplete = true;
+            if (state == DEFINED || state == DEFINE_FAILED)
+            {
+                BundleProtectionDomain pd = (BundleProtectionDomain)
+                    ((BundleRevisionImpl) m_wiring.getRevision()).getProtectionDomain();
+                for (String s : m_imports)
+                {
+                    pd.addWoven(s);
+                }
+            }
         }
         if(state == TRANSFORMED)
         {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
Thu Jan  8 11:03:40 2015
@@ -197,6 +197,7 @@ public class EventDispatcher
             catch (IllegalStateException ex)
             {
                 // Bundle context is no longer valid, so just return.
+                return null;
             }
 
             Map<BundleContext, List<ListenerInfo>> listeners = null;

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java?rev=1650249&r1=1650248&r2=1650249&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
Thu Jan  8 11:03:40 2015
@@ -1448,7 +1448,7 @@ public class SecureAction
             rh.end();
         }
     }
-    
+
     public void invokeWovenClassListener(
             org.osgi.framework.hooks.weaving.WovenClassListener wcl,
             org.osgi.framework.hooks.weaving.WovenClass wc)
@@ -1786,6 +1786,10 @@ public class SecureAction
                 case DELETE_FILEONEXIT_ACTION:
                     ((File) arg1).deleteOnExit();
                     return null;
+                case INVOKE_WOVEN_CLASS_LISTENER:
+                    ((org.osgi.framework.hooks.weaving.WovenClassListener) arg1).modified(
+                        (org.osgi.framework.hooks.weaving.WovenClass) arg2);
+                    return null;
             }
 
             return null;



Mime
View raw message