You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ec...@apache.org on 2015/10/02 17:13:16 UTC

svn commit: r1706429 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java src/changes/changes.xml

Author: ecki
Date: Fri Oct  2 15:13:15 2015
New Revision: 1706429

URL: http://svn.apache.org/viewvc?rev=1706429&view=rev
Log:
[VFS-424] Fix StandardFileSystemManager class loading so it works in a OSGi environment.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java?rev=1706429&r1=1706428&r2=1706429&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java Fri Oct  2 15:13:15 2015
@@ -130,12 +130,10 @@ public class StandardFileSystemManager
      */
     protected void configurePlugins() throws FileSystemException
     {
-        final ClassLoader cl = findClassLoader();
-
         Enumeration<URL> enumResources;
         try
         {
-            enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);
+            enumResources = loadResources(PLUGIN_CONFIG_RESOURCE);
         }
         catch (final IOException e)
         {
@@ -407,7 +405,7 @@ public class StandardFileSystemManager
     {
         try
         {
-            findClassLoader().loadClass(className);
+            loadClass(className);
             return true;
         }
         catch (final ClassNotFoundException e)
@@ -480,7 +478,7 @@ public class StandardFileSystemManager
     {
         try
         {
-            final Class<?> clazz = findClassLoader().loadClass(className);
+            Class<?> clazz = loadClass(className);
             return clazz.newInstance();
         }
         catch (final Exception e)
@@ -488,4 +486,36 @@ public class StandardFileSystemManager
             throw new FileSystemException("vfs.impl/create-provider.error", className, e);
         }
     }
+
+    /**
+     * Load a class from different class loaders.
+     * @throws ClassNotFoundException if last {@code loadClass} failed.
+     * @see #findClassLoader()
+     */
+    private Class< ? > loadClass(String className) throws ClassNotFoundException
+    {
+        try
+        {
+            return findClassLoader().loadClass(className);
+        }
+        catch (final ClassNotFoundException e)
+        {
+            return getClass().getClassLoader().loadClass(className);
+        }
+    }
+
+    /**
+     * Resolve resources from different class loaders.
+     * @throws IOException if {@code getResource} failed.
+     * @see #findClassLoader()
+     */
+    private Enumeration<URL> loadResources(String name) throws IOException
+    {
+        Enumeration<URL> res = findClassLoader().getResources(name);
+        if (res == null || !res.hasMoreElements())
+        {
+            res = getClass().getClassLoader().getResources(name);
+        }
+        return res;
+    }
 }

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1706429&r1=1706428&r2=1706429&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Fri Oct  2 15:13:15 2015
@@ -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-424" dev="ecki" type="fix">
+        Fix StandardFileSystemManager class loading so it works in a OSGi environment.
+     </action>
       <action issue="VFS-490" dev="ecki" type="fix">
         [vfsclassloader] Do not open folders with .jar extension. Adds tests.
      </action>