diff options
18 files changed, 519 insertions, 603 deletions
diff --git a/jetty-annotations/pom.xml b/jetty-annotations/pom.xml index 43cc4584bf..33965ca574 100644 --- a/jetty-annotations/pom.xml +++ b/jetty-annotations/pom.xml @@ -102,8 +102,12 @@ <artifactId>javax.annotation-api</artifactId> </dependency> <dependency> - <groupId>org.eclipse.jetty.orbit</groupId> - <artifactId>org.objectweb.asm</artifactId> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm-commons</artifactId> </dependency> </dependencies> </project> diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AbstractDiscoverableAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AbstractDiscoverableAnnotationHandler.java index a9afd8996a..446e27c566 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AbstractDiscoverableAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AbstractDiscoverableAnnotationHandler.java @@ -21,7 +21,7 @@ package org.eclipse.jetty.annotations; import java.util.ArrayList; import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; +import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.DiscoveredAnnotation; import org.eclipse.jetty.webapp.WebAppContext; @@ -31,7 +31,7 @@ import org.eclipse.jetty.webapp.WebAppContext; * * */ -public abstract class AbstractDiscoverableAnnotationHandler implements DiscoverableAnnotationHandler +public abstract class AbstractDiscoverableAnnotationHandler extends AbstractHandler { protected WebAppContext _context; protected List<DiscoveredAnnotation> _annotations; diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index c26901f73e..133ac3ed9c 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -20,18 +20,14 @@ package org.eclipse.jetty.annotations; import java.net.URI; import java.util.ArrayList; -import java.util.EventListener; import java.util.Iterator; import java.util.List; import java.util.ServiceLoader; -import java.util.StringTokenizer; import javax.servlet.ServletContainerInitializer; import javax.servlet.annotation.HandlesTypes; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; import org.eclipse.jetty.plus.annotation.ContainerInitializer; -import org.eclipse.jetty.util.ArrayUtil; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -55,7 +51,7 @@ public class AnnotationConfiguration extends AbstractConfiguration public static final String CONTAINER_INITIALIZER_LISTENER = "org.eclipse.jetty.containerInitializerListener"; - protected List<DiscoverableAnnotationHandler> _discoverableAnnotationHandlers = new ArrayList<DiscoverableAnnotationHandler>(); + protected List<AbstractDiscoverableAnnotationHandler> _discoverableAnnotationHandlers = new ArrayList<AbstractDiscoverableAnnotationHandler>(); protected ClassInheritanceHandler _classInheritanceHandler; protected List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<ContainerInitializerAnnotationHandler>(); @@ -141,7 +137,7 @@ public class AnnotationConfiguration extends AbstractConfiguration } - public void addDiscoverableAnnotationHandler(DiscoverableAnnotationHandler handler) + public void addDiscoverableAnnotationHandler(AbstractDiscoverableAnnotationHandler handler) { _discoverableAnnotationHandlers.add(handler); } @@ -203,7 +199,7 @@ public class AnnotationConfiguration extends AbstractConfiguration parseWebInfClasses(context, parser); parseWebInfLib (context, parser); - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) context.getMetaData().addDiscoveredAnnotations(((AbstractDiscoverableAnnotationHandler)h).getAnnotationList()); } } @@ -414,7 +410,7 @@ public class AnnotationConfiguration extends AbstractConfiguration //always parse for discoverable annotations as well as class hierarchy and servletcontainerinitializer related annotations parser.clearHandlers(); - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) { if (h instanceof AbstractDiscoverableAnnotationHandler) ((AbstractDiscoverableAnnotationHandler)h).setResource(null); // @@ -482,7 +478,7 @@ public class AnnotationConfiguration extends AbstractConfiguration //only register the discoverable annotation handlers if this fragment is not metadata complete, or has no fragment descriptor if (f == null || !isMetaDataComplete(f)) { - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) { if (h instanceof AbstractDiscoverableAnnotationHandler) ((AbstractDiscoverableAnnotationHandler)h).setResource(r); @@ -508,7 +504,7 @@ public class AnnotationConfiguration extends AbstractConfiguration LOG.debug("Scanning classes in WEB-INF/classes"); parser.clearHandlers(); - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) { if (h instanceof AbstractDiscoverableAnnotationHandler) ((AbstractDiscoverableAnnotationHandler)h).setResource(null); // diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java index 057d0ea22a..3e215c4ba1 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java @@ -25,13 +25,13 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -39,23 +39,43 @@ import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.JarScanner; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.commons.EmptyVisitor; +import org.objectweb.asm.Opcodes; + /** * AnnotationParser * - * Use asm to scan classes for annotations. A SAX-style parsing is done, with - * a handler being able to be registered to handle each annotation type. + * Use asm to scan classes for annotations. A SAX-style parsing is done. + * Handlers are registered which will be called back when various types of + * entity are encountered, eg a class, a method, a field. + * + * Handlers are not called back in any particular order and are assumed + * to be order-independent. + * + * As a registered Handler will be called back for each annotation discovered + * on a class, a method, a field, the Handler should test to see if the annotation + * is one that it is interested in. + * + * For the servlet spec, we are only interested in annotations on classes, methods and fields, + * so the callbacks for handling finding a class, a method a field are themselves + * not fully implemented. */ public class AnnotationParser { private static final Logger LOG = Log.getLogger(AnnotationParser.class); - protected Set<String> _parsedClassNames = new HashSet<String>(); - protected List<Handler> _handlers = new ArrayList<Handler>(); + protected Set<String> _parsedClassNames = new ConcurrentHashSet<String>(); + protected Set<Handler> _handlers = new ConcurrentHashSet<Handler>(); + /** + * Convert internal name to simple name + * + * @param name + * @return + */ public static String normalize (String name) { if (name==null) @@ -69,292 +89,354 @@ public class AnnotationParser return name.replace('/', '.'); } - - - - public abstract class Value + + /** + * Convert internal names to simple names. + * + * @param list + * @return + */ + public static String[] normalize (String[] list) { - String _name; + if (list == null) + return null; + String[] normalList = new String[list.length]; + int i=0; + for (String s : list) + normalList[i++] = normalize(s); + return normalList; + } - public Value (String name) + + /** + * ClassInfo + * + * Immutable information gathered by parsing class header. + * + */ + public class ClassInfo + { + final String _className; + final int _version; + final int _access; + final String _signature; + final String _superName; + final String[] _interfaces; + + public ClassInfo(String className, int version, int access, String signature, String superName, String[] interfaces) { - _name = name; + super(); + _className = className; + _version = version; + _access = access; + _signature = signature; + _superName = superName; + _interfaces = interfaces; } - public String getName() + public String getClassName() { - return _name; + return _className; } - public abstract Object getValue(); - - } - - - - - public class SimpleValue extends Value - { - Object _val; + public int getVersion() + { + return _version; + } - public SimpleValue(String name) + public int getAccess() { - super(name); + return _access; } - public void setValue(Object val) + public String getSignature() { - _val=val; + return _signature; } - @Override - public Object getValue() + + public String getSuperName() { - return _val; + return _superName; } - @Override - public String toString() + public String[] getInterfaces() { - return "("+getName()+":"+_val+")"; + return _interfaces; } } - public class ListValue extends Value - { - List<Value> _val; - - public ListValue (String name) + + /** + * MethodInfo + * + * Immutable information gathered by parsing a method on a class. + */ + public class MethodInfo + { + final String _className; + final String _methodName; + final int _access; + final String _desc; + final String _signature; + final String[] _exceptions; + + public MethodInfo(String className, String methodName, int access, String desc, String signature, String[] exceptions) { - super(name); - _val = new ArrayList<Value>(); + super(); + _className = className; + _methodName = methodName; + _access = access; + _desc = desc; + _signature = signature; + _exceptions = exceptions; } - @Override - public Object getValue() + public String getClassName() { - return _val; + return _className; } - public List<Value> getList() + public String getMethodName() { - return _val; + return _methodName; } - public void addValue (Value v) + public int getAccess() { - _val.add(v); + return _access; } - public int size () + public String getDesc() { - return _val.size(); + return _desc; } - @Override - public String toString() + public String getSignature() { - StringBuffer buff = new StringBuffer(); - buff.append("("); - buff.append(getName()); - buff.append(":"); - for (Value n: _val) - { - buff.append(" "+n.toString()); - } - buff.append(")"); - - return buff.toString(); + return _signature; } - } - - - /** - * Handler - * - * Signature for all handlers that respond to parsing class files. - */ - public interface Handler - { - + public String[] getExceptions() + { + return _exceptions; + } } /** - * DiscoverableAnnotationHandler + * FieldInfo * - * Processes an annotation when it is discovered on a class. + * Immutable information gathered by parsing a field on a class. + * */ - public interface DiscoverableAnnotationHandler extends Handler - { - /** - * Process an annotation that was discovered on a class - * @param className - * @param version - * @param access - * @param signature - * @param superName - * @param interfaces - * @param annotation - * @param values - */ - public void handleClass (String className, int version, int access, - String signature, String superName, String[] interfaces, - String annotation, List<Value>values); + public class FieldInfo + { + final String _className; + final String _fieldName; + final int _access; + final String _fieldType; + final String _signature; + final Object _value; + + public FieldInfo(String className, String fieldName, int access, String fieldType, String signature, Object value) + { + super(); + _className = className; + _fieldName = fieldName; + _access = access; + _fieldType = fieldType; + _signature = signature; + _value = value; + } - /** - * Process an annotation that was discovered on a method - * @param className - * @param methodName - * @param access - * @param desc - * @param signature - * @param exceptions - * @param annotation - * @param values - */ - public void handleMethod (String className, String methodName, int access, - String desc, String signature,String[] exceptions, - String annotation, List<Value>values); + public String getClassName() + { + return _className; + } - - /** - * Process an annotation that was discovered on a field - * @param className - * @param fieldName - * @param access - * @param fieldType - * @param signature - * @param value - * @param annotation - * @param values - */ - public void handleField (String className, String fieldName, int access, - String fieldType, String signature, Object value, - String annotation, List<Value>values); - - - /** - * Get the name of the annotation processed by this handler. Can be null - */ - public String getAnnotationName(); - } + public String getFieldName() + { + return _fieldName; + } + public int getAccess() + { + return _access; + } - - /** - * ClassHandler - * - * Responds to finding a Class - */ - public interface ClassHandler extends Handler - { - public void handle (String className, int version, int access, String signature, String superName, String[] interfaces); - } + public String getFieldType() + { + return _fieldType; + } + public String getSignature() + { + return _signature; + } + + public Object getValue() + { + return _value; + } + } /** - * MethodHandler + * Handler * - * Responds to finding a Method + * Signature for all handlers that respond to parsing class files. */ - public interface MethodHandler extends Handler + public static interface Handler { - public void handle (String className, String methodName, int access, String desc, String signature,String[] exceptions); + public void handle(ClassInfo classInfo); + public void handle(MethodInfo methodInfo); + public void handle (FieldInfo fieldInfo); + public void handle (ClassInfo info, String annotationName); + public void handle (MethodInfo info, String annotationName); + public void handle (FieldInfo info, String annotationName); } - - /** - * FieldHandler - * - * Responds to finding a Field - */ - public interface FieldHandler extends Handler - { - public void handle (String className, String fieldName, int access, String fieldType, String signature, Object value); - } - /** - * MyAnnotationVisitor + * AbstractHandler * - * ASM Visitor for Annotations + * Convenience base class to provide no-ops for all Handler methods. + * */ - public class MyAnnotationVisitor implements AnnotationVisitor + public static abstract class AbstractHandler implements Handler { - List<Value> _annotationValues; - String _annotationName; - public MyAnnotationVisitor (String annotationName, List<Value> values) + @Override + public void handle(ClassInfo classInfo) + { + //no-op + } + + @Override + public void handle(MethodInfo methodInfo) { - _annotationValues = values; - _annotationName = annotationName; + // no-op } - public List<Value> getAnnotationValues() + @Override + public void handle(FieldInfo fieldInfo) { - return _annotationValues; + // no-op + } + + @Override + public void handle(ClassInfo info, String annotationName) + { + // no-op } - /** - * Visit a single-valued (name,value) pair for this annotation - * @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object) - */ @Override - public void visit(String aname, Object avalue) + public void handle(MethodInfo info, String annotationName) { - SimpleValue v = new SimpleValue(aname); - v.setValue(avalue); - _annotationValues.add(v); + // no-op } + @Override + public void handle(FieldInfo info, String annotationName) + { + // no-op + } + } + + + + /** + * MyMethodVisitor + * + * ASM Visitor for parsing a method. We are only interested in the annotations on methods. + */ + public class MyMethodVisitor extends MethodVisitor + { + final MethodInfo _mi; + /** - * Visit a (name,value) pair whose value is another Annotation - * @see org.objectweb.asm.AnnotationVisitor#visitAnnotation(java.lang.String, java.lang.String) + * @param classname + * @param access + * @param name + * @param methodDesc + * @param signature + * @param exceptions */ - @Override - public AnnotationVisitor visitAnnotation(String name, String desc) + public MyMethodVisitor(final String className, + final int access, + final String name, + final String methodDesc, + final String signature, + final String[] exceptions) { - String s = normalize(desc); - ListValue v = new ListValue(s); - _annotationValues.add(v); - MyAnnotationVisitor visitor = new MyAnnotationVisitor(s, v.getList()); - return visitor; + super(Opcodes.ASM4); + _mi = new MethodInfo(className, name, access, methodDesc,signature, exceptions); } + /** - * Visit an array valued (name, value) pair for this annotation - * @see org.objectweb.asm.AnnotationVisitor#visitArray(java.lang.String) + * We are only interested in finding the annotations on methods. + * + * @see org.objectweb.asm.MethodVisitor#visitAnnotation(java.lang.String, boolean) */ @Override - public AnnotationVisitor visitArray(String name) + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - ListValue v = new ListValue(name); - _annotationValues.add(v); - MyAnnotationVisitor visitor = new MyAnnotationVisitor(null, v.getList()); - return visitor; + String annotationName = normalize(desc); + for (Handler h:_handlers) + h.handle(_mi, annotationName); + return null; } + } + + + /** + * MyFieldVisitor + * + * An ASM visitor for parsing Fields. + * We are only interested in visiting annotations on Fields. + * + */ + public class MyFieldVisitor extends FieldVisitor + { + final FieldInfo _fieldInfo; + + /** - * Visit a enum-valued (name,value) pair for this annotation - * @see org.objectweb.asm.AnnotationVisitor#visitEnum(java.lang.String, java.lang.String, java.lang.String) + * @param classname */ - @Override - public void visitEnum(String name, String desc, String value) + public MyFieldVisitor(final String className, + final int access, + final String fieldName, + final String fieldType, + final String signature, + final Object value) { - //TODO + super(Opcodes.ASM4); + _fieldInfo = new FieldInfo(className, fieldName, access, fieldType, signature, value); } + + /** + * Parse an annotation found on a Field. + * + * @see org.objectweb.asm.FieldVisitor#visitAnnotation(java.lang.String, boolean) + */ @Override - public void visitEnd() + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + String annotationName = normalize(desc); + for (Handler h : _handlers) + h.handle(_fieldInfo, annotationName); + + return null; } } - + /** @@ -362,77 +444,55 @@ public class AnnotationParser * * ASM visitor for a class. */ - public class MyClassVisitor extends EmptyVisitor + public class MyClassVisitor extends ClassVisitor { - String _className; - int _access; - String _signature; - String _superName; - String[] _interfaces; - int _version; + + ClassInfo _ci; + + public MyClassVisitor() + { + super(Opcodes.ASM4); + } @Override - public void visit (int version, + public void visit (final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) - { - _className = normalize(name); - _access = access; - _signature = signature; - _superName = superName; - _interfaces = interfaces; - _version = version; - - _parsedClassNames.add(_className); - //call all registered ClassHandlers - String[] normalizedInterfaces = null; - if (interfaces!= null) - { - normalizedInterfaces = new String[interfaces.length]; - int i=0; - for (String s : interfaces) - normalizedInterfaces[i++] = normalize(s); - } + { + _ci = new ClassInfo(normalize(name), version, access, signature, normalize(superName), normalize(interfaces)); + + _parsedClassNames.add(_ci.getClassName()); - for (Handler h : AnnotationParser.this._handlers) - { - if (h instanceof ClassHandler) - { - ((ClassHandler)h).handle(_className, _version, _access, _signature, normalize(_superName), normalizedInterfaces); - } - } + for (Handler h:_handlers) + h.handle(_ci); } + + /** + * Visit an annotation on a Class + * + * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean) + */ @Override public AnnotationVisitor visitAnnotation (String desc, boolean visible) { - MyAnnotationVisitor visitor = new MyAnnotationVisitor(normalize(desc), new ArrayList<Value>()) - { - @Override - public void visitEnd() - { - super.visitEnd(); - - //call all AnnotationHandlers with classname, annotation name + values - for (Handler h : AnnotationParser.this._handlers) - { - if (h instanceof DiscoverableAnnotationHandler) - { - DiscoverableAnnotationHandler dah = (DiscoverableAnnotationHandler)h; - if (_annotationName.equalsIgnoreCase(dah.getAnnotationName())) - dah.handleClass(_className, _version, _access, _signature, _superName, _interfaces, _annotationName, _annotationValues); - } - } - } - }; + String annotationName = normalize(desc); + for (Handler h : _handlers) + h.handle(_ci, annotationName); - return visitor; + return null; } + + /** + * Visit a method to extract its annotations + * + * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[]) + */ @Override public MethodVisitor visitMethod (final int access, final String name, @@ -441,35 +501,14 @@ public class AnnotationParser final String[] exceptions) { - return new EmptyVisitor () - { - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - MyAnnotationVisitor visitor = new MyAnnotationVisitor (normalize(desc), new ArrayList<Value>()) - { - @Override - public void visitEnd() - { - super.visitEnd(); - //call all AnnotationHandlers with classname, method, annotation name + values - for (Handler h : AnnotationParser.this._handlers) - { - if (h instanceof DiscoverableAnnotationHandler) - { - DiscoverableAnnotationHandler dah = (DiscoverableAnnotationHandler)h; - if (_annotationName.equalsIgnoreCase(dah.getAnnotationName())) - dah.handleMethod(_className, name, access, methodDesc, signature, exceptions, _annotationName, _annotationValues); - } - } - } - }; - - return visitor; - } - }; + return new MyMethodVisitor(_ci.getClassName(), access, name, methodDesc, signature, exceptions); } + /** + * Visit a field to extract its annotations + * + * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object) + */ @Override public FieldVisitor visitField (final int access, final String fieldName, @@ -477,99 +516,11 @@ public class AnnotationParser final String signature, final Object value) { - - return new EmptyVisitor () - { - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - MyAnnotationVisitor visitor = new MyAnnotationVisitor(normalize(desc), new ArrayList<Value>()) - { - @Override - public void visitEnd() - { - super.visitEnd(); - for (Handler h : AnnotationParser.this._handlers) - { - if (h instanceof DiscoverableAnnotationHandler) - { - DiscoverableAnnotationHandler dah = (DiscoverableAnnotationHandler)h; - if (_annotationName.equalsIgnoreCase(dah.getAnnotationName())) - dah.handleField(_className, fieldName, access, fieldType, signature, value, _annotationName, _annotationValues); - } - } - } - }; - return visitor; - } - }; + return new MyFieldVisitor(_ci.getClassName(), access, fieldName, fieldType, signature, value); } } - - /** - * Register a handler that will be called back when the named annotation is - * encountered on a class. - * - * @deprecated see {@link #registerHandler(Handler)} - * @param annotationName - * @param handler - */ - @Deprecated - public void registerAnnotationHandler (String annotationName, DiscoverableAnnotationHandler handler) - { - _handlers.add(handler); - } - - - /** - * @deprecated no replacement provided - * @param annotationName - */ - @Deprecated - public List<DiscoverableAnnotationHandler> getAnnotationHandlers(String annotationName) - { - List<DiscoverableAnnotationHandler> handlers = new ArrayList<DiscoverableAnnotationHandler>(); - for (Handler h:_handlers) - { - if (h instanceof DiscoverableAnnotationHandler) - { - DiscoverableAnnotationHandler dah = (DiscoverableAnnotationHandler)h; - if (annotationName.equals(dah.getAnnotationName())) - handlers.add(dah); - } - } - return handlers; - } - - /** - * @deprecated no replacement available - */ - @Deprecated - public List<DiscoverableAnnotationHandler> getAnnotationHandlers() - { - List<DiscoverableAnnotationHandler> allAnnotationHandlers = new ArrayList<DiscoverableAnnotationHandler>(); - for (Handler h:_handlers) - { - if (h instanceof DiscoverableAnnotationHandler) - allAnnotationHandlers.add((DiscoverableAnnotationHandler)h); - } - return allAnnotationHandlers; - } - - /** - * @deprecated see {@link #registerHandler(Handler)} - * @param handler - */ - @Deprecated - public void registerClassHandler (ClassHandler handler) - { - _handlers.add(handler); - } - - - /** * Add a particular handler * diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java index 50892a851a..42f8d8021b 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java @@ -20,7 +20,8 @@ package org.eclipse.jetty.annotations; import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.ClassHandler; +import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -30,7 +31,7 @@ import org.eclipse.jetty.util.log.Logger; * * As asm scans for classes, remember the type hierarchy. */ -public class ClassInheritanceHandler implements ClassHandler +public class ClassInheritanceHandler extends AbstractHandler { private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class); @@ -46,17 +47,17 @@ public class ClassInheritanceHandler implements ClassHandler _inheritanceMap = map; } - public void handle(String className, int version, int access, String signature, String superName, String[] interfaces) + public void handle(ClassInfo classInfo) { try { - for (int i=0; interfaces != null && i<interfaces.length;i++) + for (int i=0; classInfo.getInterfaces() != null && i < classInfo.getInterfaces().length;i++) { - _inheritanceMap.add (interfaces[i], className); + _inheritanceMap.add (classInfo.getInterfaces()[i], classInfo.getClassName()); } //To save memory, we don't record classes that only extend Object, as that can be assumed - if (!"java.lang.Object".equals(superName)) - _inheritanceMap.add(superName, className); + if (!"java.lang.Object".equals(classInfo.getSuperName())) + _inheritanceMap.add(classInfo.getSuperName(), classInfo.getClassName()); } catch (Exception e) { diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ContainerInitializerAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ContainerInitializerAnnotationHandler.java index 4ce68e27ab..dbe75996e6 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ContainerInitializerAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ContainerInitializerAnnotationHandler.java @@ -19,10 +19,11 @@ package org.eclipse.jetty.annotations; -import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.plus.annotation.ContainerInitializer; /** @@ -32,7 +33,11 @@ import org.eclipse.jetty.plus.annotation.ContainerInitializer; * method level. The specified annotation is derived from an @HandlesTypes on * a ServletContainerInitializer class. */ -public class ContainerInitializerAnnotationHandler implements DiscoverableAnnotationHandler +/** + * @author janb + * + */ +public class ContainerInitializerAnnotationHandler extends AbstractHandler { ContainerInitializer _initializer; Class _annotation; @@ -45,35 +50,43 @@ public class ContainerInitializerAnnotationHandler implements DiscoverableAnnota /** * Handle finding a class that is annotated with the annotation we were constructed with. - * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List) - */ - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName, - List<Value> values) + * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(ClassInfo) + * */ + public void handle(ClassInfo info, String annotationName) { - _initializer.addAnnotatedTypeName(className); + if (annotationName == null || !_annotation.getName().equals(annotationName)) + return; + + _initializer.addAnnotatedTypeName(info.getClassName()); } - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - _initializer.addAnnotatedTypeName(className); + /** + * Handle finding a field that is annotated with the annotation we were constructed with. + * + * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(org.eclipse.jetty.annotations.AnnotationParser.FieldAnnotationInfo) + */ + public void handle(FieldInfo info, String annotationName) + { + if (annotationName == null || !_annotation.getName().equals(annotationName)) + return; + _initializer.addAnnotatedTypeName(info.getClassName()); } - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) + /** + * Handle finding a method that is annotated with the annotation we were constructed with. + * + * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(org.eclipse.jetty.annotations.AnnotationParser.MethodAnnotationInfo) + */ + public void handle(MethodInfo info, String annotationName) { - _initializer.addAnnotatedTypeName(className); + if (annotationName == null || !_annotation.getName().equals(annotationName)) + return; + _initializer.addAnnotatedTypeName(info.getClassName()); } - @Override - public String getAnnotationName() - { - return _annotation.getName(); - } public ContainerInitializer getContainerInitializer() { return _initializer; } - } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java index 6b4a6382ed..c80257f752 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java @@ -23,7 +23,6 @@ import java.util.List; import javax.servlet.Servlet; import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.Value; import org.eclipse.jetty.plus.annotation.RunAsCollection; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.log.Log; @@ -87,14 +86,12 @@ public class RunAsAnnotationHandler extends AbstractIntrospectableAnnotationHand } - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) + public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation) { LOG.warn ("@RunAs annotation not applicable for fields: "+className+"."+fieldName); } - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) + public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation) { LOG.warn("@RunAs annotation ignored on method: "+className+"."+methodName+" "+signature); } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotationHandler.java index 1545977937..356199ad97 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotationHandler.java @@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations; import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.DiscoveredAnnotation; @@ -46,31 +48,28 @@ public class WebFilterAnnotationHandler extends AbstractDiscoverableAnnotationHa } @Override - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) + public void handle(ClassInfo info, String annotationName) { - WebFilterAnnotation wfAnnotation = new WebFilterAnnotation(_context, className, _resource); + if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName)) + return; + + WebFilterAnnotation wfAnnotation = new WebFilterAnnotation(_context, info.getClassName(), _resource); addAnnotation(wfAnnotation); } @Override - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - LOG.warn ("@WebFilter not applicable for fields: "+className+"."+fieldName); + public void handle(FieldInfo info, String annotationName) + { + if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName)) + return; + LOG.warn ("@WebFilter not applicable for fields: "+info.getClassName()+"."+info.getFieldName()); } @Override - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) - { - LOG.warn ("@WebFilter not applicable for methods: "+className+"."+methodName+" "+signature); + public void handle(MethodInfo info, String annotationName) + { + if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName)) + return; + LOG.warn ("@WebFilter not applicable for methods: "+info.getClassName()+"."+info.getMethodName()+" "+info.getSignature()); } - - @Override - public String getAnnotationName() - { - return "javax.servlet.annotation.WebFilter"; - } - } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebListenerAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebListenerAnnotationHandler.java index ab1670230a..81df82f4b7 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebListenerAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebListenerAnnotationHandler.java @@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations; import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.DiscoveredAnnotation; @@ -41,31 +43,28 @@ public class WebListenerAnnotationHandler extends AbstractDiscoverableAnnotation } /** - * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List) + * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(ClassAnnotationInfo) */ - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) + public void handle(ClassInfo info, String annotationName) { - WebListenerAnnotation wlAnnotation = new WebListenerAnnotation(_context, className, _resource); + if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName)) + return; + + WebListenerAnnotation wlAnnotation = new WebListenerAnnotation(_context, info.getClassName(), _resource); addAnnotation(wlAnnotation); } - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) + public void handle(FieldInfo info, String annotationName) { - LOG.warn ("@WebListener is not applicable to fields: "+className+"."+fieldName); + if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName)) + return; + LOG.warn ("@WebListener is not applicable to fields: "+info.getClassName()+"."+info.getFieldName()); } - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) + public void handle(MethodInfo info, String annotationName) { - LOG.warn ("@WebListener is not applicable to methods: "+className+"."+methodName+" "+signature); + if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName)) + return; + LOG.warn ("@WebListener is not applicable to methods: "+info.getClassName()+"."+info.getMethodName()+" "+info.getSignature()); } - - @Override - public String getAnnotationName() - { - return "javax.servlet.annotation.WebListener"; - } - } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotationHandler.java index 65227734de..67fee21926 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotationHandler.java @@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations; import java.util.List; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.DiscoveredAnnotation; @@ -54,34 +56,30 @@ public class WebServletAnnotationHandler extends AbstractDiscoverableAnnotationH * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List) */ @Override - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName, - List<Value> values) + public void handle(ClassInfo info, String annotationName) { - if (!"javax.servlet.annotation.WebServlet".equals(annotationName)) + if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName)) return; - - WebServletAnnotation annotation = new WebServletAnnotation (_context, className, _resource); + + WebServletAnnotation annotation = new WebServletAnnotation (_context, info.getClassName(), _resource); addAnnotation(annotation); } @Override - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) + public void handle(FieldInfo info, String annotationName) { + if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName)) + return; + LOG.warn ("@WebServlet annotation not supported for fields"); } @Override - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) + public void handle(MethodInfo info, String annotationName) { + if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName)) + return; + LOG.warn ("@WebServlet annotation not supported for methods"); } - - - @Override - public String getAnnotationName() - { - return "javax.servlet.annotation.WebServlet"; - } } diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java index b589f3da5c..ce668d015c 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java @@ -30,8 +30,10 @@ import java.util.Map; import javax.naming.Context; import javax.naming.InitialContext; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.util.MultiMap; import org.junit.After; import org.junit.Test; @@ -44,34 +46,32 @@ public class TestAnnotationInheritance List<String> classNames = new ArrayList<String>(); - class SampleHandler implements DiscoverableAnnotationHandler + class SampleHandler extends AbstractHandler { public final List<String> annotatedClassNames = new ArrayList<String>(); public final List<String> annotatedMethods = new ArrayList<String>(); public final List<String> annotatedFields = new ArrayList<String>(); - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) + public void handle(ClassInfo info, String annotation) { - annotatedClassNames.add(className); + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + + annotatedClassNames.add(info.getClassName()); } - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - annotatedFields.add(className+"."+fieldName); + public void handle(FieldInfo info, String annotation) + { + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + annotatedFields.add(info.getClassName()+"."+info.getFieldName()); } - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) - { - annotatedMethods.add(className+"."+methodName); - } - - @Override - public String getAnnotationName() + public void handle(MethodInfo info, String annotation) { - return "org.eclipse.jetty.annotations.Sample"; + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + annotatedMethods.add(info.getClassName()+"."+info.getMethodName()); } } @@ -129,7 +129,7 @@ public class TestAnnotationInheritance { SampleHandler handler = new SampleHandler(); AnnotationParser parser = new AnnotationParser(); - parser.registerAnnotationHandler("org.eclipse.jetty.annotations.Sample", handler); + parser.registerHandler(handler); parser.parse(ClassB.class, new ClassNameResolver () { public boolean isExcluded(String name) @@ -166,7 +166,7 @@ public class TestAnnotationInheritance { AnnotationParser parser = new AnnotationParser(); SampleHandler handler = new SampleHandler(); - parser.registerAnnotationHandler("org.eclipse.jetty.annotations.Sample", handler); + parser.registerHandler(handler); parser.parse(ClassA.class.getName(), new ClassNameResolver() { public boolean isExcluded(String name) @@ -207,7 +207,7 @@ public class TestAnnotationInheritance { AnnotationParser parser = new AnnotationParser(); ClassInheritanceHandler handler = new ClassInheritanceHandler(); - parser.registerClassHandler(handler); + parser.registerHandler(handler); class Foo implements InterfaceD { diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationParser.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationParser.java index 6e56a0def1..a0142d4fcc 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationParser.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationParser.java @@ -18,8 +18,11 @@ package org.eclipse.jetty.annotations; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.FileOutputStream; @@ -32,20 +35,20 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; +import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; +import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.TestingDir; import org.junit.Assert; import org.junit.Rule; -import org.junit.Rule; import org.junit.Test; public class TestAnnotationParser { - public static class TrackingAnnotationHandler implements DiscoverableAnnotationHandler + public static class TrackingAnnotationHandler extends AnnotationParser.AbstractHandler { private final String annotationName; public final Set<String> foundClasses; @@ -57,30 +60,11 @@ public class TestAnnotationParser } @Override - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) - { - foundClasses.add(className); - } - - @Override - public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation, - List<Value> values) - { - /* ignore */ - } - - @Override - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - /* ignore */ - } - - @Override - public String getAnnotationName() + public void handle(ClassInfo info, String annotation) { - return this.annotationName; + if (annotation == null || !annotationName.equals(annotation)) + return; + foundClasses.add(info.getClassName()); } } @@ -94,40 +78,33 @@ public class TestAnnotationParser { "org.eclipse.jetty.annotations.ClassA" }; AnnotationParser parser = new AnnotationParser(); - class SampleAnnotationHandler implements DiscoverableAnnotationHandler + class SampleAnnotationHandler extends AnnotationParser.AbstractHandler { private List<String> methods = Arrays.asList("a","b","c","d","l"); - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) + public void handle(ClassInfo info, String annotation) { - assertEquals("org.eclipse.jetty.annotations.ClassA",className); - } - - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - assertEquals("m",fieldName); - assertEquals(org.objectweb.asm.Type.OBJECT,org.objectweb.asm.Type.getType(fieldType).getSort()); - assertEquals(1,values.size()); - Value anv1 = values.get(0); - assertEquals("value",anv1.getName()); - assertEquals(7,anv1.getValue()); + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassName()); } - public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation, - List<Value> values) - { - assertEquals("org.eclipse.jetty.annotations.ClassA",className); - assertTrue(methods.contains(methodName)); - assertEquals("org.eclipse.jetty.annotations.Sample",annotation); + public void handle(FieldInfo info, String annotation) + { + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + assertEquals("m",info.getFieldName()); + assertEquals(org.objectweb.asm.Type.OBJECT,org.objectweb.asm.Type.getType(info.getFieldType()).getSort()); } - @Override - public String getAnnotationName() - { - return "org.eclipse.jetty.annotations.Sample"; + public void handle(MethodInfo info, String annotation) + { + if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation)) + return; + assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassName()); + assertTrue(methods.contains(info.getMethodName())); + assertEquals("org.eclipse.jetty.annotations.Sample",annotation); } } @@ -159,34 +136,30 @@ public class TestAnnotationParser { "org.eclipse.jetty.annotations.ClassB" }; AnnotationParser parser = new AnnotationParser(); - class MultiAnnotationHandler implements DiscoverableAnnotationHandler + class MultiAnnotationHandler extends AnnotationParser.AbstractHandler { - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation, - List<Value> values) + public void handle(ClassInfo info, String annotation) { - assertTrue("org.eclipse.jetty.annotations.ClassB".equals(className)); + if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation)) + return; + assertTrue("org.eclipse.jetty.annotations.ClassB".equals(info.getClassName())); } - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { + public void handle(FieldInfo info, String annotation) + { + if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation)) + return; // there should not be any fail(); } - public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation, - List<Value> values) - { - assertTrue("org.eclipse.jetty.annotations.ClassB".equals(className)); - assertTrue("a".equals(methodName)); - } - - @Override - public String getAnnotationName() - { - return "org.eclipse.jetty.annotations.Multi"; + public void handle(MethodInfo info, String annotation) + { + if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation)) + return; + assertTrue("org.eclipse.jetty.annotations.ClassB".equals(info.getClassName())); + assertTrue("a".equals(info.getMethodName())); } - } parser.registerHandler(new MultiAnnotationHandler()); diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java index b407dc852d..dd80616d6c 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java @@ -50,7 +50,7 @@ public class TestServletAnnotations WebAppContext wac = new WebAppContext(); WebServletAnnotationHandler handler = new WebServletAnnotationHandler(wac); - parser.registerAnnotationHandler("javax.servlet.annotation.WebServlet", handler); + parser.registerHandler(handler); parser.parse(classes, new ClassNameResolver () { diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index 901b55ccf8..371d01dc7b 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -399,8 +399,8 @@ <goal>copy-dependencies</goal> </goals> <configuration> - <includeGroupIds>javax.annotation,org.eclipse.jetty.orbit</includeGroupIds> - <includeArtifactIds>javax.annotation-api,org.objectweb.asm</includeArtifactIds> + <includeGroupIds>javax.annotation,org.eclipse.jetty.orbit,org.ow2.asm</includeGroupIds> + <includeArtifactIds>javax.annotation-api,asm,asm-commons</includeArtifactIds> <includeTypes>jar</includeTypes> <outputDirectory>${assembly-directory}/lib/annotations</outputDirectory> </configuration> @@ -543,10 +543,6 @@ </dependency> <dependency> <groupId>org.eclipse.jetty.orbit</groupId> - <artifactId>org.objectweb.asm</artifactId> - </dependency> - <dependency> - <groupId>org.eclipse.jetty.orbit</groupId> <artifactId>javax.activation</artifactId> </dependency> <dependency> @@ -579,6 +575,15 @@ <artifactId>javax.el</artifactId> </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm-commons</artifactId> + </dependency> + <!-- jetty deps --> <dependency> <groupId>org.eclipse.jetty</groupId> diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java index 8d5b502a4c..c61dc1581a 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java @@ -23,7 +23,6 @@ import java.io.File; import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler; import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.annotations.AnnotationParser; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; import org.eclipse.jetty.annotations.ClassNameResolver; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -52,7 +51,7 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration throw new IllegalStateException ("No metadata"); parser.clearHandlers(); - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) { if (h instanceof AbstractDiscoverableAnnotationHandler) ((AbstractDiscoverableAnnotationHandler)h).setResource(null); // diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java index b4ae909819..4b15ae5b9d 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java @@ -18,16 +18,11 @@ package org.eclipse.jetty.osgi.annotations; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler; import org.eclipse.jetty.annotations.ClassNameResolver; import org.eclipse.jetty.osgi.boot.OSGiWebappConstants; import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker; import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.webapp.DiscoveredAnnotation; import org.eclipse.jetty.webapp.WebAppContext; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; @@ -157,7 +152,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot Resource bundleRes = parser.getResource(bundle); parser.clearHandlers(); - for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) + for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers) { if (h instanceof AbstractDiscoverableAnnotationHandler) { diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerEndpointAnnotationHandler.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerEndpointAnnotationHandler.java index 7b97671e45..47d8086c51 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerEndpointAnnotationHandler.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerEndpointAnnotationHandler.java @@ -23,7 +23,7 @@ import java.util.List; import javax.websocket.server.ServerEndpoint; import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler; -import org.eclipse.jetty.annotations.AnnotationParser.Value; +import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.DiscoveredAnnotation; @@ -47,19 +47,13 @@ public class ServerEndpointAnnotationHandler extends AbstractDiscoverableAnnotat super(context,list); } - @Override - public String getAnnotationName() - { - return ANNOTATION_NAME; - } @Override - public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName, - List<Value> values) + public void handle(ClassInfo info, String annotationName) { if (LOG.isDebugEnabled()) { - LOG.debug("handleClass: {}, {}, {}",className,annotationName,values); + LOG.debug("handleClass: {}, {}, {}",info.getClassName(),annotationName); } if (!ANNOTATION_NAME.equals(annotationName)) @@ -68,21 +62,7 @@ public class ServerEndpointAnnotationHandler extends AbstractDiscoverableAnnotat return; } - ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,className,_resource); + ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,info.getClassName(),_resource); addAnnotation(annotation); } - - @Override - public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation, - List<Value> values) - { - /* @ServerEndpoint annotation not supported for fields */ - } - - @Override - public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation, - List<Value> values) - { - /* @ServerEndpoint annotation not supported for methods */ - } } @@ -467,10 +467,16 @@ <version>1.2</version> </dependency> <dependency> - <groupId>org.eclipse.jetty.orbit</groupId> - <artifactId>org.objectweb.asm</artifactId> - <version>3.1.0.v200803061910</version> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + <version>4.1</version> + </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm-commons</artifactId> + <version>4.1</version> </dependency> + <dependency> <groupId>org.eclipse.jetty.orbit</groupId> <artifactId>javax.security.auth.message</artifactId> |