diff options
Diffstat (limited to 'jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java')
-rw-r--r-- | jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java | 113 |
1 files changed, 33 insertions, 80 deletions
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); - } - } } |