You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/10/10 16:34:59 UTC

git commit: ISIS-805: ignore .jnilib files

Repository: isis
Updated Branches:
  refs/heads/ISIS-805 [created] 12706317b


ISIS-805: ignore .jnilib files


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/12706317
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/12706317
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/12706317

Branch: refs/heads/ISIS-805
Commit: 12706317b233164f7cb3eb9136048ba95dc4f28d
Parents: 0b52dc3
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Oct 10 15:33:29 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Oct 10 15:33:29 2014 +0100

----------------------------------------------------------------------
 .../ClassDiscoveryServiceUsingReflections.java  | 84 +++++++++++++++++++-
 1 file changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/12706317/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java b/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
index ea123e7..10d6b2a 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
@@ -19,19 +19,19 @@
 package org.apache.isis.applib.services.classdiscovery;
 
 import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLDecoder;
+import java.net.*;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.jar.JarFile;
 import com.google.common.collect.Lists;
 import org.reflections.Reflections;
 import org.reflections.scanners.SubTypesScanner;
 import org.reflections.util.ClasspathHelper;
 import org.reflections.vfs.SystemDir;
 import org.reflections.vfs.Vfs;
+import org.reflections.vfs.ZipDir;
 import org.apache.isis.applib.AbstractService;
 import org.apache.isis.applib.annotation.DomainService;
 
@@ -72,10 +72,86 @@ public class ClassDiscoveryServiceUsingReflections
         final List<Vfs.UrlType> urlTypes = Lists.newArrayList();
         urlTypes.add(new PomUrlType());
         urlTypes.add(new JettyConsoleUrlType());
-        urlTypes.addAll(Arrays.asList(Vfs.DefaultUrlTypes.values()));
+        urlTypes.addAll(Arrays.asList(CustomizedUrlTypes.values()));
+
+
+
+
         return urlTypes;
     }
 
+    /**
+     * Adapted and tweaked from {@link org.reflections.vfs.Vfs.DefaultUrlTypes}.
+     */
+    public static enum CustomizedUrlTypes implements Vfs.UrlType {
+        jarFile {
+            public boolean matches(URL url) {
+                return url.getProtocol().equals("file") && url.toExternalForm().contains(".jar");
+            }
+
+            public Vfs.Dir createDir(final URL url) throws Exception {
+                return new ZipDir(new JarFile(getFile(url)));
+            }
+        },
+
+        jarUrl {
+            public boolean matches(URL url) {
+                return "jar".equals(url.getProtocol());
+            }
+
+            public Vfs.Dir createDir(URL url) throws Exception {
+                URLConnection urlConnection = url.openConnection();
+                return urlConnection instanceof JarURLConnection ?
+                        new ZipDir(((JarURLConnection) urlConnection).getJarFile()) : null;
+            }
+        },
+
+        directory {
+            public boolean matches(URL url) {
+                return url.getProtocol().equals("file") && !url.toExternalForm().contains(".jar") && !url.toExternalForm().contains(".jnilib");
+            }
+
+            public Vfs.Dir createDir(final URL url) throws Exception {
+                return new SystemDir(getFile(url));
+            }
+        }
+    }
+
+    /**try to get {@link java.io.File} from url*/
+    static java.io.File getFile(URL url) {
+        java.io.File file;
+        String path;
+
+        try {
+            path = url.toURI().getSchemeSpecificPart();
+            if ((file = new java.io.File(path)).exists()) return file;
+        } catch (URISyntaxException e) {
+        }
+
+        try {
+            path = URLDecoder.decode(url.getPath(), "UTF-8");
+            if (path.contains(".jar!")) path = path.substring(0, path.lastIndexOf(".jar!") + ".jar".length());
+            if ((file = new java.io.File(path)).exists()) return file;
+
+        } catch (UnsupportedEncodingException e) {
+        }
+
+        try {
+            path = url.toExternalForm();
+            if (path.startsWith("jar:")) path = path.substring("jar:".length());
+            if (path.startsWith("file:")) path = path.substring("file:".length());
+            if (path.contains(".jar!")) path = path.substring(0, path.indexOf(".jar!") + ".jar".length());
+            if ((file = new java.io.File(path)).exists()) return file;
+
+            path = path.replace("%20", " ");
+            if ((file = new java.io.File(path)).exists()) return file;
+
+        } catch (Exception e) {
+        }
+
+        return null;
+    }
+
     private static class PomUrlType implements Vfs.UrlType {
         public boolean matches(URL url) {
             final String protocol = url.getProtocol();