Implement BundleWiring.findEntries(). (FELIX-2950)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1141199 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 36026f0..2a28114 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -297,7 +297,8 @@
             }
         }
 
-        return getFramework().findBundleEntries(this, path, filePattern, recurse);
+        return getFramework().findBundleEntries(
+            adapt(BundleRevision.class), path, filePattern, recurse);
     }
 
     public Dictionary getHeaders()
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 6cd132d..e55b990 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
@@ -76,7 +76,7 @@
     private final StatefulResolver m_resolver;
     private final BundleRevisionImpl m_revision;
     private final List<BundleRevision> m_fragments;
-// TODO: OSGi R,4.3 - Perhaps we should make m_wires and m_importedPkgs volatile
+// TODO: OSGi R4.3 - Perhaps we should make m_wires and m_importedPkgs volatile
 //       and copy-on-write instead of protecting them with object lock.
     private final List<BundleWire> m_wires;
     private final Map<String, BundleRevision> m_importedPkgs;
@@ -281,7 +281,7 @@
                 ? false : true;
     }
 
-    public void dispose()
+    public synchronized void dispose()
     {
         if (m_fragmentContents != null)
         {
@@ -464,7 +464,20 @@
 
     public List<URL> findEntries(String path, String filePattern, int options)
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        if (!Util.isFragment(m_revision))
+        {
+            Enumeration<URL> e =
+                ((BundleImpl) m_revision.getBundle()).getFramework()
+                    .findBundleEntries(m_revision, path, filePattern,
+                       (options & BundleWiring.FINDENTRIES_RECURSE) > 0);
+            List<URL> entries = new ArrayList<URL>();
+            while ((e != null) && e.hasMoreElements())
+            {
+                entries.add(e.nextElement());
+            }
+            return Collections.unmodifiableList(entries);
+        }
+        return Collections.EMPTY_LIST;
     }
 
     public Collection<String> listResources(String path, String filePattern, int options)
@@ -738,7 +751,7 @@
         return result;
     }
 
-    ClassLoader getBootDelegationClassLoader()
+    synchronized ClassLoader getBootDelegationClassLoader()
     {
         // Get the appropriate class loader for delegation.
         ClassLoader parent = (m_classLoader == null)
diff --git a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
index 9ebb2cf..76d5af0 100644
--- a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
+++ b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
@@ -22,12 +22,11 @@
 import java.net.URL;
 import java.util.*;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.wiring.BundleRevision;
 
 class EntryFilterEnumeration implements Enumeration
 {
-    private final Bundle m_bundle;
+    private final BundleRevision m_revision;
     private final List<Enumeration> m_enumerations;
     private final List<BundleRevision> m_revisions;
     private int m_revisionIndex = 0;
@@ -39,24 +38,23 @@
     private final List<Object> m_nextEntries = new ArrayList(2);
 
     public EntryFilterEnumeration(
-        Bundle bundle, boolean includeFragments, String path,
+        BundleRevision revision, boolean includeFragments, String path,
         String filePattern, boolean recurse, boolean isURLValues)
     {
-        m_bundle = bundle;
-        BundleRevision br = m_bundle.adapt(BundleRevision.class);
+        m_revision = revision;
         if (includeFragments
-            && (br.getWiring() != null)
-            && (((BundleWiringImpl) br.getWiring()).getFragments() != null))
+            && (m_revision.getWiring() != null)
+            && (((BundleWiringImpl) m_revision.getWiring()).getFragments() != null))
         {
             m_revisions = new ArrayList(
-                ((BundleWiringImpl) br.getWiring()).getFragments().size() + 1);
-            m_revisions.addAll(((BundleWiringImpl) br.getWiring()).getFragments());
+                ((BundleWiringImpl) m_revision.getWiring()).getFragments().size() + 1);
+            m_revisions.addAll(((BundleWiringImpl) m_revision.getWiring()).getFragments());
         }
         else
         {
             m_revisions = new ArrayList(1);
         }
-        m_revisions.add(0, br);
+        m_revisions.add(0, m_revision);
         m_enumerations = new ArrayList(m_revisions.size());
         for (int i = 0; i < m_revisions.size(); i++)
         {
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 8d5407e..4e5d173 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1621,7 +1621,8 @@
             // Use the entry filter enumeration to search the bundle content
             // recursively for matching entries and return URLs to them.
             Enumeration enumeration =
-                new EntryFilterEnumeration(bundle, false, name, "*", true, true);
+                new EntryFilterEnumeration(
+                    bundle.adapt(BundleRevision.class), false, name, "*", true, true);
             // If the enumeration has elements, then that means we need
             // to synthesize the directory entry.
             if (enumeration.hasMoreElements())
@@ -1653,7 +1654,8 @@
         // Get the entry enumeration from the revision content and
         // create a wrapper enumeration to filter it.
         Enumeration enumeration =
-            new EntryFilterEnumeration(bundle, false, path, "*", false, false);
+            new EntryFilterEnumeration(
+                bundle.adapt(BundleRevision.class), false, path, "*", false, false);
 
         // Return the enumeration if it has elements.
         return (!enumeration.hasMoreElements()) ? null : enumeration;
@@ -1663,17 +1665,17 @@
      * Implementation for Bundle.findEntries().
     **/
     Enumeration findBundleEntries(
-        BundleImpl bundle, String path, String filePattern, boolean recurse)
+        BundleRevision revision, String path, String filePattern, boolean recurse)
     {
         // Try to resolve the bundle per the spec.
         List<Bundle> list = new ArrayList<Bundle>(1);
-        list.add(bundle);
+        list.add(revision.getBundle());
         resolveBundles(list);
 
         // Get the entry enumeration from the revision content and
         // create a wrapper enumeration to filter it.
         Enumeration enumeration =
-            new EntryFilterEnumeration(bundle, true, path, filePattern, recurse, true);
+            new EntryFilterEnumeration(revision, true, path, filePattern, recurse, true);
 
         // Return the enumeration if it has elements.
         return (!enumeration.hasMoreElements()) ? null : enumeration;