Modified the resolver to longer consider uninstalled fragments and hosts
when resolving dependencies; this required a new "stale" flag on modules
that gets set when their associated bundle is uninstalled. (FELIX-776)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@704976 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleInfo.java b/framework/src/main/java/org/apache/felix/framework/BundleInfo.java
index 3be9371..e085ced 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleInfo.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleInfo.java
@@ -134,6 +134,19 @@
m_modules = dest;
}
+ /**
+ * This marks all modules as stale when the associated bundle has
+ * been uninstalled. This is necessary since uninstalled bundles
+ * should not be used for fragments or fragment hosts.
+ **/
+ public synchronized void markModulesStale()
+ {
+ for (int i = 0; i < m_modules.length; i++)
+ {
+ ((ModuleImpl) m_modules[i]).setStale();
+ }
+ }
+
public abstract String getSymbolicName();
public abstract long getBundleId();
@@ -394,4 +407,4 @@
return pd;
}
-}
\ No newline at end of file
+}
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 f96a20a..2c34bf5 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -2134,10 +2134,11 @@
if (target != null)
{
// Set the bundle's persistent state to uninstalled.
- target.getInfo().setPersistentStateUninstalled();
+ info.setPersistentStateUninstalled();
// Mark the bundle as removal pending.
- target.getInfo().setRemovalPending(true);
+ info.setRemovalPending(true);
+ info.markModulesStale();
// Put bundle in uninstalled bundle array.
rememberUninstalledBundle(bundle);
@@ -4347,4 +4348,4 @@
m_bundleLock.notifyAll();
}
}
-}
\ No newline at end of file
+}
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
index 1179a9a..dbd2c58 100755
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
@@ -1192,7 +1192,8 @@
for (int capIdx = 0; (caps != null) && (capIdx < caps.length); capIdx++)
{
if (caps[capIdx].getNamespace().equals(ICapability.HOST_NAMESPACE)
- && hostReq.isSatisfied(caps[capIdx]))
+ && hostReq.isSatisfied(caps[capIdx])
+ && !modules[modIdx].isStale())
{
hostList.add(modules[modIdx]);
break;
@@ -1235,7 +1236,8 @@
for (int reqIdx = 0; (reqs != null) && (reqIdx < reqs.length); reqIdx++)
{
if (reqs[reqIdx].getNamespace().equals(ICapability.HOST_NAMESPACE)
- && reqs[reqIdx].isSatisfied(bundleCap))
+ && reqs[reqIdx].isSatisfied(bundleCap)
+ && !modules[modIdx].isStale())
{
indexFragment(fragmentMap, modules[modIdx]);
break;
diff --git a/framework/src/main/java/org/apache/felix/moduleloader/IModule.java b/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
index 33f44ed..fc6c8dd 100644
--- a/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
+++ b/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
@@ -31,4 +31,14 @@
public Class getClass(String name) throws ClassNotFoundException;
public URL getResource(String name);
public Enumeration getResources(String name);
-}
\ No newline at end of file
+
+
+ /**
+ * Returns whether the module is associated with an uninstalled bundle.
+ * If so, then it should not be used when resolving fragments or fragment
+ * hosts. However, it still can be used for resolving imported packages.
+ * @return <tt>true</tt> if the module's bundle is uninstalled, otherwise
+ * <tt>false</tt>.
+ **/
+ public boolean isStale();
+}
diff --git a/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java b/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
index bba010d..e6f438f 100644
--- a/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
@@ -36,6 +36,7 @@
private IModule[] m_dependentHosts = new IModule[0];
private IModule[] m_dependentImporters = new IModule[0];
private IModule[] m_dependentRequirers = new IModule[0];
+ private volatile boolean m_isStale = false;
ModuleImpl(Logger logger, String id, IModuleDefinition md)
{
@@ -251,6 +252,16 @@
return null;
}
+ public boolean isStale()
+ {
+ return m_isStale;
+ }
+
+ public void setStale()
+ {
+ m_isStale = true;
+ }
+
public String toString()
{
return m_id;
@@ -302,4 +313,4 @@
return tmp;
}
-}
\ No newline at end of file
+}