openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1774477 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Date Thu, 15 Dec 2016 14:34:23 GMT
Author: ilgrosso
Date: Thu Dec 15 14:34:23 2016
New Revision: 1774477

URL: http://svn.apache.org/viewvc?rev=1774477&view=rev
Log:
[OPENJPA-2684] Adding support for JAR files via ZipStreamMetaDataIterator

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java?rev=1774477&r1=1774476&r2=1774477&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Thu Dec 15 14:34:23 2016
@@ -66,7 +66,7 @@ import org.apache.openjpa.util.UserExcep
 
 /**
  * Base class for factory implementations built around XML metadata files
- * in the common fomat.
+ * in the common format.
  *
  * @author Abe White
  * @since 0.4.0
@@ -712,25 +712,52 @@ public abstract class AbstractCFMetaData
                         log.trace(_loc.get("scanning-vfs-url", url));
                     }
 
-                    final URLConnection conn = url.openConnection();
-                    final Object vfsContent = conn.getContent();
                     final URL finalUrl = url;
-                    File file = AccessController.doPrivileged(new PrivilegedAction<File>()
{
-                        @SuppressWarnings({ "rawtypes", "unchecked" })
-                        public File run() {
-                            try {
-                                Class virtualFileClass = Class.forName("org.jboss.vfs.VirtualFile");
-                                Method getPhysicalFile = virtualFileClass.getDeclaredMethod("getPhysicalFile");
-                                return (File) getPhysicalFile.invoke(vfsContent);
-                            } catch (Exception e) {
-                                log.error(_loc.get("while-scanning-vfs-url", finalUrl), e);
+                    if (url.toString().endsWith(".jar")) {
+                        ZipInputStream zis = AccessController.doPrivileged(new PrivilegedAction<ZipInputStream>()
{
+
+                            @SuppressWarnings({ "rawtypes", "unchecked" })
+                            @Override
+                            public ZipInputStream run() {
+                                try {
+                                    Class vfs = Class.forName("org.jboss.vfs.VFS");
+                                    Method getChild = vfs.getDeclaredMethod("getChild", URL.class);
+                                    Object jarFile = getChild.invoke(null, finalUrl);
+
+                                    Class virtualFileClass = Class.forName("org.jboss.vfs.VirtualFile");
+                                    Method openStream = virtualFileClass.getDeclaredMethod("openStream");
+                                    return (ZipInputStream) openStream.invoke(jarFile);
+                                } catch (Exception e) {
+                                    log.error(_loc.get("while-scanning-vfs-url", finalUrl),
e);
+                                }
+                                return null;
                             }
-                            return null;
+                        });
+                        if (zis != null) {
+                            scan(new ZipStreamMetaDataIterator(zis, newMetaDataFilter()),
cparser, names, true, url);
                         }
-                    });
-                    if (file != null)
-                        scan(new FileMetaDataIterator(file, newMetaDataFilter()), cparser,
names, true, file);
-
+                    } else {
+                        final URLConnection conn = url.openConnection();
+                        final Object vfsContent = conn.getContent();
+                        File file = AccessController.doPrivileged(new PrivilegedAction<File>()
{
+
+                            @SuppressWarnings({ "rawtypes", "unchecked" })
+                            @Override
+                            public File run() {
+                                try {
+                                    Class virtualFileClass = Class.forName("org.jboss.vfs.VirtualFile");
+                                    Method getPhysicalFile = virtualFileClass.getDeclaredMethod("getPhysicalFile");
+                                    return (File) getPhysicalFile.invoke(vfsContent);
+                                } catch (Exception e) {
+                                    log.error(_loc.get("while-scanning-vfs-url", finalUrl),
e);
+                                }
+                                return null;
+                            }
+                        });
+                        if (file != null) {
+                            scan(new FileMetaDataIterator(file, newMetaDataFilter()), cparser,
names, true, file);
+                        }
+                    }
                     continue;
                 }
                 if ("jar".equals(url.getProtocol())) {



Mime
View raw message