improved scanning of META-INF
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@275 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
577684b4c9
commit
bc8b0d7b37
|
@ -22,7 +22,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>javax.servlet.*;version="[2.5,3.0)",*</Import-Package>
|
||||
<Import-Package>javax.servlet.*;version="[2.5,3.1)",*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -70,7 +70,7 @@
|
|||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<version>3.0.PFD20090525</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -97,7 +97,8 @@ public class AsyncRequest implements AsyncContext, Continuation
|
|||
{
|
||||
synchronized(this)
|
||||
{
|
||||
_listeners=LazyList.add(_listeners,listener);
|
||||
if ((listener instanceof ContinuationListener))
|
||||
_listeners=LazyList.add(_listeners,listener);
|
||||
// _history.append('L');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
|
|
@ -51,7 +51,6 @@ public class AsyncContextTest extends TestCase
|
|||
|
||||
_handler.setRead(0);
|
||||
_handler.setSuspendFor(1000);
|
||||
|
||||
_handler.setResumeAfter(-1);
|
||||
_handler.setCompleteAfter(-1);
|
||||
check("TIMEOUT",process(null));
|
||||
|
|
|
@ -40,7 +40,6 @@ public class Holder extends AbstractLifeCycle
|
|||
protected Map _initParams;
|
||||
protected boolean _extInstance;
|
||||
protected boolean _asyncSupported=true;
|
||||
protected AttributesMap _initAttributes;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
protected String _name;
|
||||
|
@ -275,26 +274,6 @@ public class Holder extends AbstractLifeCycle
|
|||
{
|
||||
return Holder.this.getInitParameterNames();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see javax.servlet.ServletConfig#getInitAttribute(java.lang.String)
|
||||
*/
|
||||
public Object getInitAttribute(String name)
|
||||
{
|
||||
return (Holder.this._initAttributes==null)?null:Holder.this._initAttributes.getAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see javax.servlet.ServletConfig#getInitAttributeNames()
|
||||
*/
|
||||
public Iterable<String> getInitAttributeNames()
|
||||
{
|
||||
if (Holder.this._initAttributes!=null)
|
||||
return Holder.this._initAttributes.keySet();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class FragmentConfiguration implements Configuration
|
||||
{
|
||||
public final static String FRAGMENT_RESOURCES="org.eclipse.jetty.webFragments";
|
||||
|
||||
public void preConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
if (!context.isConfigurationDiscovered())
|
||||
|
@ -75,7 +77,6 @@ public class FragmentConfiguration implements Configuration
|
|||
public void postConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
|
@ -90,42 +91,11 @@ public class FragmentConfiguration implements Configuration
|
|||
String tmp = (String) context.getInitParameter("org.eclipse.jetty.webapp.WebXmlFragmentPattern");
|
||||
Pattern webFragPattern = (tmp == null ? null : Pattern.compile(tmp));
|
||||
|
||||
List<URL> urls = (List<URL>)context.getAttribute(MetaInfConfiguration.JARS_WITH_FRAGMENTS);
|
||||
|
||||
JarScanner fragScanner = new JarScanner()
|
||||
List<Resource> frags = (List<Resource>)context.getAttribute(MetaInfConfiguration.METAINF_FRAGMENTS);
|
||||
if (frags!=null)
|
||||
{
|
||||
public void processEntry(URL jarUrl, JarEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase().equals("meta-inf/web-fragment.xml"))
|
||||
{
|
||||
Resource webXmlFrag = context.newResource("jar:" + jarUrl + "!/" + name);
|
||||
Log.debug("web.xml fragment found {}", webXmlFrag);
|
||||
// Process web.xml
|
||||
// web-fragment
|
||||
// servlet
|
||||
// servlet-mapping
|
||||
// filter
|
||||
// filter-mapping
|
||||
// listener
|
||||
processor.parseFragment(webXmlFrag.getURL());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("Problem processing jar entry " + entry, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//process only the jars that have web fragments in them, according to the pattern provided
|
||||
if (urls != null)
|
||||
fragScanner.scan(webFragPattern, urls.toArray(new URL[urls.size()]), true);
|
||||
else
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("No jars with web-fragments");
|
||||
for (Resource frag : frags)
|
||||
processor.parseFragment(frag.getURL());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class MetaInfConfiguration implements Configuration
|
||||
{
|
||||
public static final String JARS_WITH_TLDS = "org.eclipse.jetty.tlds";
|
||||
public static final String JARS_WITH_FRAGMENTS = "org.eclipse.jetty.webFragments";
|
||||
public static final String JARS_WITH_RESOURCES = WebInfConfiguration.RESOURCE_URLS;
|
||||
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 void preConfigure(final WebAppContext context) throws Exception
|
||||
{
|
||||
//Find all jars in WEB-INF
|
||||
|
@ -81,12 +79,12 @@ public class MetaInfConfiguration implements Configuration
|
|||
|
||||
}
|
||||
|
||||
public void addJar (WebAppContext context, String attribute, URL jar)
|
||||
public void addResource (WebAppContext context, String attribute, Resource jar)
|
||||
{
|
||||
List<URL> list = (List<URL>)context.getAttribute(attribute);
|
||||
List<Resource> list = (List<Resource>)context.getAttribute(attribute);
|
||||
if (list==null)
|
||||
{
|
||||
list=new ArrayList<URL>();
|
||||
list=new ArrayList<Resource>();
|
||||
context.setAttribute(attribute,list);
|
||||
}
|
||||
if (!list.contains(jar))
|
||||
|
@ -96,18 +94,32 @@ public class MetaInfConfiguration implements Configuration
|
|||
|
||||
protected void processEntry(WebAppContext context, URL jarUrl, JarEntry entry)
|
||||
{
|
||||
String name = entry.getName().toLowerCase();
|
||||
if (name.equals("meta-inf/web-fragment.xml") && context.isConfigurationDiscovered())
|
||||
String name = entry.getName();
|
||||
if (!name.startsWith("META-INF/"))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
addJar(context,JARS_WITH_FRAGMENTS,jarUrl);
|
||||
if (name.equals("META-INF/web-fragment.xml") && context.isConfigurationDiscovered())
|
||||
{
|
||||
addResource(context,METAINF_FRAGMENTS,Resource.newResource(jarUrl));
|
||||
}
|
||||
else if (name.equals("META-INF/resources/") && context.isConfigurationDiscovered())
|
||||
{
|
||||
addResource(context,METAINF_RESOURCES,Resource.newResource("jar:"+jarUrl+"!/META-INF/resources"));
|
||||
}
|
||||
else
|
||||
{
|
||||
String lcname = name.toLowerCase();
|
||||
if (lcname.endsWith(".tld"))
|
||||
{
|
||||
addResource(context,METAINF_TLDS,Resource.newResource("jar:"+jarUrl+"!/"+name));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (name.endsWith(".tld"))
|
||||
catch(Exception e)
|
||||
{
|
||||
addJar(context,JARS_WITH_TLDS,jarUrl);
|
||||
}
|
||||
else if (name.equals("meta-inf/resources") && context.isConfigurationDiscovered())
|
||||
{
|
||||
addJar(context,JARS_WITH_RESOURCES,jarUrl);
|
||||
context.getServletContext().log(jarUrl+"!/"+name,e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.webapp;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EventListener;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -50,56 +51,9 @@ import org.eclipse.jetty.xml.XmlParser;
|
|||
*/
|
||||
public class TagLibConfiguration implements Configuration
|
||||
{
|
||||
public static final String __web_inf_pattern = "org.eclipse.jetty.webapp.WebInfIncludeTLDJarPattern";
|
||||
public static final String __container_pattern = "org.eclipse.jetty.server.webapp.ContainerIncludeTLDJarPattern";
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* TagLibJarScanner
|
||||
*
|
||||
* Scan jars for META-INF/*.tlds
|
||||
*/
|
||||
public class TagLibJarScanner extends JarScanner
|
||||
{
|
||||
Set _tlds;
|
||||
WebAppContext _context;
|
||||
|
||||
public TagLibJarScanner (WebAppContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void setTldSet (Set tlds)
|
||||
{
|
||||
_tlds=tlds;
|
||||
}
|
||||
|
||||
public Set getTldSet ()
|
||||
{
|
||||
return _tlds;
|
||||
}
|
||||
|
||||
public void processEntry(URL jarUrl, JarEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.startsWith("META-INF/") && name.toLowerCase().endsWith(".tld"))
|
||||
{
|
||||
Resource tld=_context.newResource("jar:"+jarUrl+"!/"+name);
|
||||
_tlds.add(tld);
|
||||
Log.debug("TLD found {}",tld);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("Problem processing jar entry "+entry, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final String TLD_RESOURCES = "org.eclipse.jetty.tlds";
|
||||
private static final String __web_inf_pattern = "org.eclipse.jetty.webapp.WebInfIncludeTLDJarPattern";
|
||||
private static final String __container_pattern = "org.eclipse.jetty.server.webapp.ContainerIncludeTLDJarPattern";
|
||||
|
||||
public class TldProcessor
|
||||
{
|
||||
|
@ -283,7 +237,6 @@ public class TagLibConfiguration implements Configuration
|
|||
Resource l=context.getWebInf().addPath(contents[i]);
|
||||
tlds.add(l);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,24 +264,8 @@ public class TagLibConfiguration implements Configuration
|
|||
tmp = context.getInitParameter(__container_pattern);
|
||||
Pattern containerPattern = (tmp==null?null:Pattern.compile(tmp));
|
||||
|
||||
List<URL> tldJars = (List<URL>)context.getAttribute(MetaInfConfiguration.JARS_WITH_TLDS);
|
||||
tlds.addAll((Collection<Resource>)context.getAttribute(TLD_RESOURCES));
|
||||
|
||||
TagLibJarScanner tldScanner = new TagLibJarScanner(context);
|
||||
try
|
||||
{
|
||||
tldScanner.setTldSet(tlds);
|
||||
//scan the jars we know have META-INF/tld files
|
||||
if (tldJars != null)
|
||||
tldScanner.scan(webInfPattern, tldJars.toArray(new URL[tldJars.size()]), true);
|
||||
|
||||
//scan the parent loader for tld files
|
||||
tldScanner.scan(containerPattern, Thread.currentThread().getContextClassLoader().getParent(), false, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
|
||||
// Create a processor for the tlds and save it
|
||||
TldProcessor processor = new TldProcessor (context);
|
||||
context.setAttribute(TldProcessor.__taglib_processor, processor);
|
||||
|
|
Loading…
Reference in New Issue