417382 - Upgrade to asm 4.1 and refactor annotation parsing
This commit is contained in:
parent
6594ee87fa
commit
f44787075a
|
@ -102,8 +102,12 @@
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>org.objectweb.asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.eclipse.jetty.annotations;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.util.resource.Resource;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
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 WebAppContext _context;
|
||||||
protected List<DiscoveredAnnotation> _annotations;
|
protected List<DiscoveredAnnotation> _annotations;
|
||||||
|
|
|
@ -20,18 +20,14 @@ package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EventListener;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContainerInitializer;
|
import javax.servlet.ServletContainerInitializer;
|
||||||
import javax.servlet.annotation.HandlesTypes;
|
import javax.servlet.annotation.HandlesTypes;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
|
||||||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||||
import org.eclipse.jetty.util.ArrayUtil;
|
|
||||||
import org.eclipse.jetty.util.MultiMap;
|
import org.eclipse.jetty.util.MultiMap;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
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";
|
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 ClassInheritanceHandler _classInheritanceHandler;
|
||||||
protected List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<ContainerInitializerAnnotationHandler>();
|
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);
|
_discoverableAnnotationHandlers.add(handler);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +199,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
parseWebInfClasses(context, parser);
|
parseWebInfClasses(context, parser);
|
||||||
parseWebInfLib (context, parser);
|
parseWebInfLib (context, parser);
|
||||||
|
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
context.getMetaData().addDiscoveredAnnotations(((AbstractDiscoverableAnnotationHandler)h).getAnnotationList());
|
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
|
//always parse for discoverable annotations as well as class hierarchy and servletcontainerinitializer related annotations
|
||||||
parser.clearHandlers();
|
parser.clearHandlers();
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
((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
|
//only register the discoverable annotation handlers if this fragment is not metadata complete, or has no fragment descriptor
|
||||||
if (f == null || !isMetaDataComplete(f))
|
if (f == null || !isMetaDataComplete(f))
|
||||||
{
|
{
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||||
((AbstractDiscoverableAnnotationHandler)h).setResource(r);
|
((AbstractDiscoverableAnnotationHandler)h).setResource(r);
|
||||||
|
@ -508,7 +504,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
LOG.debug("Scanning classes in WEB-INF/classes");
|
LOG.debug("Scanning classes in WEB-INF/classes");
|
||||||
|
|
||||||
parser.clearHandlers();
|
parser.clearHandlers();
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||||
|
|
|
@ -25,13 +25,13 @@ import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.ConcurrentHashSet;
|
||||||
import org.eclipse.jetty.util.Loader;
|
import org.eclipse.jetty.util.Loader;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
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.eclipse.jetty.webapp.JarScanner;
|
||||||
import org.objectweb.asm.AnnotationVisitor;
|
import org.objectweb.asm.AnnotationVisitor;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
import org.objectweb.asm.FieldVisitor;
|
import org.objectweb.asm.FieldVisitor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.commons.EmptyVisitor;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AnnotationParser
|
* AnnotationParser
|
||||||
*
|
*
|
||||||
* Use asm to scan classes for annotations. A SAX-style parsing is done, with
|
* Use asm to scan classes for annotations. A SAX-style parsing is done.
|
||||||
* a handler being able to be registered to handle each annotation type.
|
* 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
|
public class AnnotationParser
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(AnnotationParser.class);
|
private static final Logger LOG = Log.getLogger(AnnotationParser.class);
|
||||||
|
|
||||||
protected Set<String> _parsedClassNames = new HashSet<String>();
|
protected Set<String> _parsedClassNames = new ConcurrentHashSet<String>();
|
||||||
protected List<Handler> _handlers = new ArrayList<Handler>();
|
protected Set<Handler> _handlers = new ConcurrentHashSet<Handler>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert internal name to simple name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static String normalize (String name)
|
public static String normalize (String name)
|
||||||
{
|
{
|
||||||
if (name==null)
|
if (name==null)
|
||||||
|
@ -70,287 +90,349 @@ public class AnnotationParser
|
||||||
return name.replace('/', '.');
|
return name.replace('/', '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert internal names to simple names.
|
||||||
public abstract class Value
|
*
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String[] normalize (String[] list)
|
||||||
{
|
{
|
||||||
String _name;
|
if (list == null)
|
||||||
|
return null;
|
||||||
public Value (String name)
|
String[] normalList = new String[list.length];
|
||||||
{
|
int i=0;
|
||||||
_name = name;
|
for (String s : list)
|
||||||
|
normalList[i++] = normalize(s);
|
||||||
|
return normalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
|
||||||
|
/**
|
||||||
|
* ClassInfo
|
||||||
|
*
|
||||||
|
* Immutable information gathered by parsing class header.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ClassInfo
|
||||||
{
|
{
|
||||||
return _name;
|
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)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
_className = className;
|
||||||
|
_version = version;
|
||||||
|
_access = access;
|
||||||
|
_signature = signature;
|
||||||
|
_superName = superName;
|
||||||
|
_interfaces = interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Object getValue();
|
public String getClassName()
|
||||||
|
{
|
||||||
|
return _className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion()
|
||||||
|
{
|
||||||
|
return _version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAccess()
|
||||||
|
{
|
||||||
|
return _access;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignature()
|
||||||
|
{
|
||||||
|
return _signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuperName()
|
||||||
|
{
|
||||||
|
return _superName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getInterfaces()
|
||||||
|
{
|
||||||
|
return _interfaces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
_className = className;
|
||||||
|
_methodName = methodName;
|
||||||
|
_access = access;
|
||||||
|
_desc = desc;
|
||||||
|
_signature = signature;
|
||||||
|
_exceptions = exceptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName()
|
||||||
|
{
|
||||||
|
return _className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethodName()
|
||||||
|
{
|
||||||
|
return _methodName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAccess()
|
||||||
|
{
|
||||||
|
return _access;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc()
|
||||||
|
{
|
||||||
|
return _desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignature()
|
||||||
|
{
|
||||||
|
return _signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getExceptions()
|
||||||
|
{
|
||||||
|
return _exceptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
public class SimpleValue extends Value
|
* FieldInfo
|
||||||
|
*
|
||||||
|
* Immutable information gathered by parsing a field on a class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class FieldInfo
|
||||||
{
|
{
|
||||||
Object _val;
|
final String _className;
|
||||||
|
final String _fieldName;
|
||||||
|
final int _access;
|
||||||
|
final String _fieldType;
|
||||||
|
final String _signature;
|
||||||
|
final Object _value;
|
||||||
|
|
||||||
public SimpleValue(String name)
|
public FieldInfo(String className, String fieldName, int access, String fieldType, String signature, Object value)
|
||||||
{
|
{
|
||||||
super(name);
|
super();
|
||||||
|
_className = className;
|
||||||
|
_fieldName = fieldName;
|
||||||
|
_access = access;
|
||||||
|
_fieldType = fieldType;
|
||||||
|
_signature = signature;
|
||||||
|
_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(Object val)
|
public String getClassName()
|
||||||
{
|
{
|
||||||
_val=val;
|
return _className;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
|
public String getFieldName()
|
||||||
|
{
|
||||||
|
return _fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAccess()
|
||||||
|
{
|
||||||
|
return _access;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldType()
|
||||||
|
{
|
||||||
|
return _fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignature()
|
||||||
|
{
|
||||||
|
return _signature;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getValue()
|
public Object getValue()
|
||||||
{
|
{
|
||||||
return _val;
|
return _value;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "("+getName()+":"+_val+")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ListValue extends Value
|
|
||||||
{
|
|
||||||
List<Value> _val;
|
|
||||||
|
|
||||||
public ListValue (String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
_val = new ArrayList<Value>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getValue()
|
|
||||||
{
|
|
||||||
return _val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Value> getList()
|
|
||||||
{
|
|
||||||
return _val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addValue (Value v)
|
|
||||||
{
|
|
||||||
_val.add(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size ()
|
|
||||||
{
|
|
||||||
return _val.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuffer buff = new StringBuffer();
|
|
||||||
buff.append("(");
|
|
||||||
buff.append(getName());
|
|
||||||
buff.append(":");
|
|
||||||
for (Value n: _val)
|
|
||||||
{
|
|
||||||
buff.append(" "+n.toString());
|
|
||||||
}
|
|
||||||
buff.append(")");
|
|
||||||
|
|
||||||
return buff.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler
|
* Handler
|
||||||
*
|
*
|
||||||
* Signature for all handlers that respond to parsing class files.
|
* Signature for all handlers that respond to parsing class files.
|
||||||
*/
|
*/
|
||||||
public interface Handler
|
public static interface Handler
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DiscoverableAnnotationHandler
|
* AbstractHandler
|
||||||
|
*
|
||||||
|
* Convenience base class to provide no-ops for all Handler methods.
|
||||||
*
|
*
|
||||||
* Processes an annotation when it is discovered on a class.
|
|
||||||
*/
|
*/
|
||||||
public interface DiscoverableAnnotationHandler extends Handler
|
public static abstract class AbstractHandler implements Handler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Process an annotation that was discovered on a class
|
@Override
|
||||||
* @param className
|
public void handle(ClassInfo classInfo)
|
||||||
* @param version
|
{
|
||||||
* @param access
|
//no-op
|
||||||
* @param signature
|
}
|
||||||
* @param superName
|
|
||||||
* @param interfaces
|
@Override
|
||||||
* @param annotation
|
public void handle(MethodInfo methodInfo)
|
||||||
* @param values
|
{
|
||||||
*/
|
// no-op
|
||||||
public void handleClass (String className, int version, int access,
|
}
|
||||||
String signature, String superName, String[] interfaces,
|
|
||||||
String annotation, List<Value>values);
|
@Override
|
||||||
|
public void handle(FieldInfo fieldInfo)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(ClassInfo info, String annotationName)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MethodInfo info, String annotationName)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(FieldInfo info, String annotationName)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an annotation that was discovered on a method
|
* MyMethodVisitor
|
||||||
* @param className
|
*
|
||||||
* @param methodName
|
* ASM Visitor for parsing a method. We are only interested in the annotations on methods.
|
||||||
|
*/
|
||||||
|
public class MyMethodVisitor extends MethodVisitor
|
||||||
|
{
|
||||||
|
final MethodInfo _mi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param classname
|
||||||
* @param access
|
* @param access
|
||||||
* @param desc
|
* @param name
|
||||||
|
* @param methodDesc
|
||||||
* @param signature
|
* @param signature
|
||||||
* @param exceptions
|
* @param exceptions
|
||||||
* @param annotation
|
|
||||||
* @param values
|
|
||||||
*/
|
*/
|
||||||
public void handleMethod (String className, String methodName, int access,
|
public MyMethodVisitor(final String className,
|
||||||
String desc, String signature,String[] exceptions,
|
final int access,
|
||||||
String annotation, List<Value>values);
|
final String name,
|
||||||
|
final String methodDesc,
|
||||||
|
final String signature,
|
||||||
/**
|
final String[] exceptions)
|
||||||
* Process an annotation that was discovered on a field
|
{
|
||||||
* @param className
|
super(Opcodes.ASM4);
|
||||||
* @param fieldName
|
_mi = new MethodInfo(className, name, access, methodDesc,signature, exceptions);
|
||||||
* @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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassHandler
|
* We are only interested in finding the annotations on methods.
|
||||||
*
|
*
|
||||||
* Responds to finding a Class
|
* @see org.objectweb.asm.MethodVisitor#visitAnnotation(java.lang.String, boolean)
|
||||||
*/
|
*/
|
||||||
public interface ClassHandler extends Handler
|
@Override
|
||||||
|
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
|
||||||
{
|
{
|
||||||
public void handle (String className, int version, int access, String signature, String superName, String[] interfaces);
|
String annotationName = normalize(desc);
|
||||||
|
for (Handler h:_handlers)
|
||||||
|
h.handle(_mi, annotationName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MethodHandler
|
* MyFieldVisitor
|
||||||
*
|
*
|
||||||
* Responds to finding a Method
|
* An ASM visitor for parsing Fields.
|
||||||
*/
|
* We are only interested in visiting annotations on Fields.
|
||||||
public interface MethodHandler extends Handler
|
|
||||||
{
|
|
||||||
public void handle (String className, String methodName, int access, String desc, String signature,String[] exceptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FieldHandler
|
|
||||||
*
|
*
|
||||||
* Responds to finding a Field
|
|
||||||
*/
|
*/
|
||||||
public interface FieldHandler extends Handler
|
public class MyFieldVisitor extends FieldVisitor
|
||||||
{
|
{
|
||||||
public void handle (String className, String fieldName, int access, String fieldType, String signature, Object value);
|
final FieldInfo _fieldInfo;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MyAnnotationVisitor
|
* @param classname
|
||||||
|
*/
|
||||||
|
public MyFieldVisitor(final String className,
|
||||||
|
final int access,
|
||||||
|
final String fieldName,
|
||||||
|
final String fieldType,
|
||||||
|
final String signature,
|
||||||
|
final Object value)
|
||||||
|
{
|
||||||
|
super(Opcodes.ASM4);
|
||||||
|
_fieldInfo = new FieldInfo(className, fieldName, access, fieldType, signature, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse an annotation found on a Field.
|
||||||
*
|
*
|
||||||
* ASM Visitor for Annotations
|
* @see org.objectweb.asm.FieldVisitor#visitAnnotation(java.lang.String, boolean)
|
||||||
*/
|
|
||||||
public class MyAnnotationVisitor implements AnnotationVisitor
|
|
||||||
{
|
|
||||||
List<Value> _annotationValues;
|
|
||||||
String _annotationName;
|
|
||||||
|
|
||||||
public MyAnnotationVisitor (String annotationName, List<Value> values)
|
|
||||||
{
|
|
||||||
_annotationValues = values;
|
|
||||||
_annotationName = annotationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Value> getAnnotationValues()
|
|
||||||
{
|
|
||||||
return _annotationValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Visit a single-valued (name,value) pair for this annotation
|
|
||||||
* @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visit(String aname, Object avalue)
|
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
|
||||||
{
|
{
|
||||||
SimpleValue v = new SimpleValue(aname);
|
String annotationName = normalize(desc);
|
||||||
v.setValue(avalue);
|
for (Handler h : _handlers)
|
||||||
_annotationValues.add(v);
|
h.handle(_fieldInfo, annotationName);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return null;
|
||||||
* Visit a (name,value) pair whose value is another Annotation
|
|
||||||
* @see org.objectweb.asm.AnnotationVisitor#visitAnnotation(java.lang.String, java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public AnnotationVisitor visitAnnotation(String name, String desc)
|
|
||||||
{
|
|
||||||
String s = normalize(desc);
|
|
||||||
ListValue v = new ListValue(s);
|
|
||||||
_annotationValues.add(v);
|
|
||||||
MyAnnotationVisitor visitor = new MyAnnotationVisitor(s, v.getList());
|
|
||||||
return visitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Visit an array valued (name, value) pair for this annotation
|
|
||||||
* @see org.objectweb.asm.AnnotationVisitor#visitArray(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public AnnotationVisitor visitArray(String name)
|
|
||||||
{
|
|
||||||
ListValue v = new ListValue(name);
|
|
||||||
_annotationValues.add(v);
|
|
||||||
MyAnnotationVisitor visitor = new MyAnnotationVisitor(null, v.getList());
|
|
||||||
return visitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void visitEnum(String name, String desc, String value)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitEnd()
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,77 +444,55 @@ public class AnnotationParser
|
||||||
*
|
*
|
||||||
* ASM visitor for a class.
|
* ASM visitor for a class.
|
||||||
*/
|
*/
|
||||||
public class MyClassVisitor extends EmptyVisitor
|
public class MyClassVisitor extends ClassVisitor
|
||||||
{
|
{
|
||||||
String _className;
|
|
||||||
int _access;
|
ClassInfo _ci;
|
||||||
String _signature;
|
|
||||||
String _superName;
|
public MyClassVisitor()
|
||||||
String[] _interfaces;
|
{
|
||||||
int _version;
|
super(Opcodes.ASM4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit (int version,
|
public void visit (final int version,
|
||||||
final int access,
|
final int access,
|
||||||
final String name,
|
final String name,
|
||||||
final String signature,
|
final String signature,
|
||||||
final String superName,
|
final String superName,
|
||||||
final String[] interfaces)
|
final String[] interfaces)
|
||||||
{
|
{
|
||||||
_className = normalize(name);
|
_ci = new ClassInfo(normalize(name), version, access, signature, normalize(superName), normalize(interfaces));
|
||||||
_access = access;
|
|
||||||
_signature = signature;
|
|
||||||
_superName = superName;
|
|
||||||
_interfaces = interfaces;
|
|
||||||
_version = version;
|
|
||||||
|
|
||||||
_parsedClassNames.add(_className);
|
_parsedClassNames.add(_ci.getClassName());
|
||||||
//call all registered ClassHandlers
|
|
||||||
String[] normalizedInterfaces = null;
|
for (Handler h:_handlers)
|
||||||
if (interfaces!= null)
|
h.handle(_ci);
|
||||||
{
|
|
||||||
normalizedInterfaces = new String[interfaces.length];
|
|
||||||
int i=0;
|
|
||||||
for (String s : interfaces)
|
|
||||||
normalizedInterfaces[i++] = normalize(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Handler h : AnnotationParser.this._handlers)
|
|
||||||
{
|
|
||||||
if (h instanceof ClassHandler)
|
|
||||||
{
|
|
||||||
((ClassHandler)h).handle(_className, _version, _access, _signature, normalize(_superName), normalizedInterfaces);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit an annotation on a Class
|
||||||
|
*
|
||||||
|
* @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AnnotationVisitor visitAnnotation (String desc, boolean visible)
|
public AnnotationVisitor visitAnnotation (String desc, boolean visible)
|
||||||
{
|
{
|
||||||
MyAnnotationVisitor visitor = new MyAnnotationVisitor(normalize(desc), new ArrayList<Value>())
|
String annotationName = normalize(desc);
|
||||||
{
|
for (Handler h : _handlers)
|
||||||
@Override
|
h.handle(_ci, annotationName);
|
||||||
public void visitEnd()
|
|
||||||
{
|
|
||||||
super.visitEnd();
|
|
||||||
|
|
||||||
//call all AnnotationHandlers with classname, annotation name + values
|
return null;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return visitor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Override
|
||||||
public MethodVisitor visitMethod (final int access,
|
public MethodVisitor visitMethod (final int access,
|
||||||
final String name,
|
final String name,
|
||||||
|
@ -441,35 +501,14 @@ public class AnnotationParser
|
||||||
final String[] exceptions)
|
final String[] exceptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new EmptyVisitor ()
|
return new MyMethodVisitor(_ci.getClassName(), access, name, methodDesc, signature, exceptions);
|
||||||
{
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Override
|
||||||
public FieldVisitor visitField (final int access,
|
public FieldVisitor visitField (final int access,
|
||||||
final String fieldName,
|
final String fieldName,
|
||||||
|
@ -477,97 +516,9 @@ public class AnnotationParser
|
||||||
final String signature,
|
final String signature,
|
||||||
final Object value)
|
final Object value)
|
||||||
{
|
{
|
||||||
|
return new MyFieldVisitor(_ci.getClassName(), access, fieldName, fieldType, signature, 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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,8 @@ package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
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.MultiMap;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
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.
|
* 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);
|
private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class);
|
||||||
|
|
||||||
|
@ -46,17 +47,17 @@ public class ClassInheritanceHandler implements ClassHandler
|
||||||
_inheritanceMap = map;
|
_inheritanceMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(String className, int version, int access, String signature, String superName, String[] interfaces)
|
public void handle(ClassInfo classInfo)
|
||||||
{
|
{
|
||||||
try
|
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
|
//To save memory, we don't record classes that only extend Object, as that can be assumed
|
||||||
if (!"java.lang.Object".equals(superName))
|
if (!"java.lang.Object".equals(classInfo.getSuperName()))
|
||||||
_inheritanceMap.add(superName, className);
|
_inheritanceMap.add(classInfo.getSuperName(), classInfo.getClassName());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,10 +19,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.annotations;
|
package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler;
|
||||||
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.plus.annotation.ContainerInitializer;
|
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
|
* method level. The specified annotation is derived from an @HandlesTypes on
|
||||||
* a ServletContainerInitializer class.
|
* a ServletContainerInitializer class.
|
||||||
*/
|
*/
|
||||||
public class ContainerInitializerAnnotationHandler implements DiscoverableAnnotationHandler
|
/**
|
||||||
|
* @author janb
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ContainerInitializerAnnotationHandler extends AbstractHandler
|
||||||
{
|
{
|
||||||
ContainerInitializer _initializer;
|
ContainerInitializer _initializer;
|
||||||
Class _annotation;
|
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.
|
* 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)
|
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(ClassInfo)
|
||||||
|
* */
|
||||||
|
public void handle(ClassInfo info, String annotationName)
|
||||||
|
{
|
||||||
|
if (annotationName == null || !_annotation.getName().equals(annotationName))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_initializer.addAnnotatedTypeName(info.getClassName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName,
|
public void handle(FieldInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
_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)
|
* 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
|
|
||||||
List<Value> values)
|
|
||||||
{
|
|
||||||
_initializer.addAnnotatedTypeName(className);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return _annotation.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContainerInitializer getContainerInitializer()
|
public ContainerInitializer getContainerInitializer()
|
||||||
{
|
{
|
||||||
return _initializer;
|
return _initializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.List;
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler;
|
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.plus.annotation.RunAsCollection;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
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,
|
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
LOG.warn ("@RunAs annotation not applicable for fields: "+className+"."+fieldName);
|
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,
|
public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
LOG.warn("@RunAs annotation ignored on method: "+className+"."+methodName+" "+signature);
|
LOG.warn("@RunAs annotation ignored on method: "+className+"."+methodName+" "+signature);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
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.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
||||||
|
@ -46,31 +48,28 @@ public class WebFilterAnnotationHandler extends AbstractDiscoverableAnnotationHa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
|
public void handle(ClassInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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);
|
addAnnotation(wfAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
public void handle(FieldInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
LOG.warn ("@WebFilter not applicable for fields: "+className+"."+fieldName);
|
if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName))
|
||||||
|
return;
|
||||||
|
LOG.warn ("@WebFilter not applicable for fields: "+info.getClassName()+"."+info.getFieldName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
|
public void handle(MethodInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
LOG.warn ("@WebFilter not applicable for methods: "+className+"."+methodName+" "+signature);
|
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
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.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
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,
|
public void handle(ClassInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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);
|
addAnnotation(wlAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
public void handle(FieldInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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,
|
public void handle(MethodInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,9 @@ package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
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.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
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)
|
* @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
|
@Override
|
||||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName,
|
public void handle(ClassInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
if (!"javax.servlet.annotation.WebServlet".equals(annotationName))
|
if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WebServletAnnotation annotation = new WebServletAnnotation (_context, className, _resource);
|
WebServletAnnotation annotation = new WebServletAnnotation (_context, info.getClassName(), _resource);
|
||||||
addAnnotation(annotation);
|
addAnnotation(annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
public void handle(FieldInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
|
if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName))
|
||||||
|
return;
|
||||||
|
|
||||||
LOG.warn ("@WebServlet annotation not supported for fields");
|
LOG.warn ("@WebServlet annotation not supported for fields");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
|
public void handle(MethodInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
|
if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName))
|
||||||
|
return;
|
||||||
|
|
||||||
LOG.warn ("@WebServlet annotation not supported for methods");
|
LOG.warn ("@WebServlet annotation not supported for methods");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return "javax.servlet.annotation.WebServlet";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,10 @@ import java.util.Map;
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler;
|
||||||
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.MultiMap;
|
import org.eclipse.jetty.util.MultiMap;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -44,34 +46,32 @@ public class TestAnnotationInheritance
|
||||||
List<String> classNames = new ArrayList<String>();
|
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> annotatedClassNames = new ArrayList<String>();
|
||||||
public final List<String> annotatedMethods = new ArrayList<String>();
|
public final List<String> annotatedMethods = new ArrayList<String>();
|
||||||
public final List<String> annotatedFields = 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,
|
public void handle(ClassInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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,
|
public void handle(FieldInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
annotatedFields.add(className+"."+fieldName);
|
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,
|
public void handle(MethodInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
annotatedMethods.add(className+"."+methodName);
|
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||||
}
|
return;
|
||||||
|
annotatedMethods.add(info.getClassName()+"."+info.getMethodName());
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return "org.eclipse.jetty.annotations.Sample";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class TestAnnotationInheritance
|
||||||
{
|
{
|
||||||
SampleHandler handler = new SampleHandler();
|
SampleHandler handler = new SampleHandler();
|
||||||
AnnotationParser parser = new AnnotationParser();
|
AnnotationParser parser = new AnnotationParser();
|
||||||
parser.registerAnnotationHandler("org.eclipse.jetty.annotations.Sample", handler);
|
parser.registerHandler(handler);
|
||||||
parser.parse(ClassB.class, new ClassNameResolver ()
|
parser.parse(ClassB.class, new ClassNameResolver ()
|
||||||
{
|
{
|
||||||
public boolean isExcluded(String name)
|
public boolean isExcluded(String name)
|
||||||
|
@ -166,7 +166,7 @@ public class TestAnnotationInheritance
|
||||||
{
|
{
|
||||||
AnnotationParser parser = new AnnotationParser();
|
AnnotationParser parser = new AnnotationParser();
|
||||||
SampleHandler handler = new SampleHandler();
|
SampleHandler handler = new SampleHandler();
|
||||||
parser.registerAnnotationHandler("org.eclipse.jetty.annotations.Sample", handler);
|
parser.registerHandler(handler);
|
||||||
parser.parse(ClassA.class.getName(), new ClassNameResolver()
|
parser.parse(ClassA.class.getName(), new ClassNameResolver()
|
||||||
{
|
{
|
||||||
public boolean isExcluded(String name)
|
public boolean isExcluded(String name)
|
||||||
|
@ -207,7 +207,7 @@ public class TestAnnotationInheritance
|
||||||
{
|
{
|
||||||
AnnotationParser parser = new AnnotationParser();
|
AnnotationParser parser = new AnnotationParser();
|
||||||
ClassInheritanceHandler handler = new ClassInheritanceHandler();
|
ClassInheritanceHandler handler = new ClassInheritanceHandler();
|
||||||
parser.registerClassHandler(handler);
|
parser.registerHandler(handler);
|
||||||
|
|
||||||
class Foo implements InterfaceD
|
class Foo implements InterfaceD
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,8 +18,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.annotations;
|
package org.eclipse.jetty.annotations;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.junit.Assert.*;
|
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.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -32,20 +35,20 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo;
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.Value;
|
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.FS;
|
||||||
import org.eclipse.jetty.toolchain.test.IO;
|
import org.eclipse.jetty.toolchain.test.IO;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestAnnotationParser
|
public class TestAnnotationParser
|
||||||
{
|
{
|
||||||
public static class TrackingAnnotationHandler implements DiscoverableAnnotationHandler
|
public static class TrackingAnnotationHandler extends AnnotationParser.AbstractHandler
|
||||||
{
|
{
|
||||||
private final String annotationName;
|
private final String annotationName;
|
||||||
public final Set<String> foundClasses;
|
public final Set<String> foundClasses;
|
||||||
|
@ -57,30 +60,11 @@ public class TestAnnotationParser
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
|
public void handle(ClassInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
foundClasses.add(className);
|
if (annotation == null || !annotationName.equals(annotation))
|
||||||
}
|
return;
|
||||||
|
foundClasses.add(info.getClassName());
|
||||||
@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()
|
|
||||||
{
|
|
||||||
return this.annotationName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,41 +78,34 @@ public class TestAnnotationParser
|
||||||
{ "org.eclipse.jetty.annotations.ClassA" };
|
{ "org.eclipse.jetty.annotations.ClassA" };
|
||||||
AnnotationParser parser = new AnnotationParser();
|
AnnotationParser parser = new AnnotationParser();
|
||||||
|
|
||||||
class SampleAnnotationHandler implements DiscoverableAnnotationHandler
|
class SampleAnnotationHandler extends AnnotationParser.AbstractHandler
|
||||||
{
|
{
|
||||||
private List<String> methods = Arrays.asList("a","b","c","d","l");
|
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,
|
public void handle(ClassInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
assertEquals("org.eclipse.jetty.annotations.ClassA",className);
|
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||||
|
return;
|
||||||
|
|
||||||
|
assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
public void handle(FieldInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
assertEquals("m",fieldName);
|
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||||
assertEquals(org.objectweb.asm.Type.OBJECT,org.objectweb.asm.Type.getType(fieldType).getSort());
|
return;
|
||||||
assertEquals(1,values.size());
|
assertEquals("m",info.getFieldName());
|
||||||
Value anv1 = values.get(0);
|
assertEquals(org.objectweb.asm.Type.OBJECT,org.objectweb.asm.Type.getType(info.getFieldType()).getSort());
|
||||||
assertEquals("value",anv1.getName());
|
|
||||||
assertEquals(7,anv1.getValue());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
|
public void handle(MethodInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
assertEquals("org.eclipse.jetty.annotations.ClassA",className);
|
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||||
assertTrue(methods.contains(methodName));
|
return;
|
||||||
|
assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassName());
|
||||||
|
assertTrue(methods.contains(info.getMethodName()));
|
||||||
assertEquals("org.eclipse.jetty.annotations.Sample",annotation);
|
assertEquals("org.eclipse.jetty.annotations.Sample",annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return "org.eclipse.jetty.annotations.Sample";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.registerHandler(new SampleAnnotationHandler());
|
parser.registerHandler(new SampleAnnotationHandler());
|
||||||
|
@ -159,34 +136,30 @@ public class TestAnnotationParser
|
||||||
{ "org.eclipse.jetty.annotations.ClassB" };
|
{ "org.eclipse.jetty.annotations.ClassB" };
|
||||||
AnnotationParser parser = new AnnotationParser();
|
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,
|
public void handle(ClassInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
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,
|
public void handle(FieldInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
|
if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation))
|
||||||
|
return;
|
||||||
// there should not be any
|
// there should not be any
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
|
public void handle(MethodInfo info, String annotation)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(className));
|
if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation))
|
||||||
assertTrue("a".equals(methodName));
|
return;
|
||||||
|
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(info.getClassName()));
|
||||||
|
assertTrue("a".equals(info.getMethodName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return "org.eclipse.jetty.annotations.Multi";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.registerHandler(new MultiAnnotationHandler());
|
parser.registerHandler(new MultiAnnotationHandler());
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class TestServletAnnotations
|
||||||
|
|
||||||
WebAppContext wac = new WebAppContext();
|
WebAppContext wac = new WebAppContext();
|
||||||
WebServletAnnotationHandler handler = new WebServletAnnotationHandler(wac);
|
WebServletAnnotationHandler handler = new WebServletAnnotationHandler(wac);
|
||||||
parser.registerAnnotationHandler("javax.servlet.annotation.WebServlet", handler);
|
parser.registerHandler(handler);
|
||||||
|
|
||||||
parser.parse(classes, new ClassNameResolver ()
|
parser.parse(classes, new ClassNameResolver ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -399,8 +399,8 @@
|
||||||
<goal>copy-dependencies</goal>
|
<goal>copy-dependencies</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includeGroupIds>javax.annotation,org.eclipse.jetty.orbit</includeGroupIds>
|
<includeGroupIds>javax.annotation,org.eclipse.jetty.orbit,org.ow2.asm</includeGroupIds>
|
||||||
<includeArtifactIds>javax.annotation-api,org.objectweb.asm</includeArtifactIds>
|
<includeArtifactIds>javax.annotation-api,asm,asm-commons</includeArtifactIds>
|
||||||
<includeTypes>jar</includeTypes>
|
<includeTypes>jar</includeTypes>
|
||||||
<outputDirectory>${assembly-directory}/lib/annotations</outputDirectory>
|
<outputDirectory>${assembly-directory}/lib/annotations</outputDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -541,10 +541,6 @@
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
|
||||||
<artifactId>org.objectweb.asm</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||||
<artifactId>javax.activation</artifactId>
|
<artifactId>javax.activation</artifactId>
|
||||||
|
@ -579,6 +575,15 @@
|
||||||
<artifactId>javax.el</artifactId>
|
<artifactId>javax.el</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- jetty deps -->
|
<!-- jetty deps -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.io.File;
|
||||||
import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
|
import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
|
||||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser;
|
import org.eclipse.jetty.annotations.AnnotationParser;
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
|
||||||
import org.eclipse.jetty.annotations.ClassNameResolver;
|
import org.eclipse.jetty.annotations.ClassNameResolver;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
@ -52,7 +51,7 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration
|
||||||
throw new IllegalStateException ("No metadata");
|
throw new IllegalStateException ("No metadata");
|
||||||
|
|
||||||
parser.clearHandlers();
|
parser.clearHandlers();
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||||
|
|
|
@ -18,16 +18,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.osgi.annotations;
|
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.AbstractDiscoverableAnnotationHandler;
|
||||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
|
||||||
import org.eclipse.jetty.annotations.ClassNameResolver;
|
import org.eclipse.jetty.annotations.ClassNameResolver;
|
||||||
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
||||||
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
|
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
import org.osgi.framework.Constants;
|
import org.osgi.framework.Constants;
|
||||||
|
@ -157,7 +152,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
|
||||||
Resource bundleRes = parser.getResource(bundle);
|
Resource bundleRes = parser.getResource(bundle);
|
||||||
|
|
||||||
parser.clearHandlers();
|
parser.clearHandlers();
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
|
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.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
||||||
|
@ -47,19 +47,13 @@ public class ServerEndpointAnnotationHandler extends AbstractDiscoverableAnnotat
|
||||||
super(context,list);
|
super(context,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAnnotationName()
|
|
||||||
{
|
|
||||||
return ANNOTATION_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName,
|
public void handle(ClassInfo info, String annotationName)
|
||||||
List<Value> values)
|
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
{
|
{
|
||||||
LOG.debug("handleClass: {}, {}, {}",className,annotationName,values);
|
LOG.debug("handleClass: {}, {}, {}",info.getClassName(),annotationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ANNOTATION_NAME.equals(annotationName))
|
if (!ANNOTATION_NAME.equals(annotationName))
|
||||||
|
@ -68,21 +62,7 @@ public class ServerEndpointAnnotationHandler extends AbstractDiscoverableAnnotat
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,className,_resource);
|
ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,info.getClassName(),_resource);
|
||||||
addAnnotation(annotation);
|
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 */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
12
pom.xml
12
pom.xml
|
@ -467,10 +467,16 @@
|
||||||
<version>1.2</version>
|
<version>1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>org.objectweb.asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
<version>3.1.0.v200803061910</version>
|
<version>4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
|
<version>4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||||
<artifactId>javax.security.auth.message</artifactId>
|
<artifactId>javax.security.auth.message</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue