Patch to address a bug during shutdown where uninstalled fragments are not
properly closed, since the fragment and it host both have the fragment's
content open. Modified the purge during shutdown to happen after all bundles
are remove/closed, instead of before. (FELIX-819)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@719404 13f79535-47bb-0310-9956-ffa450edef68
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 e4060e7..5574219 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -3838,13 +3838,37 @@
                 // Should never happen.
             }
 
+            // Shutdown event dispatching queue.
+            EventDispatcher.shutdown();
+
+            // Remove all bundles from the module factory so that any
+            // open resources will be closed.
+            Bundle[] bundles = getBundles();
+            for (int i = 0; i < bundles.length; i++)
+            {
+                FelixBundle bundle = (FelixBundle) bundles[i];
+                IModule[] modules = bundle.getInfo().getModules();
+                for (int j = 0; j < modules.length; j++)
+                {
+                    try
+                    {
+                        m_factory.removeModule(modules[j]);
+                    }
+                    catch (Exception ex)
+                    {
+                        m_logger.log(Logger.LOG_ERROR,
+                           "Unable to clean up " + bundle.getInfo().getLocation(), ex);
+                    }
+                }
+            }
+
             // Since there may be updated and uninstalled bundles that
             // have not been refreshed, we will take care of refreshing
             // them during shutdown.
 
             // First loop through all bundled and purge old revisions
             // from updated bundles.
-            Bundle[] bundles = getBundles();
+            bundles = getBundles();
             for (int i = 0; i < bundles.length; i++)
             {
                 FelixBundle bundle = (FelixBundle) bundles[i];
@@ -3883,30 +3907,6 @@
                 }
             }
 
-            // Shutdown event dispatching queue.
-            EventDispatcher.shutdown();
-
-            // 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++)
-            {
-                FelixBundle bundle = (FelixBundle) bundles[i];
-                IModule[] modules = bundle.getInfo().getModules();
-                for (int j = 0; j < modules.length; j++)
-                {
-                    try
-                    {
-                        m_factory.removeModule(modules[j]);
-                    }
-                    catch (Exception ex)
-                    {
-                        m_logger.log(Logger.LOG_ERROR,
-                           "Unable to clean up " + bundle.getInfo().getLocation(), ex);
-                    }
-                }
-            }
-
             // Next, stop all system bundle activators.
             for (int i = 0; i < m_activatorList.size(); i++)
             {