Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-09-05 08:31:53 +0000
committerJan Bartel2013-09-05 08:31:53 +0000
commit810fbdc439c9cf7b96494746fcc9ec73b032859d (patch)
treeebf629da761ce52866f32ea7a562ca83bb5855f9
parent6fb95b8ad7564af60fc945d69b5ec5667cdbdb6a (diff)
parentb8a4bf37e6b77a19498e9068222c9ccc8c3bd899 (diff)
downloadorg.eclipse.jetty.project-810fbdc439c9cf7b96494746fcc9ec73b032859d.tar.gz
org.eclipse.jetty.project-810fbdc439c9cf7b96494746fcc9ec73b032859d.tar.xz
org.eclipse.jetty.project-810fbdc439c9cf7b96494746fcc9ec73b032859d.zip
Merge remote-tracking branch 'origin/master' into jetty-9.1
-rw-r--r--jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java162
-rw-r--r--jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java28
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java12
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java136
4 files changed, 257 insertions, 81 deletions
diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java
index 5d1ac1c1d7..c26901f73e 100644
--- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java
+++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java
@@ -24,6 +24,7 @@ import java.util.EventListener;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
+import java.util.StringTokenizer;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.annotation.HandlesTypes;
@@ -59,6 +60,81 @@ public class AnnotationConfiguration extends AbstractConfiguration
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
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()]),
- new ClassNameResolver ()
- {
- 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;
- }
- });
-
-
+ new ContainerClassNameResolver (context));
}
@@ -432,24 +490,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
parser.registerHandlers(_discoverableAnnotationHandlers);
}
- parser.parse(uri,
- 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;
- }
- });
+ parser.parse(uri, new WebAppClassNameResolver(context));
}
}
}
@@ -465,45 +506,26 @@ public class AnnotationConfiguration extends AbstractConfiguration
throws Exception
{
LOG.debug("Scanning classes in WEB-INF/classes");
- if (context.getWebInf() != null)
+
+ parser.clearHandlers();
+ for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
{
- Resource classesDir = context.getWebInf().addPath("classes/");
- if (classesDir.exists())
- {
- parser.clearHandlers();
- for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
- {
- if (h instanceof AbstractDiscoverableAnnotationHandler)
- ((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
- }
- parser.registerHandlers(_discoverableAnnotationHandlers);
- parser.registerHandler(_classInheritanceHandler);
- parser.registerHandlers(_containerInitializerAnnotationHandlers);
-
- 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;
- }
- });
- }
+ if (h instanceof AbstractDiscoverableAnnotationHandler)
+ ((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
+ }
+ parser.registerHandlers(_discoverableAnnotationHandlers);
+ parser.registerHandler(_classInheritanceHandler);
+ parser.registerHandlers(_containerInitializerAnnotationHandlers);
+
+ for (Resource dir : context.getMetaData().getWebInfClassesDirs())
+ {
+ parser.parseDir(dir, new WebAppClassNameResolver(context));
}
}
- /**
+ /**
* Get the web-fragment.xml from a jar
*
* @param jar
diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java
index c698cc2d47..057d0ea22a 100644
--- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java
+++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java
@@ -752,7 +752,7 @@ public class AnnotationParser
return;
if (LOG.isDebugEnabled()) {LOG.debug("Scanning dir {}", dir);};
-
+
String[] files=dir.list();
for (int f=0;files!=null && f<files.length;f++)
{
@@ -854,7 +854,7 @@ public class AnnotationParser
}
/**
- * Parse a particular resource
+ * Parse a particular uri
* @param uri
* @param resolver
* @throws Exception
@@ -865,7 +865,24 @@ public class AnnotationParser
if (uri == null)
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())
{
parseDir(r, resolver);
@@ -885,11 +902,10 @@ public class AnnotationParser
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.
*
@@ -904,7 +920,6 @@ public class AnnotationParser
return;
URI uri = jarResource.getURI();
-
if (jarResource.toString().endsWith(".jar"))
{
if (LOG.isDebugEnabled()) {LOG.debug("Scanning jar {}", jarResource);};
@@ -1031,7 +1046,6 @@ public class AnnotationParser
if (path == null || path.length()==0)
return false;
-
//skip any classfiles that are in a hidden directory
if (path.startsWith(".") || path.contains("/."))
{
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java
index eee8191c15..c5978f8422 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java
@@ -55,6 +55,7 @@ public class MetaData
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 List<Resource> _webInfClasses = new ArrayList<Resource>();
protected final List<Resource> _webInfJars = new ArrayList<Resource>();
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
@@ -573,6 +574,17 @@ public class MetaData
{
_orderedContainerResources.add(jar);
}
+
+ public void setWebInfClassesDirs (List<Resource> dirs)
+ {
+ _webInfClasses.addAll(dirs);
+ }
+
+ public List<Resource> getWebInfClassesDirs ()
+ {
+ return _webInfClasses;
+ }
+
public boolean isAllowDuplicateFragmentNames()
{
return allowDuplicateFragmentNames;
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java
index e360faf76e..d0d4085161 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java
@@ -27,6 +27,7 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.StringTokenizer;
import java.util.regex.Pattern;
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
+
+ //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();
}
+
+ 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
* @return the list of jar resources found within context
* @throws Exception
@@ -704,14 +729,31 @@ public class WebInfConfiguration extends AbstractConfiguration
throws Exception
{
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();
if (web_inf==null || !web_inf.exists())
return null;
+ List<Resource> jarResources = new ArrayList<Resource>();
Resource web_inf_lib = web_inf.addPath("/lib");
-
-
if (web_inf_lib.exists() && web_inf_lib.isDirectory())
{
String[] files=web_inf_lib.list();
@@ -736,4 +778,90 @@ public class WebInfConfiguration extends AbstractConfiguration
}
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;
+ }
+
+
}

Back to the top