Implement BundleWiring.isInUse() and don't add host capability
for hosts that disallow fragments. (FELIX-2950)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1137688 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
index 9b4f83a..44b29df 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionDependencies.java
@@ -88,21 +88,30 @@
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;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
index bd12416..6cd132d 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
@@ -324,7 +324,11 @@
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)
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
index 58ed7ec..839edd5 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
@@ -109,15 +109,25 @@
// 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.