Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-09-26 08:26:13 +0000
committerJan Bartel2013-09-30 03:27:05 +0000
commit04002898263b3d408f7f4851906dfcb7185902ee (patch)
tree47886b39b850fb96f7c1a5872eb964556590001b /jetty-webapp
parent0fd656dcbe0102c7e9deecaac9ac4de1a5016c62 (diff)
downloadorg.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.tar.gz
org.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.tar.xz
org.eclipse.jetty.project-04002898263b3d408f7f4851906dfcb7185902ee.zip
417561 Refactor annotation related code - make annotation phase able to be multithreaded
Diffstat (limited to 'jetty-webapp')
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java12
-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/MetaInfConfiguration.java113
-rw-r--r--jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java8
4 files changed, 55 insertions, 90 deletions
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java
index eb8129228f..ff28d0562a 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java
@@ -19,7 +19,7 @@
package org.eclipse.jetty.webapp;
-import java.util.List;
+import java.util.Map;
import org.eclipse.jetty.util.resource.Resource;
@@ -70,18 +70,18 @@ public class FragmentConfiguration extends AbstractConfiguration
public void findWebFragments (final WebAppContext context, final MetaData metaData) throws Exception
{
@SuppressWarnings("unchecked")
- List<Resource> frags = (List<Resource>)context.getAttribute(FRAGMENT_RESOURCES);
+ Map<Resource, Resource> frags = (Map<Resource,Resource>)context.getAttribute(FRAGMENT_RESOURCES);
if (frags!=null)
{
- for (Resource frag : frags)
+ for (Resource key : frags.keySet())
{
- if (frag.isDirectory()) //tolerate the case where the library is a directory, not a jar. useful for OSGi for example
+ if (key.isDirectory()) //tolerate the case where the library is a directory, not a jar. useful for OSGi for example
{
- metaData.addFragment(frag, Resource.newResource(frag.getURL()+"/META-INF/web-fragment.xml"));
+ metaData.addFragment(key, frags.get(key));
}
else //the standard case: a jar most likely inside WEB-INF/lib
{
- metaData.addFragment(frag, Resource.newResource("jar:"+frag.getURL()+"!/META-INF/web-fragment.xml"));
+ metaData.addFragment(key, frags.get(key));
}
}
}
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 7c476586a9..1bd781e873 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
@@ -288,7 +288,17 @@ public class MetaData
}
}
- public void addDiscoveredAnnotation (DiscoveredAnnotation annotation)
+
+ /**
+ * Add an annotation that has been discovered on a class, method or field within a resource
+ * eg a jar or dir.
+ *
+ * This method is synchronized as it is anticipated that it may be called by many threads
+ * during the annotation scanning phase.
+ *
+ * @param annotation
+ */
+ public synchronized void addDiscoveredAnnotation (DiscoveredAnnotation annotation)
{
if (annotation == null)
return;
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java
index df913b508d..b7c4e0f0b2 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java
@@ -21,8 +21,13 @@ package org.eclipse.jetty.webapp;
import java.net.URI;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import org.eclipse.jetty.util.log.Log;
@@ -45,57 +50,51 @@ public class MetaInfConfiguration extends AbstractConfiguration
public static final String METAINF_TLDS = TagLibConfiguration.TLD_RESOURCES;
public static final String METAINF_FRAGMENTS = FragmentConfiguration.FRAGMENT_RESOURCES;
- public static final String METAINF_RESOURCES = WebInfConfiguration.RESOURCE_URLS;
+ public static final String METAINF_RESOURCES = WebInfConfiguration.RESOURCE_DIRS;
@Override
public void preConfigure(final WebAppContext context) throws Exception
{
- //Merge all container and webinf lib jars to look for META-INF resources
-
+ //Merge all container and webinf lib jars to look for META-INF resources
ArrayList<Resource> jars = new ArrayList<Resource>();
jars.addAll(context.getMetaData().getContainerResources());
jars.addAll(context.getMetaData().getWebInfJars());
- JarScanner scanner = new JarScanner()
+ //Scan jars for META-INF information
+ if (jars != null)
{
- public void processEntry(URI jarUri, JarEntry entry)
+ for (Resource r : jars)
{
- try
+ URI uri = r.getURI();
+ Resource fragXml = Resource.newResource("jar:"+uri+"!/META-INF/web-fragment.xml");
+ if (fragXml.exists())
{
- MetaInfConfiguration.this.processEntry(context,jarUri,entry);
+ //add mapping for resource->fragment
+ Map<Resource, Resource> fragments = (Map<Resource,Resource>)context.getAttribute(METAINF_FRAGMENTS);
+ if (fragments == null)
+ {
+ fragments = new HashMap<Resource, Resource>();
+ context.setAttribute(METAINF_FRAGMENTS, fragments);
+ }
+ fragments.put(r, fragXml);
}
- catch (Exception e)
+
+ Resource resourcesDir = Resource.newResource("jar:"+uri+"!/META-INF/resources");
+ if (resourcesDir.exists())
{
- LOG.warn("Problem processing jar entry " + entry, e);
+ //add resources dir
+ Set<Resource> dirs = (Set<Resource>)context.getAttribute(METAINF_RESOURCES);
+ if (dirs == null)
+ {
+ dirs = new HashSet<Resource>();
+ context.setAttribute(METAINF_RESOURCES, dirs);
+ }
+ dirs.add(resourcesDir);
}
}
- };
-
-
- //Scan jars for META-INF information
- if (jars != null)
- {
- URI[] uris = new URI[jars.size()];
- int i=0;
- for (Resource r : jars)
- {
- uris[i++] = r.getURI();
- }
- scanner.scan(null, uris, true);
}
}
- @Override
- public void configure(WebAppContext context) throws Exception
- {
-
- }
-
- @Override
- public void deconfigure(WebAppContext context) throws Exception
- {
-
- }
-
+
@Override
public void postConfigure(WebAppContext context) throws Exception
{
@@ -103,50 +102,4 @@ public class MetaInfConfiguration extends AbstractConfiguration
context.setAttribute(METAINF_RESOURCES, null);
context.setAttribute(METAINF_TLDS, null);
}
-
- public void addResource (WebAppContext context, String attribute, Resource jar)
- {
- @SuppressWarnings("unchecked")
- List<Resource> list = (List<Resource>)context.getAttribute(attribute);
- if (list==null)
- {
- list=new ArrayList<Resource>();
- context.setAttribute(attribute,list);
- }
- if (!list.contains(jar))
- list.add(jar);
- }
-
-
- protected void processEntry(WebAppContext context, URI jarUri, JarEntry entry)
- {
- String name = entry.getName();
-
- if (!name.startsWith("META-INF/"))
- return;
-
- try
- {
- if (name.equals("META-INF/web-fragment.xml") && context.isConfigurationDiscovered())
- {
- addResource(context,METAINF_FRAGMENTS,Resource.newResource(jarUri));
- }
- else if (name.equals("META-INF/resources/") && context.isConfigurationDiscovered())
- {
- addResource(context,METAINF_RESOURCES,Resource.newResource("jar:"+jarUri+"!/META-INF/resources"));
- }
- else
- {
- String lcname = name.toLowerCase(Locale.ENGLISH);
- if (lcname.endsWith(".tld"))
- {
- addResource(context,METAINF_TLDS,Resource.newResource("jar:"+jarUri+"!/"+name));
- }
- }
- }
- catch(Exception e)
- {
- context.getServletContext().log(jarUri+"!/"+name,e);
- }
- }
}
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 d0d4085161..d9ebc2fb9e 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,7 +27,9 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
import java.util.StringTokenizer;
+import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.eclipse.jetty.server.Connector;
@@ -54,7 +56,7 @@ public class WebInfConfiguration extends AbstractConfiguration
* If set, to a list of URLs, these resources are added to the context
* resource base as a resource collection.
*/
- public static final String RESOURCE_URLS = "org.eclipse.jetty.resources";
+ public static final String RESOURCE_DIRS = "org.eclipse.jetty.resources";
protected Resource _preUnpackBaseResource;
@@ -140,7 +142,7 @@ 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));
}
@@ -175,7 +177,7 @@ public class WebInfConfiguration extends AbstractConfiguration
// Look for extra resource
@SuppressWarnings("unchecked")
- List<Resource> resources = (List<Resource>)context.getAttribute(RESOURCE_URLS);
+ Set<Resource> resources = (Set<Resource>)context.getAttribute(RESOURCE_DIRS);
if (resources!=null)
{
Resource[] collection=new Resource[resources.size()+1];

Back to the top