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/07/28 15:28:42 UTC
[04/39] git commit: ISIS-839: fix Reflections discovery of
@DomainService for jetty-console,
remove "harmless" stack traces when running in jetty:run.
ISIS-839: fix Reflections discovery of @DomainService for jetty-console, remove "harmless" stack traces when running in jetty:run.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/4e93d1b8
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/4e93d1b8
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/4e93d1b8
Branch: refs/heads/master
Commit: 4e93d1b875caaa7de6102301bc4435e284e3b125
Parents: d2394b8
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Jul 21 11:11:33 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Jul 21 11:11:33 2014 +0100
----------------------------------------------------------------------
.../ClassDiscoveryServiceUsingReflections.java | 104 ++++++++++++++++++-
.../ServicesInstallerFromAnnotation.java | 3 +
2 files changed, 102 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/4e93d1b8/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 a8b5df2..993319f 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
@@ -18,12 +18,20 @@
*/
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.util.Arrays;
+import java.util.List;
import java.util.Set;
-
+import com.google.common.collect.Lists;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
-
+import org.reflections.util.ConfigurationBuilder;
+import org.reflections.vfs.SystemDir;
+import org.reflections.vfs.Vfs;
import org.apache.isis.applib.AbstractService;
import org.apache.isis.applib.annotation.DomainService;
@@ -42,13 +50,99 @@ public class ClassDiscoveryServiceUsingReflections
extends AbstractService
implements ClassDiscoveryService {
+
@Override
public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type) {
- final Reflections reflections = new Reflections(
- ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
- ClasspathHelper.forClass(Object.class),
+ List<Vfs.UrlType> urlTypes = getUrlTypes();
+ Vfs.setDefaultURLTypes(urlTypes);
+
+ ConfigurationBuilder configuration = ConfigurationBuilder.build(
+ ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
+ ClasspathHelper.forClass(Object.class),
new SubTypesScanner(false));
+ // doesn't seem to do anything
+ // configuration = configuration.filterInputsBy(ignorePom());
+ final Reflections reflections = new Reflections(configuration);
return reflections.getSubTypesOf(type);
}
+ // //////////////////////////////////////
+
+ /**
+ * Has <tt>public</tt> visibility only so can be reused by other services (including Isis runtime itself).
+ */
+ public static List<Vfs.UrlType> getUrlTypes() {
+ final List<Vfs.UrlType> urlTypes = Lists.newArrayList();
+ urlTypes.add(new PomUrlType());
+ urlTypes.add(new JettyConsoleUrlType());
+ urlTypes.addAll(Arrays.asList(Vfs.DefaultUrlTypes.values()));
+ return urlTypes;
+ }
+
+ private static class PomUrlType implements Vfs.UrlType {
+ public boolean matches(URL url) {
+ final String protocol = url.getProtocol();
+ final String externalForm = url.toExternalForm();
+ return protocol.equals("file") && externalForm.endsWith(".pom");
+ }
+
+ public Vfs.Dir createDir(final URL url) throws Exception {
+ return null;
+ }
+ }
+
+ public static class JettyConsoleUrlType implements Vfs.UrlType {
+ public boolean matches(URL url) {
+ final String protocol = url.getProtocol();
+ final String externalForm = url.toExternalForm();
+ final boolean matches = protocol.equals("file") && externalForm.contains("jetty-console") && externalForm.contains("-any-") && externalForm.endsWith("webapp/WEB-INF/classes/");
+ return matches;
+ }
+
+ public Vfs.Dir createDir(final URL url) throws Exception {
+ return new SystemDir(getFile(url));
+ }
+ }
+
+ /**
+ * try to get {@link java.io.File} from url
+ *
+ * <p>
+ * Copied from {@link org.reflections.vfs.Vfs} (not publicly accessible)
+ * </p>
+ */
+ 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;
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/4e93d1b8/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerFromAnnotation.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerFromAnnotation.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerFromAnnotation.java
index 6e091f8..68c187b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerFromAnnotation.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerFromAnnotation.java
@@ -29,9 +29,11 @@ import com.google.common.base.*;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import org.reflections.Reflections;
+import org.reflections.vfs.Vfs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.services.classdiscovery.ClassDiscoveryServiceUsingReflections;
import org.apache.isis.core.commons.config.InstallerAbstract;
import org.apache.isis.core.runtime.system.DeploymentType;
@@ -182,6 +184,7 @@ public class ServicesInstallerFromAnnotation extends InstallerAbstract implement
initIfRequired();
for (final String packagePrefix : Iterables.transform(Splitter.on(",").split(packagePrefixes), trim())) {
+ Vfs.setDefaultURLTypes(ClassDiscoveryServiceUsingReflections.getUrlTypes());
Reflections reflections = new Reflections(packagePrefix);
final Iterable<Class<?>> classes = Iterables.filter(