From: patriot1burke Date: Mon, 11 Feb 2008 22:05:27 +0000 (+0000) Subject: reapath must be used to determine WEB-INF/classes X-Git-Tag: scannotation-1.0.4~6 X-Git-Url: https://juplo.de/gitweb/?p=scannotation;a=commitdiff_plain;h=ef4ea99491aa96637db0c580e938724a68dd6e15 reapath must be used to determine WEB-INF/classes --- diff --git a/pom.xml b/pom.xml index 1c1141b..027958f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scannotation scannotation jar - 1.0.1 + 1.0.2 scannotation http://maven.apache.org diff --git a/src/main/java/org/scannotation/AnnotationDB.java b/src/main/java/org/scannotation/AnnotationDB.java index 92e28c6..6eb4afe 100644 --- a/src/main/java/org/scannotation/AnnotationDB.java +++ b/src/main/java/org/scannotation/AnnotationDB.java @@ -28,11 +28,11 @@ import java.util.Set; * The class allows you to scan an arbitrary set of "archives" for .class files. These class files * are parsed to see what annotations they use. Two indexes are created. The javax, java, sun, com.sun, and javassist * packages will not be scanned by default. - * + *

* One is a map of annotations and what classes * use those annotations. This could be used, for example, by an EJB deployer to find all the EJBs contained * in the archive - * + *

* Another is a mpa of classes and what annotations those classes use. * * @author Bill Burke @@ -92,16 +92,13 @@ public class AnnotationDB implements Serializable * This method will cross reference annotations in the annotation index with any meta-annotations that they have * and create additional entries as needed. For example: * - * @HttpMethod("GET") - * public @interface GET {} - * + * @HttpMethod("GET") public @interface GET {} + *

* The HttpMethod index will have additional classes added to it for any classes annotated with annotations that * have the HttpMethod meta-annotation. - * + *

* WARNING: If the annotation class has not already been scaned, this method will load all annotation classes indexed - * as a resource so they must be in your classpath - * - * + * as a resource so they must be in your classpath */ public void crossReferenceMetaAnnotations() throws CrossReferenceException { @@ -142,7 +139,7 @@ public class AnnotationDB implements Serializable { annotationIndex.get(xref).addAll(annotationIndex.get(annotation)); } - + } if (unresolved.size() > 0) throw new CrossReferenceException(unresolved); } @@ -171,12 +168,19 @@ public class AnnotationDB implements Serializable { unresolved.add(intf); } - Set classAnnotations = classIndex.get(clazz); - classAnnotations.addAll(xrefAnnotations); - for (String annotation : xrefAnnotations) + else { - Set classes = annotationIndex.get(annotation); - classes.add(clazz); + Set classAnnotations = classIndex.get(clazz); + if (classAnnotations == null) + { + classIndex.put(clazz, xrefAnnotations); + } + else classAnnotations.addAll(xrefAnnotations); + for (String annotation : xrefAnnotations) + { + Set classes = annotationIndex.get(annotation); + classes.add(clazz); + } } } } @@ -190,7 +194,7 @@ public class AnnotationDB implements Serializable { if (intf.startsWith(ignored + ".")) { - return true; + return true; } else { @@ -203,7 +207,6 @@ public class AnnotationDB implements Serializable /** * returns a map keyed by the fully qualified string name of a annotation class. The Set returne is * a list of classes that use that annotation somehow. - * */ public Map> getAnnotationIndex() { @@ -213,7 +216,6 @@ public class AnnotationDB implements Serializable /** * returns a map keyed by the list of classes scanned. The value set returned is a list of annotations * used by that class. - * */ public Map> getClassIndex() { @@ -262,7 +264,6 @@ public class AnnotationDB implements Serializable } - /** * Scan a url that represents an "archive" this is a classpath directory or jar file * diff --git a/src/main/java/org/scannotation/WarUrlFinder.java b/src/main/java/org/scannotation/WarUrlFinder.java index f253764..a158c3c 100644 --- a/src/main/java/org/scannotation/WarUrlFinder.java +++ b/src/main/java/org/scannotation/WarUrlFinder.java @@ -6,6 +6,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Set; +import java.io.File; /** * @author Bill Burke @@ -48,27 +49,21 @@ public class WarUrlFinder * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory * * @param servletContext - * @return + * @return null if cannot determin /WEB-INF/classes */ public static URL findWebInfClassesPath(ServletContext servletContext) { - Set libJars = servletContext.getResourcePaths("/WEB-INF/classes"); - for (Object jar : libJars) + String path = servletContext.getRealPath("/WEB-INF/classes"); + if (path == null) return null; + File fp = new File(path); + if (fp.exists() == false) return null; + try { - try - { - URL url = servletContext.getResource((String) jar); - String urlString = url.toString(); - int index = urlString.lastIndexOf("/WEB-INF/classes/"); - urlString = urlString.substring(0, index + "/WEB-INF/classes/".length()); - return new URL(urlString); - } - catch (MalformedURLException e) - { - throw new RuntimeException(e); - } + return fp.toURL(); + } + catch (MalformedURLException e) + { + throw new RuntimeException(e); } - return null; - } }