Author: ggregory
Date: Wed Feb 12 16:01:21 2014
New Revision: 1567662
URL: http://svn.apache.org/r1567662
Log:
<action issue="VFS-500" dev="ggregory" type="update" due-to="Bernd Eckenfels">
VFSClassLoader.findResources missing.
</action>
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VFSClassLoader.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/VfsClassLoaderTests.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VFSClassLoader.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VFSClassLoader.java?rev=1567662&r1=1567661&r2=1567662&view=diff
==============================================================================
---
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VFSClassLoader.java
(original)
+++
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VFSClassLoader.java
Wed Feb 12 16:01:21 2014
@@ -25,8 +25,10 @@ import java.security.Permissions;
import java.security.SecureClassLoader;
import java.security.cert.Certificate;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
@@ -369,27 +371,25 @@ public class VFSClassLoader extends Secu
/**
* Returns an Enumeration of all the resources in the search path
* with the specified name.
- * TODO - Implement this.
+ *
+ * Gets called from {@link ClassLoader#getResources(String)} after
+ * parent class loader was questioned.
* @param name The resources to find.
* @return An Enumeration of the resources associated with the name.
+ * @throws FileSystemException
*/
@Override
- protected Enumeration<URL> findResources(final String name)
- {
- return new Enumeration<URL>()
- {
- @Override
- public boolean hasMoreElements()
- {
- return false;
- }
+ protected Enumeration<URL> findResources(final String name) throws
IOException {
+ final List<URL> result = new ArrayList<URL>(2);
- @Override
- public URL nextElement()
- {
- return null;
+ for (FileObject baseFile : resources) {
+ final FileObject file = baseFile.resolveFile(name,
NameScope.DESCENDENT_OR_SELF);
+ if (file.exists()) {
+ result.add(new Resource(name, baseFile, file).getURL());
}
- };
+ }
+
+ return Collections.enumeration(result);
}
/**
Modified:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/VfsClassLoaderTests.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/VfsClassLoaderTests.java?rev=1567662&r1=1567661&r2=1567662&view=diff
==============================================================================
---
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/VfsClassLoaderTests.java
(original)
+++
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/VfsClassLoaderTests.java
Wed Feb 12 16:01:21 2014
@@ -16,12 +16,17 @@
*/
package org.apache.commons.vfs2.impl.test;
+import java.io.File;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Enumeration;
+import org.apache.commons.AbstractVfsTestCase;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.impl.VFSClassLoader;
import org.apache.commons.vfs2.test.AbstractProviderTestCase;
@@ -96,6 +101,56 @@ public class VfsClassLoaderTests
}
/**
+ * Tests retrieving resources (from JAR searchpath)
+ */
+ public void testGetResourcesJARs() throws Exception
+ {
+ final FileSystemManager manager = getManager();
+ final File baseDir = AbstractVfsTestCase.getTestDirectory();
+
+ // make sure the provider config is useable
+ if (baseDir == null || manager == null || !baseDir.isDirectory())
+ {
+ return;
+ }
+
+ // build search path without using #getBaseFolder()
+ // because NestedJarTestCase redefines it
+ final FileObject nestedJar;
+ final FileObject testJar;
+ try
+ {
+ nestedJar = manager.resolveFile(baseDir, "nested.jar");
+ testJar = manager.resolveFile(baseDir, "test.jar");
+ }
+ catch (FileSystemException ignored)
+ {
+ return; // this suite cannot handle localFiles
+ }
+
+ final FileObject[] search = new FileObject[] { nestedJar, testJar };
+
+ // test setup needs to know about .jar extension - i.e.
NestedJarTestCase
+ if (!manager.canCreateFileSystem(nestedJar))
+ {
+ return;
+ }
+
+ // verify test setup
+ assertTrue("nested.jar is required for testing", nestedJar.getType()
== FileType.FILE);
+ assertTrue("test.jar is required for testing", testJar.getType() ==
FileType.FILE);
+
+ final VFSClassLoader loader = new VFSClassLoader(search, getManager());
+ final Enumeration<URL> urls =
loader.getResources("META-INF/MANIFEST.MF");
+ final URL url1 = urls.nextElement();
+ final URL url2 = urls.nextElement();
+
+ assertTrue("First resource must refer to nested.jar but was " + url1,
url1.toString().endsWith("nested.jar!/META-INF/MANIFEST.MF"));
+ assertTrue("Second resource must refer to test.jar but was " + url2,
url2.toString().endsWith("test.jar!/META-INF/MANIFEST.MF"));
+ }
+
+
+ /**
* Verify the package loaded with class loader.
*/
private void verifyPackage(final Package pack,
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1567662&r1=1567661&r2=1567662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Wed Feb 12 16:01:21 2014
@@ -26,6 +26,9 @@
<!-- <action issue="VFS-443" dev="ggregory" type="update"
due-to="nickallen"> -->
<!-- [Local] Need an easy way to convert from a FileObject to a
File. -->
<!-- </action> -->
+ <action issue="VFS-500" dev="ggregory" type="update" due-to="Bernd
Eckenfels">
+ VFSClassLoader.findResources missing.
+ </action>
<action issue="VFS-514" dev="ggregory" type="update" due-to="Bernd
Eckenfels">
[tests] PermissionsTests leaves unclean test directory.
</action>