Null the classloader of a bundle when it's contenloader is closed and call System.gc twice when we can not delete the bundle revision in the cache. This allows to update and uninstall bundles with native libs on windows. (FELIX-733)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@704246 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java b/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
index d9cc7db..1b6525e 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
@@ -275,7 +275,23 @@
 
     protected static boolean deleteDirectoryTree(File target)
     {
-        if (!getSecureAction().fileExists(target))
+        if (!deleteDirectoryTreeRecursiv(target))
+        {
+            // We might be talking windows and native libs -- hence,
+            // try to trigger a gc and try again. The hope is that
+            // this releases the classloader that loaded the native
+            // lib and allows us to delete it because it then 
+            // would not be used anymore. 
+            System.gc();
+            System.gc();
+            return deleteDirectoryTreeRecursiv(target);
+        }
+        return true;
+    }
+
+    private static boolean deleteDirectoryTreeRecursiv(File target)
+    {
+    	if (!getSecureAction().fileExists(target))
         {
             return true;
         }
@@ -285,7 +301,7 @@
             File[] files = getSecureAction().listDirectory(target);
             for (int i = 0; i < files.length; i++)
             {
-                deleteDirectoryTree(files[i]);
+                deleteDirectoryTreeRecursiv(files[i]);
             }
         }
 
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
index d99f872..a140f53 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
@@ -70,6 +70,10 @@
         {
             m_fragmentContents[i].close();
         }
+        synchronized (this)
+        {
+            m_classLoader = null;
+        }
     }
 
     public IContent getContent()