You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2008/01/04 17:27:26 UTC

svn commit: r608905 - in /felix/trunk/framework/src/main/java/org/apache/felix: framework/cache/DirectoryRevision.java framework/cache/JarRevision.java moduleloader/ContentDirectoryContent.java

Author: rickhall
Date: Fri Jan  4 08:27:25 2008
New Revision: 608905

URL: http://svn.apache.org/viewvc?rev=608905&view=rev
Log:
Applied patch (FELIX-426) to fix some issues related to directories on
the bundle class path. Specifically, leading slashes created an issue
and are now stripped and entries were not being properly filtered when
enumerating the contents of a class path directory.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
    felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java?rev=608905&r1=608904&r2=608905&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java Fri Jan  4 08:27:25 2008
@@ -142,6 +142,13 @@
         List contentList = new ArrayList();
         for (int i = 0; i < classPathStrings.length; i++)
         {
+            // Remove any leading slash, since all bundle class path
+            // entries are relative to the root of the bundle.
+            classPathStrings[i] = (classPathStrings[i].startsWith("/"))
+                ? classPathStrings[i].substring(1)
+                : classPathStrings[i];
+
+            // Check for the bundle itself on the class path.
             if (classPathStrings[i].equals(FelixConstants.CLASS_PATH_DOT))
             {
                 contentList.add(self);
@@ -194,4 +201,4 @@
         // of the revision directory, which will be automatically deleted
         // by the parent bundle archive.
     }
-}
+}
\ No newline at end of file

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java?rev=608905&r1=608904&r2=608905&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java Fri Jan  4 08:27:25 2008
@@ -161,6 +161,13 @@
             List contentList = new ArrayList();
             for (int i = 0; i < classPathStrings.length; i++)
             {
+                // Remove any leading slash, since all bundle class path
+                // entries are relative to the root of the bundle.
+                classPathStrings[i] = (classPathStrings[i].startsWith("/"))
+                    ? classPathStrings[i].substring(1)
+                    : classPathStrings[i];
+
+                // Check for the bundle itself on the class path.
                 if (classPathStrings[i].equals(FelixConstants.CLASS_PATH_DOT))
                 {
                     contentList.add(self);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java?rev=608905&r1=608904&r2=608905&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java Fri Jan  4 08:27:25 2008
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Enumeration;
+import java.util.NoSuchElementException;
 
 public class ContentDirectoryContent implements IContent
 {
@@ -133,25 +134,44 @@
     {
         private Enumeration m_enumeration = null;
         private String m_rootPath = null;
+        private String m_nextEntry = null;
 
         public EntriesEnumeration(Enumeration enumeration, String rootPath)
         {
             m_enumeration = enumeration;
             m_rootPath = rootPath;
+            m_nextEntry = findNextEntry();
         }
 
         public boolean hasMoreElements()
         {
-            return m_enumeration.hasMoreElements();
+            return (m_nextEntry != null);
         }
 
         public Object nextElement()
         {
-            // We need to treat the specified path as the root of the
-            // content, so we need to strip off the leading path from
-            // each entry because it is automatically added back on
-            // in the other calls above.
-            return ((String) m_enumeration.nextElement()).substring(m_rootPath.length());
+            if (m_nextEntry == null)
+            {
+                throw new NoSuchElementException("No more elements.");
+            }
+            String currentEntry = m_nextEntry;
+            m_nextEntry = findNextEntry();
+            return currentEntry;
+        }
+
+        private String findNextEntry()
+        {
+            // Find next entry that is inside the root directory.
+            while (m_enumeration.hasMoreElements())
+            {
+                String next = (String) m_enumeration.nextElement();
+                if (next.startsWith(m_rootPath) && !next.equals(m_rootPath))
+                {
+                    // Strip off the root directory.
+                    return next.substring(m_rootPath.length());
+                }
+            }
+            return null;
         }
     }
 }