You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2011/06/20 18:29:53 UTC

svn commit: r1137688 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: BundleRevisionDependencies.java BundleWiringImpl.java util/manifestparser/ManifestParser.java

Author: rickhall
Date: Mon Jun 20 16:29:53 2011
New Revision: 1137688

URL: http://svn.apache.org/viewvc?rev=1137688&view=rev
Log:
Implement BundleWiring.isInUse() and don't add host capability
for hosts that disallow fragments. (FELIX-2950)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java?rev=1137688&r1=1137687&r2=1137688&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java Mon Jun 20 16:29:53 2011
@@ -88,21 +88,30 @@ class BundleRevisionDependencies
         return m_dependentsMap.get(provider);
     }
 
+    public synchronized boolean hasDependents(BundleRevision revision)
+    {
+        // We have to special case fragments, since their dependencies
+        // are actually reversed (i.e., they require a host, but then
+        // the host ends up dependent on them at run time).
+        if (Util.isFragment(revision)
+            && (revision.getWiring() != null)
+            && !revision.getWiring().getRequiredWires(null).isEmpty())
+        {
+            return true;
+        }
+        else if (m_dependentsMap.containsKey(revision))
+        {
+            return true;
+        }
+        return false;
+    }
+
     public synchronized boolean hasDependents(BundleImpl bundle)
     {
         List<BundleRevision> revisions = bundle.getRevisions();
         for (BundleRevision revision : revisions)
         {
-            // We have to special case fragments, since their dependencies
-            // are actually reversed (i.e., they require a host, but then
-            // the host ends up dependent on them at run time).
-            if (Util.isFragment(revision)
-                && (revision.getWiring() != null)
-                && !revision.getWiring().getRequiredWires(null).isEmpty())
-            {
-                return true;
-            }
-            else if (m_dependentsMap.containsKey(revision))
+            if (hasDependents(revision))
             {
                 return true;
             }

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=1137688&r1=1137687&r2=1137688&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 Mon Jun 20 16:29:53 2011
@@ -324,7 +324,11 @@ public class BundleWiringImpl implements
 
     public boolean isInUse()
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        return (isCurrent()
+// TODO: OSGi R4.3 - The following can be replaced with a call to getProvidedWires()
+//       once it is implemented.
+            || ((BundleImpl) m_revision.getBundle())
+                .getFramework().getDependencies().hasDependents(m_revision));
     }
 
     public List<BundleCapability> getCapabilities(String namespace)

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java?rev=1137688&r1=1137687&r2=1137688&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java Mon Jun 20 16:29:53 2011
@@ -109,15 +109,25 @@ public class ManifestParser
             // dependencies.
             if (headerMap.get(Constants.FRAGMENT_HOST) == null)
             {
+                // All non-fragment bundles have host capabilities.
                 capList.add(bundleCap);
-                Map<String, Object> hostAttrs =
-                    new HashMap<String, Object>(bundleCap.getAttributes());
-                Object value = hostAttrs.remove(BundleRevision.BUNDLE_NAMESPACE);
-                hostAttrs.put(BundleRevision.HOST_NAMESPACE, value);
-                capList.add(new BundleCapabilityImpl(
-                    owner, BundleRevision.HOST_NAMESPACE,
-                    Collections.EMPTY_MAP,
-                    hostAttrs));
+                // A non-fragment bundle can choose to not have a host capability.
+                String attachment =
+                    bundleCap.getDirectives().get(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
+                attachment = (attachment == null)
+                    ? Constants.FRAGMENT_ATTACHMENT_RESOLVETIME
+                    : attachment;
+                if (!attachment.equalsIgnoreCase(Constants.FRAGMENT_ATTACHMENT_NEVER))
+                {
+                    Map<String, Object> hostAttrs =
+                        new HashMap<String, Object>(bundleCap.getAttributes());
+                    Object value = hostAttrs.remove(BundleRevision.BUNDLE_NAMESPACE);
+                    hostAttrs.put(BundleRevision.HOST_NAMESPACE, value);
+                    capList.add(new BundleCapabilityImpl(
+                        owner, BundleRevision.HOST_NAMESPACE,
+                        Collections.EMPTY_MAP,
+                        hostAttrs));
+                }
             }
 
             // Add a singleton capability if the bundle is a singleton.