404176 Jetty's AnnotationConfiguration class does not scan non-jar resources on the container classpath
This commit is contained in:
parent
ea60965803
commit
4951b1ccc4
|
@ -326,10 +326,10 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
|
||||
//Convert from Resource to URI
|
||||
ArrayList<URI> containerUris = new ArrayList<URI>();
|
||||
for (Resource r : context.getMetaData().getOrderedContainerJars())
|
||||
for (Resource r : context.getMetaData().getContainerResources())
|
||||
{
|
||||
URI uri = r.getURI();
|
||||
containerUris.add(uri);
|
||||
containerUris.add(uri);
|
||||
}
|
||||
|
||||
parser.parse (containerUris.toArray(new URI[containerUris.size()]),
|
||||
|
@ -457,24 +457,23 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
||||
parser.parse(classesDir,
|
||||
new ClassNameResolver()
|
||||
{
|
||||
public boolean isExcluded (String name)
|
||||
{
|
||||
if (context.isSystemClass(name)) return true;
|
||||
if (context.isServerClass(name)) return false;
|
||||
return false;
|
||||
}
|
||||
parser.parseDir(classesDir,
|
||||
new ClassNameResolver()
|
||||
{
|
||||
public boolean isExcluded (String name)
|
||||
{
|
||||
if (context.isSystemClass(name)) return true;
|
||||
if (context.isServerClass(name)) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldOverride (String name)
|
||||
{
|
||||
//looking at webapp classpath, found already-parsed class of same name - did it come from system or duplicate in webapp?
|
||||
if (context.isParentLoaderPriority())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
public boolean shouldOverride (String name)
|
||||
{
|
||||
//looking at webapp classpath, found already-parsed class of same name - did it come from system or duplicate in webapp?
|
||||
if (context.isParentLoaderPriority()) return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
import org.eclipse.jetty.util.Loader;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -749,13 +750,14 @@ public class AnnotationParser
|
|||
* @param resolver
|
||||
* @throws Exception
|
||||
*/
|
||||
public void parse (Resource dir, ClassNameResolver resolver)
|
||||
public void parseDir (Resource dir, ClassNameResolver resolver)
|
||||
throws Exception
|
||||
{
|
||||
if (!dir.isDirectory() || !dir.exists())
|
||||
return;
|
||||
|
||||
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning dir {}", dir);};
|
||||
|
||||
String[] files=dir.list();
|
||||
for (int f=0;files!=null && f<files.length;f++)
|
||||
{
|
||||
|
@ -763,13 +765,14 @@ public class AnnotationParser
|
|||
{
|
||||
Resource res = dir.addPath(files[f]);
|
||||
if (res.isDirectory())
|
||||
parse(res, resolver);
|
||||
parseDir(res, resolver);
|
||||
String name = res.getName();
|
||||
if (name.endsWith(".class"))
|
||||
{
|
||||
if ((resolver == null)|| (!resolver.isExcluded(name) && (!isParsed(name) || resolver.shouldOverride(name))))
|
||||
{
|
||||
Resource r = Resource.newResource(res.getURL());
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class {}", r);};
|
||||
scanClass(r.getInputStream());
|
||||
}
|
||||
|
||||
|
@ -836,7 +839,7 @@ public class AnnotationParser
|
|||
|
||||
|
||||
/**
|
||||
* Parse classes in the supplied url of jar files.
|
||||
* Parse classes in the supplied uris.
|
||||
*
|
||||
* @param uris
|
||||
* @param resolver
|
||||
|
@ -848,36 +851,18 @@ public class AnnotationParser
|
|||
if (uris==null)
|
||||
return;
|
||||
|
||||
JarScanner scanner = new JarScanner()
|
||||
for (URI uri:uris)
|
||||
{
|
||||
@Override
|
||||
public void processEntry(URI jarUri, JarEntry entry)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
|
||||
if ((resolver == null)
|
||||
||
|
||||
(!resolver.isExcluded(shortName) && (!isParsed(shortName) || resolver.shouldOverride(shortName))))
|
||||
{
|
||||
Resource clazz = Resource.newResource("jar:"+jarUri+"!/"+name);
|
||||
scanClass(clazz.getInputStream());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Problem processing jar entry "+entry, e);
|
||||
}
|
||||
parse(uri, resolver);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Problem parsing classes from {}", uri);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
scanner.scan(null, uris, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -891,10 +876,91 @@ public class AnnotationParser
|
|||
{
|
||||
if (uri == null)
|
||||
return;
|
||||
URI[] uris = {uri};
|
||||
parse(uris, resolver);
|
||||
|
||||
Resource r = Resource.newResource(uri);
|
||||
if (r.exists() && r.isDirectory())
|
||||
{
|
||||
parseDir(r, resolver);
|
||||
return;
|
||||
}
|
||||
|
||||
String fullname = r.toString();
|
||||
if (fullname.endsWith(".jar"))
|
||||
{
|
||||
parseJar(r, resolver);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fullname.endsWith(".class"))
|
||||
{
|
||||
scanClass(r.getInputStream());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse a resource that is a jar file.
|
||||
*
|
||||
* @param jarResource
|
||||
* @param resolver
|
||||
* @throws Exception
|
||||
*/
|
||||
public 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);};
|
||||
|
||||
//treat it as a jar that we need to open and scan all entries from
|
||||
InputStream in = jarResource.getInputStream();
|
||||
if (in==null)
|
||||
return;
|
||||
|
||||
JarInputStream jar_in = new JarInputStream(in);
|
||||
try
|
||||
{
|
||||
JarEntry entry = jar_in.getNextJarEntry();
|
||||
while (entry!=null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
|
||||
if ((resolver == null)
|
||||
||
|
||||
(!resolver.isExcluded(shortName) && (!isParsed(shortName) || resolver.shouldOverride(shortName))))
|
||||
{
|
||||
Resource clazz = Resource.newResource("jar:"+uri+"!/"+name);
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class from jar {}", clazz);};
|
||||
scanClass(clazz.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Problem processing jar entry "+entry, e);
|
||||
}
|
||||
|
||||
entry = jar_in.getNextJarEntry();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
jar_in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,7 +66,7 @@ public class AntWebInfConfiguration extends WebInfConfiguration
|
|||
{
|
||||
public void matched(URI uri) throws Exception
|
||||
{
|
||||
context.getMetaData().addContainerJar(Resource.newResource(uri));
|
||||
context.getMetaData().addContainerResource(Resource.newResource(uri));
|
||||
}
|
||||
};
|
||||
ClassLoader loader = context.getClassLoader();
|
||||
|
|
|
@ -88,7 +88,7 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration
|
|||
public void doParse (final WebAppContext context, final AnnotationParser parser, Resource resource)
|
||||
throws Exception
|
||||
{
|
||||
parser.parse(resource, new ClassNameResolver()
|
||||
parser.parseDir(resource, new ClassNameResolver()
|
||||
{
|
||||
public boolean isExcluded (String name)
|
||||
{
|
||||
|
|
|
@ -115,7 +115,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
|
|||
|
||||
for (Resource r:matchingResources)
|
||||
{
|
||||
context.getMetaData().addContainerJar(r);
|
||||
context.getMetaData().addContainerResource(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class MetaData
|
|||
protected final Map<Resource, List<DiscoveredAnnotation>> _webFragmentAnnotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
|
||||
protected final List<Resource> _webInfJars = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedContainerJars = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
|
||||
protected Ordering _ordering;//can be set to RelativeOrdering by web-default.xml, web.xml, web-override.xml
|
||||
protected boolean allowDuplicateFragmentNames = false;
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class MetaData
|
|||
_webFragmentAnnotations.clear();
|
||||
_webInfJars.clear();
|
||||
_orderedWebInfJars.clear();
|
||||
_orderedContainerJars.clear();
|
||||
_orderedContainerResources.clear();
|
||||
_ordering = null;
|
||||
allowDuplicateFragmentNames = false;
|
||||
}
|
||||
|
@ -564,14 +564,14 @@ public class MetaData
|
|||
return Collections.unmodifiableList(_webInfJars);
|
||||
}
|
||||
|
||||
public List<Resource> getOrderedContainerJars()
|
||||
public List<Resource> getContainerResources()
|
||||
{
|
||||
return _orderedContainerJars;
|
||||
return _orderedContainerResources;
|
||||
}
|
||||
|
||||
public void addContainerJar(Resource jar)
|
||||
public void addContainerResource(Resource jar)
|
||||
{
|
||||
_orderedContainerJars.add(jar);
|
||||
_orderedContainerResources.add(jar);
|
||||
}
|
||||
public boolean isAllowDuplicateFragmentNames()
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
//Merge all container and webinf lib jars to look for META-INF resources
|
||||
|
||||
ArrayList<Resource> jars = new ArrayList<Resource>();
|
||||
jars.addAll(context.getMetaData().getOrderedContainerJars());
|
||||
jars.addAll(context.getMetaData().getContainerResources());
|
||||
jars.addAll(context.getMetaData().getWebInfJars());
|
||||
|
||||
JarScanner scanner = new JarScanner()
|
||||
|
|
|
@ -85,7 +85,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public void matched(URI uri) throws Exception
|
||||
{
|
||||
context.getMetaData().addContainerJar(Resource.newResource(uri));
|
||||
context.getMetaData().addContainerResource(Resource.newResource(uri));
|
||||
}
|
||||
};
|
||||
ClassLoader loader = context.getClassLoader();
|
||||
|
|
Loading…
Reference in New Issue