417561 Refactor annotation related code to remove some deadwood
This commit is contained in:
parent
aa5705fd78
commit
d4c035a06f
|
@ -18,24 +18,22 @@
|
|||
|
||||
package org.eclipse.jetty.annotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* DiscoverableAnnotationHandler
|
||||
*
|
||||
*
|
||||
* Base class for handling the discovery of an annotation.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractDiscoverableAnnotationHandler extends AbstractHandler
|
||||
{
|
||||
protected WebAppContext _context;
|
||||
protected List<DiscoveredAnnotation> _annotations;
|
||||
protected Resource _resource;
|
||||
|
||||
|
||||
public AbstractDiscoverableAnnotationHandler(WebAppContext context)
|
||||
{
|
||||
|
@ -45,35 +43,13 @@ public abstract class AbstractDiscoverableAnnotationHandler extends AbstractHand
|
|||
public AbstractDiscoverableAnnotationHandler(WebAppContext context, List<DiscoveredAnnotation> list)
|
||||
{
|
||||
_context = context;
|
||||
if (list == null)
|
||||
_annotations = new ArrayList<DiscoveredAnnotation>();
|
||||
else
|
||||
_annotations = list;
|
||||
|
||||
}
|
||||
|
||||
public Resource getResource()
|
||||
{
|
||||
return _resource;
|
||||
}
|
||||
|
||||
public void setResource(Resource resource)
|
||||
{
|
||||
_resource = resource;
|
||||
}
|
||||
|
||||
public List<DiscoveredAnnotation> getAnnotationList ()
|
||||
{
|
||||
return _annotations;
|
||||
}
|
||||
|
||||
public void resetList()
|
||||
{
|
||||
_annotations.clear();
|
||||
}
|
||||
|
||||
public void addAnnotation (DiscoveredAnnotation a)
|
||||
{
|
||||
_annotations.add(a);
|
||||
_context.getMetaData().addDiscoveredAnnotation(a);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -197,10 +197,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
// In case there is no others then it is
|
||||
// WEB-INF/classes + order of the elements.
|
||||
parseWebInfClasses(context, parser);
|
||||
parseWebInfLib (context, parser);
|
||||
|
||||
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
context.getMetaData().addDiscoveredAnnotations(((AbstractDiscoverableAnnotationHandler)h).getAnnotationList());
|
||||
parseWebInfLib (context, parser);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +229,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
}
|
||||
|
||||
/**
|
||||
* @return a new AnnotationParser. This method can be overridden to use a different impleemntation of
|
||||
* @return a new AnnotationParser. This method can be overridden to use a different implementation of
|
||||
* the AnnotationParser. Note that this is considered internal API.
|
||||
*/
|
||||
protected AnnotationParser createAnnotationParser()
|
||||
|
@ -259,12 +256,8 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
public void createServletContainerInitializerAnnotationHandlers (WebAppContext context, List<ServletContainerInitializer> scis)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
|
||||
if (scis == null || scis.isEmpty())
|
||||
return; // nothing to do
|
||||
|
||||
|
||||
|
||||
List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
|
||||
context.setAttribute(CONTAINER_INITIALIZERS, initializers);
|
||||
|
@ -300,7 +293,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
if (c.isAnnotation())
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Registering annotation handler for "+c.getName());
|
||||
|
||||
_containerInitializerAnnotationHandlers.add(new ContainerInitializerAnnotationHandler(initializer, c));
|
||||
}
|
||||
}
|
||||
|
@ -410,11 +402,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
|
||||
//always parse for discoverable annotations as well as class hierarchy and servletcontainerinitializer related annotations
|
||||
parser.clearHandlers();
|
||||
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
@ -477,14 +464,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 (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(r);
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
}
|
||||
|
||||
parser.parse(uri, new WebAppClassNameResolver(context));
|
||||
}
|
||||
|
@ -504,11 +484,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
LOG.debug("Scanning classes in WEB-INF/classes");
|
||||
|
||||
parser.clearHandlers();
|
||||
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
@ -550,6 +525,4 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
{
|
||||
return (d!=null && d.getMetaDataComplete() == MetaDataComplete.True);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ public class AnnotationParser
|
|||
*/
|
||||
public class ClassInfo
|
||||
{
|
||||
final Resource _containingResource;
|
||||
final String _className;
|
||||
final int _version;
|
||||
final int _access;
|
||||
|
@ -123,9 +124,10 @@ public class AnnotationParser
|
|||
final String _superName;
|
||||
final String[] _interfaces;
|
||||
|
||||
public ClassInfo(String className, int version, int access, String signature, String superName, String[] interfaces)
|
||||
public ClassInfo(Resource resource, String className, int version, int access, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
super();
|
||||
_containingResource = resource;
|
||||
_className = className;
|
||||
_version = version;
|
||||
_access = access;
|
||||
|
@ -163,6 +165,11 @@ public class AnnotationParser
|
|||
{
|
||||
return _interfaces;
|
||||
}
|
||||
|
||||
public Resource getContainingResource()
|
||||
{
|
||||
return _containingResource;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,17 +180,17 @@ public class AnnotationParser
|
|||
*/
|
||||
public class MethodInfo
|
||||
{
|
||||
final String _className;
|
||||
final ClassInfo _classInfo;
|
||||
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)
|
||||
public MethodInfo(ClassInfo classInfo, String methodName, int access, String desc, String signature, String[] exceptions)
|
||||
{
|
||||
super();
|
||||
_className = className;
|
||||
_classInfo = classInfo;
|
||||
_methodName = methodName;
|
||||
_access = access;
|
||||
_desc = desc;
|
||||
|
@ -191,9 +198,9 @@ public class AnnotationParser
|
|||
_exceptions = exceptions;
|
||||
}
|
||||
|
||||
public String getClassName()
|
||||
public ClassInfo getClassInfo()
|
||||
{
|
||||
return _className;
|
||||
return _classInfo;
|
||||
}
|
||||
|
||||
public String getMethodName()
|
||||
|
@ -219,7 +226,7 @@ public class AnnotationParser
|
|||
public String[] getExceptions()
|
||||
{
|
||||
return _exceptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -232,17 +239,17 @@ public class AnnotationParser
|
|||
*/
|
||||
public class FieldInfo
|
||||
{
|
||||
final String _className;
|
||||
final ClassInfo _classInfo;
|
||||
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)
|
||||
public FieldInfo(ClassInfo classInfo, String fieldName, int access, String fieldType, String signature, Object value)
|
||||
{
|
||||
super();
|
||||
_className = className;
|
||||
_classInfo = classInfo;
|
||||
_fieldName = fieldName;
|
||||
_access = access;
|
||||
_fieldType = fieldType;
|
||||
|
@ -250,9 +257,9 @@ public class AnnotationParser
|
|||
_value = value;
|
||||
}
|
||||
|
||||
public String getClassName()
|
||||
public ClassInfo getClassInfo()
|
||||
{
|
||||
return _className;
|
||||
return _classInfo;
|
||||
}
|
||||
|
||||
public String getFieldName()
|
||||
|
@ -355,6 +362,7 @@ public class AnnotationParser
|
|||
public class MyMethodVisitor extends MethodVisitor
|
||||
{
|
||||
final MethodInfo _mi;
|
||||
|
||||
|
||||
/**
|
||||
* @param classname
|
||||
|
@ -364,7 +372,8 @@ public class AnnotationParser
|
|||
* @param signature
|
||||
* @param exceptions
|
||||
*/
|
||||
public MyMethodVisitor(final String className,
|
||||
public MyMethodVisitor(
|
||||
final ClassInfo classInfo,
|
||||
final int access,
|
||||
final String name,
|
||||
final String methodDesc,
|
||||
|
@ -372,7 +381,7 @@ public class AnnotationParser
|
|||
final String[] exceptions)
|
||||
{
|
||||
super(Opcodes.ASM4);
|
||||
_mi = new MethodInfo(className, name, access, methodDesc,signature, exceptions);
|
||||
_mi = new MethodInfo(classInfo, name, access, methodDesc,signature, exceptions);
|
||||
}
|
||||
|
||||
|
||||
|
@ -408,7 +417,7 @@ public class AnnotationParser
|
|||
/**
|
||||
* @param classname
|
||||
*/
|
||||
public MyFieldVisitor(final String className,
|
||||
public MyFieldVisitor(final ClassInfo classInfo,
|
||||
final int access,
|
||||
final String fieldName,
|
||||
final String fieldType,
|
||||
|
@ -416,7 +425,7 @@ public class AnnotationParser
|
|||
final Object value)
|
||||
{
|
||||
super(Opcodes.ASM4);
|
||||
_fieldInfo = new FieldInfo(className, fieldName, access, fieldType, signature, value);
|
||||
_fieldInfo = new FieldInfo(classInfo, fieldName, access, fieldType, signature, value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -447,11 +456,13 @@ public class AnnotationParser
|
|||
public class MyClassVisitor extends ClassVisitor
|
||||
{
|
||||
|
||||
final Resource _containingResource;
|
||||
ClassInfo _ci;
|
||||
|
||||
public MyClassVisitor()
|
||||
public MyClassVisitor(Resource containingResource)
|
||||
{
|
||||
super(Opcodes.ASM4);
|
||||
_containingResource = containingResource;
|
||||
}
|
||||
|
||||
|
||||
|
@ -463,7 +474,7 @@ public class AnnotationParser
|
|||
final String superName,
|
||||
final String[] interfaces)
|
||||
{
|
||||
_ci = new ClassInfo(normalize(name), version, access, signature, normalize(superName), normalize(interfaces));
|
||||
_ci = new ClassInfo(_containingResource, normalize(name), version, access, signature, normalize(superName), normalize(interfaces));
|
||||
|
||||
_parsedClassNames.add(_ci.getClassName());
|
||||
|
||||
|
@ -501,7 +512,7 @@ public class AnnotationParser
|
|||
final String[] exceptions)
|
||||
{
|
||||
|
||||
return new MyMethodVisitor(_ci.getClassName(), access, name, methodDesc, signature, exceptions);
|
||||
return new MyMethodVisitor(_ci, access, name, methodDesc, signature, exceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -516,7 +527,7 @@ public class AnnotationParser
|
|||
final String signature,
|
||||
final Object value)
|
||||
{
|
||||
return new MyFieldVisitor(_ci.getClassName(), access, fieldName, fieldType, signature, value);
|
||||
return new MyFieldVisitor(_ci, access, fieldName, fieldType, signature, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,7 +612,7 @@ public class AnnotationParser
|
|||
if (resource!= null)
|
||||
{
|
||||
Resource r = Resource.newResource(resource);
|
||||
scanClass(r.getInputStream());
|
||||
scanClass(null, r.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -632,7 +643,7 @@ public class AnnotationParser
|
|||
if (resource!= null)
|
||||
{
|
||||
Resource r = Resource.newResource(resource);
|
||||
scanClass(r.getInputStream());
|
||||
scanClass(null, r.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -681,7 +692,7 @@ public class AnnotationParser
|
|||
if (resource!= null)
|
||||
{
|
||||
Resource r = Resource.newResource(resource);
|
||||
scanClass(r.getInputStream());
|
||||
scanClass(null, r.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -695,7 +706,7 @@ public class AnnotationParser
|
|||
* @param resolver
|
||||
* @throws Exception
|
||||
*/
|
||||
public void parseDir (Resource dir, ClassNameResolver resolver)
|
||||
protected void parseDir (Resource dir, ClassNameResolver resolver)
|
||||
throws Exception
|
||||
{
|
||||
//skip dirs whose name start with . (ie hidden)
|
||||
|
@ -723,7 +734,7 @@ public class AnnotationParser
|
|||
{
|
||||
Resource r = Resource.newResource(res.getURL());
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class {}", r);};
|
||||
scanClass(r.getInputStream());
|
||||
scanClass(dir, r.getInputStream());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -763,7 +774,7 @@ public class AnnotationParser
|
|||
{
|
||||
try
|
||||
{
|
||||
parseJarEntry(jarUri, entry, resolver);
|
||||
parseJarEntry(Resource.newResource(jarUri), entry, resolver);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -849,13 +860,15 @@ public class AnnotationParser
|
|||
|
||||
if (fullname.endsWith(".class"))
|
||||
{
|
||||
scanClass(r.getInputStream());
|
||||
scanClass(null, r.getInputStream());
|
||||
return;
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) LOG.warn("Resource not scannable for classes: {}", r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse a resource that is a jar file.
|
||||
|
@ -864,13 +877,13 @@ public class AnnotationParser
|
|||
* @param resolver
|
||||
* @throws Exception
|
||||
*/
|
||||
public void parseJar (Resource jarResource, final ClassNameResolver resolver)
|
||||
protected void parseJar (Resource jarResource, final ClassNameResolver resolver)
|
||||
throws Exception
|
||||
{
|
||||
if (jarResource == null)
|
||||
return;
|
||||
|
||||
URI uri = jarResource.getURI();
|
||||
|
||||
if (jarResource.toString().endsWith(".jar"))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning jar {}", jarResource);};
|
||||
|
@ -879,14 +892,14 @@ public class AnnotationParser
|
|||
InputStream in = jarResource.getInputStream();
|
||||
if (in==null)
|
||||
return;
|
||||
|
||||
|
||||
JarInputStream jar_in = new JarInputStream(in);
|
||||
try
|
||||
{
|
||||
JarEntry entry = jar_in.getNextJarEntry();
|
||||
while (entry!=null)
|
||||
{
|
||||
parseJarEntry(uri, entry, resolver);
|
||||
parseJarEntry(jarResource, entry, resolver);
|
||||
entry = jar_in.getNextJarEntry();
|
||||
}
|
||||
}
|
||||
|
@ -904,7 +917,7 @@ public class AnnotationParser
|
|||
* @param resolver
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void parseJarEntry (URI jar, JarEntry entry, final ClassNameResolver resolver)
|
||||
protected void parseJarEntry (Resource jar, JarEntry entry, final ClassNameResolver resolver)
|
||||
throws Exception
|
||||
{
|
||||
if (jar == null || entry == null)
|
||||
|
@ -925,9 +938,9 @@ public class AnnotationParser
|
|||
||
|
||||
(!resolver.isExcluded(shortName) && (!isParsed(shortName) || resolver.shouldOverride(shortName))))
|
||||
{
|
||||
Resource clazz = Resource.newResource("jar:"+jar+"!/"+name);
|
||||
Resource clazz = Resource.newResource("jar:"+jar.getURI()+"!/"+name);
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class from jar {}", clazz);};
|
||||
scanClass(clazz.getInputStream());
|
||||
scanClass(jar, clazz.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -937,14 +950,15 @@ public class AnnotationParser
|
|||
/**
|
||||
* Use ASM on a class
|
||||
*
|
||||
* @param containingResource the dir or jar that the class is contained within, can be null if not known
|
||||
* @param is
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void scanClass (InputStream is)
|
||||
protected void scanClass (Resource containingResource, InputStream is)
|
||||
throws IOException
|
||||
{
|
||||
ClassReader reader = new ClassReader(is);
|
||||
reader.accept(new MyClassVisitor(), ClassReader.SKIP_CODE|ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);
|
||||
reader.accept(new MyClassVisitor(containingResource), ClassReader.SKIP_CODE|ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,11 +36,7 @@ public class ClassInheritanceHandler extends AbstractHandler
|
|||
private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class);
|
||||
|
||||
MultiMap<String> _inheritanceMap;
|
||||
|
||||
public ClassInheritanceHandler()
|
||||
{
|
||||
_inheritanceMap = new MultiMap<>();
|
||||
}
|
||||
|
||||
|
||||
public ClassInheritanceHandler(MultiMap<String> map)
|
||||
{
|
||||
|
@ -64,14 +60,4 @@ public class ClassInheritanceHandler extends AbstractHandler
|
|||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getClassNamesExtendingOrImplementing (String className)
|
||||
{
|
||||
return _inheritanceMap.getValues(className);
|
||||
}
|
||||
|
||||
public MultiMap<String> getMap ()
|
||||
{
|
||||
return _inheritanceMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class ContainerInitializerAnnotationHandler extends AbstractHandler
|
|||
{
|
||||
if (annotationName == null || !_annotation.getName().equals(annotationName))
|
||||
return;
|
||||
_initializer.addAnnotatedTypeName(info.getClassName());
|
||||
_initializer.addAnnotatedTypeName(info.getClassInfo().getClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public class ContainerInitializerAnnotationHandler extends AbstractHandler
|
|||
{
|
||||
if (annotationName == null || !_annotation.getName().equals(annotationName))
|
||||
return;
|
||||
_initializer.addAnnotatedTypeName(info.getClassName());
|
||||
_initializer.addAnnotatedTypeName(info.getClassInfo().getClassName());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class WebFilterAnnotationHandler extends AbstractDiscoverableAnnotationHa
|
|||
if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName))
|
||||
return;
|
||||
|
||||
WebFilterAnnotation wfAnnotation = new WebFilterAnnotation(_context, info.getClassName(), _resource);
|
||||
WebFilterAnnotation wfAnnotation = new WebFilterAnnotation(_context, info.getClassName(), info.getContainingResource());
|
||||
addAnnotation(wfAnnotation);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class WebFilterAnnotationHandler extends AbstractDiscoverableAnnotationHa
|
|||
{
|
||||
if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName))
|
||||
return;
|
||||
LOG.warn ("@WebFilter not applicable for fields: "+info.getClassName()+"."+info.getFieldName());
|
||||
LOG.warn ("@WebFilter not applicable for fields: "+info.getClassInfo().getClassName()+"."+info.getFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,6 +70,6 @@ public class WebFilterAnnotationHandler extends AbstractDiscoverableAnnotationHa
|
|||
{
|
||||
if (annotationName == null || !"javax.servlet.annotation.WebFilter".equals(annotationName))
|
||||
return;
|
||||
LOG.warn ("@WebFilter not applicable for methods: "+info.getClassName()+"."+info.getMethodName()+" "+info.getSignature());
|
||||
LOG.warn ("@WebFilter not applicable for methods: "+info.getClassInfo().getClassName()+"."+info.getMethodName()+" "+info.getSignature());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class WebListenerAnnotationHandler extends AbstractDiscoverableAnnotation
|
|||
if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName))
|
||||
return;
|
||||
|
||||
WebListenerAnnotation wlAnnotation = new WebListenerAnnotation(_context, info.getClassName(), _resource);
|
||||
WebListenerAnnotation wlAnnotation = new WebListenerAnnotation(_context, info.getClassName(), info.getContainingResource());
|
||||
addAnnotation(wlAnnotation);
|
||||
}
|
||||
|
||||
|
@ -58,13 +58,13 @@ public class WebListenerAnnotationHandler extends AbstractDiscoverableAnnotation
|
|||
{
|
||||
if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName))
|
||||
return;
|
||||
LOG.warn ("@WebListener is not applicable to fields: "+info.getClassName()+"."+info.getFieldName());
|
||||
LOG.warn ("@WebListener is not applicable to fields: "+info.getClassInfo().getClassName()+"."+info.getFieldName());
|
||||
}
|
||||
|
||||
public void handle(MethodInfo info, String annotationName)
|
||||
{
|
||||
if (annotationName == null || !"javax.servlet.annotation.WebListener".equals(annotationName))
|
||||
return;
|
||||
LOG.warn ("@WebListener is not applicable to methods: "+info.getClassName()+"."+info.getMethodName()+" "+info.getSignature());
|
||||
LOG.warn ("@WebListener is not applicable to methods: "+info.getClassInfo().getClassName()+"."+info.getMethodName()+" "+info.getSignature());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class WebServletAnnotationHandler extends AbstractDiscoverableAnnotationH
|
|||
if (annotationName == null || !"javax.servlet.annotation.WebServlet".equals(annotationName))
|
||||
return;
|
||||
|
||||
WebServletAnnotation annotation = new WebServletAnnotation (_context, info.getClassName(), _resource);
|
||||
WebServletAnnotation annotation = new WebServletAnnotation (_context, info.getClassName(), info.getContainingResource());
|
||||
addAnnotation(annotation);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,14 +64,14 @@ public class TestAnnotationInheritance
|
|||
{
|
||||
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||
return;
|
||||
annotatedFields.add(info.getClassName()+"."+info.getFieldName());
|
||||
annotatedFields.add(info.getClassInfo().getClassName()+"."+info.getFieldName());
|
||||
}
|
||||
|
||||
public void handle(MethodInfo info, String annotation)
|
||||
{
|
||||
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||
return;
|
||||
annotatedMethods.add(info.getClassName()+"."+info.getMethodName());
|
||||
annotatedMethods.add(info.getClassInfo().getClassName()+"."+info.getMethodName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,8 +205,10 @@ public class TestAnnotationInheritance
|
|||
@Test
|
||||
public void testTypeInheritanceHandling() throws Exception
|
||||
{
|
||||
MultiMap map = new MultiMap();
|
||||
|
||||
AnnotationParser parser = new AnnotationParser();
|
||||
ClassInheritanceHandler handler = new ClassInheritanceHandler();
|
||||
ClassInheritanceHandler handler = new ClassInheritanceHandler(map);
|
||||
parser.registerHandler(handler);
|
||||
|
||||
class Foo implements InterfaceD
|
||||
|
@ -221,7 +223,6 @@ public class TestAnnotationInheritance
|
|||
|
||||
parser.parse(classNames, null);
|
||||
|
||||
MultiMap map = handler.getMap();
|
||||
assertNotNull(map);
|
||||
assertFalse(map.isEmpty());
|
||||
assertEquals(2, map.size());
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TestAnnotationParser
|
|||
{
|
||||
if (annotation == null || !"org.eclipse.jetty.annotations.Sample".equals(annotation))
|
||||
return;
|
||||
assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassName());
|
||||
assertEquals("org.eclipse.jetty.annotations.ClassA",info.getClassInfo().getClassName());
|
||||
assertTrue(methods.contains(info.getMethodName()));
|
||||
assertEquals("org.eclipse.jetty.annotations.Sample",annotation);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class TestAnnotationParser
|
|||
{
|
||||
if (annotation == null || ! "org.eclipse.jetty.annotations.Multi".equals(annotation))
|
||||
return;
|
||||
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(info.getClassName()));
|
||||
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(info.getClassInfo().getClassName()));
|
||||
assertTrue("a".equals(info.getMethodName()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.List;
|
|||
import org.eclipse.jetty.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.servlet.ServletMapping;
|
||||
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -41,6 +42,27 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TestServletAnnotations
|
||||
{
|
||||
|
||||
public class TestWebServletAnnotationHandler extends WebServletAnnotationHandler
|
||||
{
|
||||
List<DiscoveredAnnotation> _list = null;
|
||||
|
||||
public TestWebServletAnnotationHandler(WebAppContext context, List<DiscoveredAnnotation> list)
|
||||
{
|
||||
super(context);
|
||||
_list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotation(DiscoveredAnnotation a)
|
||||
{
|
||||
super.addAnnotation(a);
|
||||
_list.add(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testServletAnnotation() throws Exception
|
||||
{
|
||||
|
@ -49,7 +71,9 @@ public class TestServletAnnotations
|
|||
AnnotationParser parser = new AnnotationParser();
|
||||
|
||||
WebAppContext wac = new WebAppContext();
|
||||
WebServletAnnotationHandler handler = new WebServletAnnotationHandler(wac);
|
||||
List<DiscoveredAnnotation> results = new ArrayList<DiscoveredAnnotation>();
|
||||
|
||||
TestWebServletAnnotationHandler handler = new TestWebServletAnnotationHandler(wac, results);
|
||||
parser.registerHandler(handler);
|
||||
|
||||
parser.parse(classes, new ClassNameResolver ()
|
||||
|
@ -65,10 +89,11 @@ public class TestServletAnnotations
|
|||
}
|
||||
});
|
||||
|
||||
assertEquals(1, handler.getAnnotationList().size());
|
||||
assertTrue(handler.getAnnotationList().get(0) instanceof WebServletAnnotation);
|
||||
|
||||
assertEquals(1, results.size());
|
||||
assertTrue(results.get(0) instanceof WebServletAnnotation);
|
||||
|
||||
handler.getAnnotationList().get(0).apply();
|
||||
results.get(0).apply();
|
||||
|
||||
ServletHolder[] holders = wac.getServletHandler().getServlets();
|
||||
assertNotNull(holders);
|
||||
|
|
|
@ -51,11 +51,6 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration
|
|||
throw new IllegalStateException ("No metadata");
|
||||
|
||||
parser.clearHandlers();
|
||||
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
@ -87,7 +82,7 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration
|
|||
public void doParse (final WebAppContext context, final AnnotationParser parser, Resource resource)
|
||||
throws Exception
|
||||
{
|
||||
parser.parseDir(resource, new ClassNameResolver()
|
||||
parser.parse(resource, new ClassNameResolver()
|
||||
{
|
||||
public boolean isExcluded (String name)
|
||||
{
|
||||
|
|
|
@ -152,16 +152,6 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
|
|||
Resource bundleRes = parser.getResource(bundle);
|
||||
|
||||
parser.clearHandlers();
|
||||
for (AbstractDiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
{
|
||||
if (webbundle == bundle)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null);
|
||||
else
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(bundleRes);
|
||||
}
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
|
|
@ -190,7 +190,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
|
|||
//transform into a classname to pass to the resolver
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
if ((resolver == null)|| (!resolver.isExcluded(shortName) && (!isParsed(shortName) || resolver.shouldOverride(shortName))))
|
||||
scanClass(classUrl.openStream());
|
||||
scanClass(getResource(bundle), classUrl.openStream());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
/**
|
||||
* EmptyResource
|
||||
*
|
||||
* Represents a resource that does does not refer to any file, url, jar etc.
|
||||
*/
|
||||
public class EmptyResource extends Resource
|
||||
{
|
||||
public static final Resource INSTANCE = new EmptyResource();
|
||||
|
||||
private EmptyResource()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContainedIn(Resource r) throws MalformedURLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastModified()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long length()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getURL()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableByteChannel getReadableByteChannel() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete() throws SecurityException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renameTo(Resource dest) throws SecurityException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] list()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource addPath(String path) throws IOException, MalformedURLException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.webapp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -28,6 +34,8 @@ import javax.servlet.ServletContext;
|
|||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.EmptyResource;
|
||||
import org.eclipse.jetty.util.resource.JarResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
|
||||
|
@ -43,18 +51,18 @@ public class MetaData
|
|||
private static final Logger LOG = Log.getLogger(MetaData.class);
|
||||
|
||||
public static final String ORDERED_LIBS = "javax.servlet.context.orderedLibs";
|
||||
public static final Resource NON_FRAG_RESOURCE = EmptyResource.INSTANCE;
|
||||
|
||||
protected Map<String, OriginInfo> _origins =new HashMap<String,OriginInfo>();
|
||||
protected WebDescriptor _webDefaultsRoot;
|
||||
protected WebDescriptor _webXmlRoot;
|
||||
protected final List<WebDescriptor> _webOverrideRoots=new ArrayList<WebDescriptor>();
|
||||
protected boolean _metaDataComplete;
|
||||
protected final List<DiscoveredAnnotation> _annotations = new ArrayList<DiscoveredAnnotation>();
|
||||
protected boolean _metaDataComplete;
|
||||
protected final List<DescriptorProcessor> _descriptorProcessors = new ArrayList<DescriptorProcessor>();
|
||||
protected final List<FragmentDescriptor> _webFragmentRoots = new ArrayList<FragmentDescriptor>();
|
||||
protected final Map<String,FragmentDescriptor> _webFragmentNameMap = new HashMap<String,FragmentDescriptor>();
|
||||
protected final Map<Resource, FragmentDescriptor> _webFragmentResourceMap = new HashMap<Resource, FragmentDescriptor>();
|
||||
protected final Map<Resource, List<DiscoveredAnnotation>> _webFragmentAnnotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
|
||||
protected final Map<Resource, List<DiscoveredAnnotation>> _annotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
|
||||
protected final List<Resource> _webInfClasses = new ArrayList<Resource>();
|
||||
protected final List<Resource> _webInfJars = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
|
||||
|
@ -135,7 +143,7 @@ public class MetaData
|
|||
_webFragmentRoots.clear();
|
||||
_webFragmentNameMap.clear();
|
||||
_webFragmentResourceMap.clear();
|
||||
_webFragmentAnnotations.clear();
|
||||
_annotations.clear();
|
||||
_webInfJars.clear();
|
||||
_orderedWebInfJars.clear();
|
||||
_orderedContainerResources.clear();
|
||||
|
@ -276,45 +284,37 @@ public class MetaData
|
|||
return;
|
||||
for (DiscoveredAnnotation a:annotations)
|
||||
{
|
||||
Resource r = a.getResource();
|
||||
if (r == null || !_webInfJars.contains(r))
|
||||
_annotations.add(a);
|
||||
else
|
||||
addDiscoveredAnnotation(a.getResource(), a);
|
||||
|
||||
addDiscoveredAnnotation(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addDiscoveredAnnotation(Resource resource, DiscoveredAnnotation annotation)
|
||||
{
|
||||
List<DiscoveredAnnotation> list = _webFragmentAnnotations.get(resource);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<DiscoveredAnnotation>();
|
||||
_webFragmentAnnotations.put(resource, list);
|
||||
}
|
||||
list.add(annotation);
|
||||
}
|
||||
|
||||
|
||||
public void addDiscoveredAnnotations(Resource resource, List<DiscoveredAnnotation> annotations)
|
||||
public void addDiscoveredAnnotation (DiscoveredAnnotation annotation)
|
||||
{
|
||||
List<DiscoveredAnnotation> list = _webFragmentAnnotations.get(resource);
|
||||
if (annotation == null)
|
||||
return;
|
||||
|
||||
//if no resource associated with an annotation or the resource is not one of the WEB-INF/lib jars,
|
||||
//map it to empty resource
|
||||
Resource resource = annotation.getResource();
|
||||
if (resource == null || !_webInfJars.contains(resource))
|
||||
resource = EmptyResource.INSTANCE;
|
||||
|
||||
List<DiscoveredAnnotation> list = _annotations.get(resource);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<DiscoveredAnnotation>();
|
||||
_webFragmentAnnotations.put(resource, list);
|
||||
_annotations.put(resource, list);
|
||||
}
|
||||
|
||||
list.addAll(annotations);
|
||||
list.add(annotation);
|
||||
}
|
||||
|
||||
|
||||
public void addDescriptorProcessor(DescriptorProcessor p)
|
||||
{
|
||||
_descriptorProcessors.add(p);
|
||||
}
|
||||
|
||||
|
||||
public void orderFragments ()
|
||||
{
|
||||
//if we have already ordered them don't do it again
|
||||
|
@ -373,13 +373,20 @@ public class MetaData
|
|||
}
|
||||
}
|
||||
|
||||
for (DiscoveredAnnotation a:_annotations)
|
||||
//get an apply the annotations that are not associated with a fragment (and hence for
|
||||
//which no ordering applies
|
||||
List<DiscoveredAnnotation> nonFragAnnotations = _annotations.get(NON_FRAG_RESOURCE);
|
||||
if (nonFragAnnotations != null)
|
||||
{
|
||||
LOG.debug("apply {}",a);
|
||||
a.apply();
|
||||
for (DiscoveredAnnotation a:nonFragAnnotations)
|
||||
{
|
||||
LOG.debug("apply {}",a);
|
||||
a.apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//apply the annotations that are associated with a fragment, according to the
|
||||
//established ordering
|
||||
List<Resource> resources = getOrderedWebInfJars();
|
||||
for (Resource r:resources)
|
||||
{
|
||||
|
@ -393,7 +400,7 @@ public class MetaData
|
|||
}
|
||||
}
|
||||
|
||||
List<DiscoveredAnnotation> fragAnnotations = _webFragmentAnnotations.get(r);
|
||||
List<DiscoveredAnnotation> fragAnnotations = _annotations.get(r);
|
||||
if (fragAnnotations != null)
|
||||
{
|
||||
for (DiscoveredAnnotation a:fragAnnotations)
|
||||
|
|
|
@ -62,7 +62,7 @@ public class ServerEndpointAnnotationHandler extends AbstractDiscoverableAnnotat
|
|||
return;
|
||||
}
|
||||
|
||||
ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,info.getClassName(),_resource);
|
||||
ServerEndpointAnnotation annotation = new ServerEndpointAnnotation(_context,info.getClassName(),info.getContainingResource());
|
||||
addAnnotation(annotation);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue