pkt1583 / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Fails to scan exploded archive #160

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

During development I am deploying to a weblogic cluster which requires me to 
deploy from eclipse as an exploded archive not a virtual application.

My code was working great when I was deploying to the single AdminServer during 
development and I fully expect my code will still work in production when it 
really is a ear/jar file. 

What version of the product are you using? On what operating system?
I am using reflections-0.9.9-RC1.

Please provide any additional information below.

LOG FILE:
Sep 19, 2013 6:40:49 PM org.reflections.vfs.Vfs fromURL
WARNING: could not create Dir using jarFile from url 
file:/opt/Oracle/Middleware12c/user_projects/domains/devel12c/servers/server12c2
/stage/EiCtm/EiCtm/lib/EiCtmGems.jar/. skipping.
java.io.FileNotFoundException: 
/opt/Oracle/Middleware12c/user_projects/domains/devel12c/servers/server12c2/stag
e/EiCtm/EiCtm/lib/EiCtmGems.jar (Is a directory)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:214)

ACTUAL DIRECTORY
09:00 AM user@linux> ls -l 
/opt/Oracle/Middleware12c/user_projects/domains/devel12c/servers/server12c1/stag
e/EiCtm/EiCtm/lib/EiCtmGems.jar
total 8.0K
drwxrwx--- 2 user az25-sgss 4.0K Sep 19 17:06 META-INF/
drwxrwx--- 3 user az25-sgss 4.0K Sep 19 17:06 sgss/

FAILED JAR COMMAND
08:49 AM user@linux> jar -tf 
/opt/Oracle/Middleware12c/user_projects/domains/devel12c/servers/server12c1/stag
e/EiCtm/EiCtm/lib/EiCtmGems.jar
java.io.FileNotFoundException: 
/opt/Oracle/Middleware12c/user_projects/domains/devel12c/servers/server12c1/stag
e/EiCtm/EiCtm/lib/EiCtmGems.jar (Is a directory)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:214)
    at java.util.zip.ZipFile.<init>(ZipFile.java:144)
    at java.util.zip.ZipFile.<init>(ZipFile.java:115)
    at sun.tools.jar.Main.list(Main.java:1004)
    at sun.tools.jar.Main.run(Main.java:245)
    at sun.tools.jar.Main.main(Main.java:1177)

Original issue reported on code.google.com by cfous...@gmail.com on 20 Sep 2013 at 4:51

GoogleCodeExporter commented 8 years ago
It appears that Reflections is mistakenly assuming the URL is a JAR file 
because of the .jar extension without first checking to see if it is actually a 
directory (?). The following seems to work around this issue for me, but is 
probably not the best solution (do this before constructing the Reflections 
object).

      // Create a custom Reflections VFS URL type to handle exploded jar directories (the
      // reflection code should probably test to see if a URL with a jar extension is
      // actually a JAR file). 
      Vfs.UrlType explodedJarUrlType = new Vfs.UrlType()
      {
         /**
          * Returns true if the URL is a directory on the filesystem.
          */
         public boolean matches(URL url)
         {
            try
            {
               // Fairly ugly way to determine if the URL is a directory.
               File file = new File(url.toURI());
               return file.isDirectory();
            }
            catch (URISyntaxException e)
            {
               return false;
            }
         }

         /**
          * Returns the Reflections SystemDir VFS type.
          */
         public Vfs.Dir createDir(final URL url)
         {
            try
            {
               File file = new File(url.toURI());
               return new SystemDir(file);
            }
            catch (URISyntaxException e)
            {
               // Cannot happen due to matches() method
               log.error("The URL is not in the correct format");
               return null;
            }
         }
      };

      // Replace the default URL types, inserting our custom URL type to the beginning
      // of the list.
      List<Vfs.UrlType> urlTypes = Vfs.getDefaultUrlTypes();
      urlTypes.add(0, explodedJarUrlType);
      Vfs.setDefaultURLTypes(urlTypes);

Original comment by geech1...@gmail.com on 24 Sep 2013 at 10:31