Added a patch to aggressively remove modules from module factory during
framework shutdown to force resources for modules to be cleaned up
immediately, rather than waiting for garbage collection.


git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@415575 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
index 908accf..15bfd0e 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -590,6 +590,27 @@
 
         // The framework is no longer in a usable state.
         m_frameworkStatus = INITIAL_STATUS;
+
+        // Remove all bundles from the module factory so that any
+        // open resources will be closed.
+        bundles = getBundles();
+        for (int i = 0; i < bundles.length; i++)
+        {
+            BundleImpl bundle = (BundleImpl) bundles[i];
+            try
+            {
+                IModule[] modules = bundle.getInfo().getModules();
+                for (int j = 0; j < modules.length; j++)
+                {
+                    m_factory.removeModule(modules[j]);
+                }
+            }
+            catch (Exception ex)
+            {
+                m_logger.log(Logger.LOG_ERROR,
+                   "Unable to clean up " + bundle.getInfo().getLocation(), ex);
+            }
+        }
     }
 
     public int getStatus()