Merge remote-tracking branch 'origin/master' into jetty-9.1
This commit is contained in:
commit
810fbdc439
|
@ -24,6 +24,7 @@ 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;
|
||||||
|
@ -59,6 +60,81 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
protected List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<ContainerInitializerAnnotationHandler>();
|
protected List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<ContainerInitializerAnnotationHandler>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebAppClassNameResolver
|
||||||
|
*
|
||||||
|
* Checks to see if a classname belongs to hidden or visible packages when scanning,
|
||||||
|
* and whether a classname that is a duplicate should override a previously
|
||||||
|
* scanned classname.
|
||||||
|
*
|
||||||
|
* This is analogous to the management of classes that the WebAppClassLoader is doing,
|
||||||
|
* however we don't want to load the classes at this point so we are doing it on
|
||||||
|
* the name only.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WebAppClassNameResolver implements ClassNameResolver
|
||||||
|
{
|
||||||
|
private WebAppContext _context;
|
||||||
|
|
||||||
|
public WebAppClassNameResolver (WebAppContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContainerClassNameResolver
|
||||||
|
*
|
||||||
|
* Checks to see if a classname belongs to a hidden or visible package
|
||||||
|
* when scanning for annotations and thus whether it should be excluded from
|
||||||
|
* consideration or not.
|
||||||
|
*
|
||||||
|
* This is analogous to the management of classes that the WebAppClassLoader is doing,
|
||||||
|
* however we don't want to load the classes at this point so we are doing it on
|
||||||
|
* the name only.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ContainerClassNameResolver implements ClassNameResolver
|
||||||
|
{
|
||||||
|
private WebAppContext _context;
|
||||||
|
|
||||||
|
public ContainerClassNameResolver (WebAppContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
public boolean isExcluded (String name)
|
||||||
|
{
|
||||||
|
if (_context.isSystemClass(name)) return false;
|
||||||
|
if (_context.isServerClass(name)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldOverride (String name)
|
||||||
|
{
|
||||||
|
//visiting the container classpath,
|
||||||
|
if (_context.isParentLoaderPriority())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preConfigure(final WebAppContext context) throws Exception
|
public void preConfigure(final WebAppContext context) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -356,25 +432,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.parse (containerUris.toArray(new URI[containerUris.size()]),
|
parser.parse (containerUris.toArray(new URI[containerUris.size()]),
|
||||||
new ClassNameResolver ()
|
new ContainerClassNameResolver (context));
|
||||||
{
|
|
||||||
public boolean isExcluded (String name)
|
|
||||||
{
|
|
||||||
if (context.isSystemClass(name)) return false;
|
|
||||||
if (context.isServerClass(name)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldOverride (String name)
|
|
||||||
{
|
|
||||||
//looking at system classpath
|
|
||||||
if (context.isParentLoaderPriority())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -432,24 +490,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.parse(uri,
|
parser.parse(uri, new WebAppClassNameResolver(context));
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,11 +506,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
LOG.debug("Scanning classes in WEB-INF/classes");
|
LOG.debug("Scanning classes in WEB-INF/classes");
|
||||||
if (context.getWebInf() != null)
|
|
||||||
{
|
|
||||||
Resource classesDir = context.getWebInf().addPath("classes/");
|
|
||||||
if (classesDir.exists())
|
|
||||||
{
|
|
||||||
parser.clearHandlers();
|
parser.clearHandlers();
|
||||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||||
{
|
{
|
||||||
|
@ -480,24 +517,9 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
parser.registerHandler(_classInheritanceHandler);
|
parser.registerHandler(_classInheritanceHandler);
|
||||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||||
|
|
||||||
parser.parseDir(classesDir,
|
for (Resource dir : context.getMetaData().getWebInfClassesDirs())
|
||||||
new ClassNameResolver()
|
|
||||||
{
|
{
|
||||||
public boolean isExcluded (String name)
|
parser.parseDir(dir, new WebAppClassNameResolver(context));
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -854,7 +854,7 @@ public class AnnotationParser
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a particular resource
|
* Parse a particular uri
|
||||||
* @param uri
|
* @param uri
|
||||||
* @param resolver
|
* @param resolver
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -865,7 +865,24 @@ public class AnnotationParser
|
||||||
if (uri == null)
|
if (uri == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Resource r = Resource.newResource(uri);
|
parse (Resource.newResource(uri), resolver);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a resource
|
||||||
|
* @param r
|
||||||
|
* @param resolver
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void parse (Resource r, final ClassNameResolver resolver)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (r == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (r.exists() && r.isDirectory())
|
if (r.exists() && r.isDirectory())
|
||||||
{
|
{
|
||||||
parseDir(r, resolver);
|
parseDir(r, resolver);
|
||||||
|
@ -885,11 +902,10 @@ public class AnnotationParser
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) LOG.warn("Resource not scannable for classes: {}", uri);
|
if (LOG.isDebugEnabled()) LOG.warn("Resource not scannable for classes: {}", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a resource that is a jar file.
|
* Parse a resource that is a jar file.
|
||||||
*
|
*
|
||||||
|
@ -904,7 +920,6 @@ public class AnnotationParser
|
||||||
return;
|
return;
|
||||||
|
|
||||||
URI uri = jarResource.getURI();
|
URI uri = jarResource.getURI();
|
||||||
|
|
||||||
if (jarResource.toString().endsWith(".jar"))
|
if (jarResource.toString().endsWith(".jar"))
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning jar {}", jarResource);};
|
if (LOG.isDebugEnabled()) {LOG.debug("Scanning jar {}", jarResource);};
|
||||||
|
@ -1031,7 +1046,6 @@ public class AnnotationParser
|
||||||
if (path == null || path.length()==0)
|
if (path == null || path.length()==0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
//skip any classfiles that are in a hidden directory
|
//skip any classfiles that are in a hidden directory
|
||||||
if (path.startsWith(".") || path.contains("/."))
|
if (path.startsWith(".") || path.contains("/."))
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class MetaData
|
||||||
protected final Map<String,FragmentDescriptor> _webFragmentNameMap = new HashMap<String,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, FragmentDescriptor> _webFragmentResourceMap = new HashMap<Resource, FragmentDescriptor>();
|
||||||
protected final Map<Resource, List<DiscoveredAnnotation>> _webFragmentAnnotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
|
protected final Map<Resource, List<DiscoveredAnnotation>> _webFragmentAnnotations = 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> _webInfJars = new ArrayList<Resource>();
|
||||||
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
|
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
|
||||||
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
|
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
|
||||||
|
@ -573,6 +574,17 @@ public class MetaData
|
||||||
{
|
{
|
||||||
_orderedContainerResources.add(jar);
|
_orderedContainerResources.add(jar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWebInfClassesDirs (List<Resource> dirs)
|
||||||
|
{
|
||||||
|
_webInfClasses.addAll(dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Resource> getWebInfClassesDirs ()
|
||||||
|
{
|
||||||
|
return _webInfClasses;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAllowDuplicateFragmentNames()
|
public boolean isAllowDuplicateFragmentNames()
|
||||||
{
|
{
|
||||||
return allowDuplicateFragmentNames;
|
return allowDuplicateFragmentNames;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
|
@ -139,6 +140,9 @@ public class WebInfConfiguration extends AbstractConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webInfJarNameMatcher.match(webInfPattern, uris, true); //null is inclusive, no pattern == all jars match
|
webInfJarNameMatcher.match(webInfPattern, uris, true); //null is inclusive, no pattern == all jars match
|
||||||
|
|
||||||
|
//No pattern to appy to classes, just add to metadata
|
||||||
|
context.getMetaData().setWebInfClassesDirs(findClassDirs(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -694,8 +698,29 @@ public class WebInfConfiguration extends AbstractConfiguration
|
||||||
return canonicalName.toString();
|
return canonicalName.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected List<Resource> findClassDirs (WebAppContext context)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<Resource> classDirs = new ArrayList<Resource>();
|
||||||
|
|
||||||
|
Resource webInfClasses = findWebInfClassesDir(context);
|
||||||
|
if (webInfClasses != null)
|
||||||
|
classDirs.add(webInfClasses);
|
||||||
|
List<Resource> extraClassDirs = findExtraClasspathDirs(context);
|
||||||
|
if (extraClassDirs != null)
|
||||||
|
classDirs.addAll(extraClassDirs);
|
||||||
|
|
||||||
|
return classDirs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for jars in WEB-INF/lib
|
* Look for jars that should be treated as if they are in WEB-INF/lib
|
||||||
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return the list of jar resources found within context
|
* @return the list of jar resources found within context
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -704,14 +729,31 @@ public class WebInfConfiguration extends AbstractConfiguration
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
List<Resource> jarResources = new ArrayList<Resource>();
|
List<Resource> jarResources = new ArrayList<Resource>();
|
||||||
|
List<Resource> webInfLibJars = findWebInfLibJars(context);
|
||||||
|
if (webInfLibJars != null)
|
||||||
|
jarResources.addAll(webInfLibJars);
|
||||||
|
List<Resource> extraClasspathJars = findExtraClasspathJars(context);
|
||||||
|
if (extraClasspathJars != null)
|
||||||
|
jarResources.addAll(extraClasspathJars);
|
||||||
|
return jarResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look for jars in WEB-INF/lib
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected List<Resource> findWebInfLibJars(WebAppContext context)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
Resource web_inf = context.getWebInf();
|
Resource web_inf = context.getWebInf();
|
||||||
if (web_inf==null || !web_inf.exists())
|
if (web_inf==null || !web_inf.exists())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
List<Resource> jarResources = new ArrayList<Resource>();
|
||||||
Resource web_inf_lib = web_inf.addPath("/lib");
|
Resource web_inf_lib = web_inf.addPath("/lib");
|
||||||
|
|
||||||
|
|
||||||
if (web_inf_lib.exists() && web_inf_lib.isDirectory())
|
if (web_inf_lib.exists() && web_inf_lib.isDirectory())
|
||||||
{
|
{
|
||||||
String[] files=web_inf_lib.list();
|
String[] files=web_inf_lib.list();
|
||||||
|
@ -736,4 +778,90 @@ public class WebInfConfiguration extends AbstractConfiguration
|
||||||
}
|
}
|
||||||
return jarResources;
|
return jarResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get jars from WebAppContext.getExtraClasspath as resources
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected List<Resource> findExtraClasspathJars(WebAppContext context)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (context == null || context.getExtraClasspath() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<Resource> jarResources = new ArrayList<Resource>();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(context.getExtraClasspath(), ",;");
|
||||||
|
while (tokenizer.hasMoreTokens())
|
||||||
|
{
|
||||||
|
Resource resource = context.newResource(tokenizer.nextToken().trim());
|
||||||
|
String fnlc = resource.getName().toLowerCase(Locale.ENGLISH);
|
||||||
|
int dot = fnlc.lastIndexOf('.');
|
||||||
|
String extension = (dot < 0 ? null : fnlc.substring(dot));
|
||||||
|
if (extension != null && (extension.equals(".jar") || extension.equals(".zip")))
|
||||||
|
{
|
||||||
|
jarResources.add(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jarResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get WEB-INF/classes dir
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected Resource findWebInfClassesDir (WebAppContext context)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Resource web_inf = context.getWebInf();
|
||||||
|
|
||||||
|
// Find WEB-INF/classes
|
||||||
|
if (web_inf != null && web_inf.isDirectory())
|
||||||
|
{
|
||||||
|
// Look for classes directory
|
||||||
|
Resource classes= web_inf.addPath("classes/");
|
||||||
|
if (classes.exists())
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get class dirs from WebAppContext.getExtraClasspath as resources
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected List<Resource> findExtraClasspathDirs(WebAppContext context)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (context == null || context.getExtraClasspath() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<Resource> dirResources = new ArrayList<Resource>();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(context.getExtraClasspath(), ",;");
|
||||||
|
while (tokenizer.hasMoreTokens())
|
||||||
|
{
|
||||||
|
Resource resource = context.newResource(tokenizer.nextToken().trim());
|
||||||
|
if (resource.exists() && resource.isDirectory())
|
||||||
|
dirResources.add(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue