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.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@608905 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
index 3806787..b235a2e 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryRevision.java
@@ -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
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java b/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
index 12c08fe..76b8763 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
@@ -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);
diff --git a/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java b/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java
index 7290ab4..1aa0674 100644
--- a/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java
+++ b/framework/src/main/java/org/apache/felix/moduleloader/ContentDirectoryContent.java
@@ -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;
}
}
}
\ No newline at end of file