public boolean accepts(DeploymentInfo di) {
boolean trace = log.isTraceEnabled();
try
{
// Reject extensions not configured in this subdeployer
// but do consider accepting non-dotted deployments,
// like deploy-hasingleton
if (di.shortName.indexOf('.") != -1 && super.accepts(di) == false)
{
return false;
}
// Reject deployments with a WEB-INF/ directory
URL wdDir = di.localCl.findResource("WEB-INF/");
if (wdDir != null)
{
return false;
}
// Since a META-INF directory exists within rt.jar, we can't just do a
// getResource (it will always return rt.jar's version).
// The method we want is findResource, but it is marked protected in
// ClassLoader. Fortunately, URLClassLoader exposes it which makes
// this hack possible. Anybody have a better way to check a URL
// for the existance of a META-INF??
URL ddDir;
try
{
ddDir = di.localCl.findResource("META-INF/");
if (ddDir == null)
{
log.debug("No META-INF or WEB-INF resource found, assuming it if for us");
return true;
}
}
catch (ClassCastException e)
{
// assume there is a META-INF...
ddDir = new URL(di.url, "META-INF/");
}
if (ddDir.getProtocol().equals("file"))
{
log.trace("File protocol: "+ddDir);
File file = new File(ddDir.getFile());
if (!file.exists())
{
log.warn("File not found: " + file);
return true;
}
// Scan for any xml files in the META-INF dir
File[] entries = file.listFiles(
new FileFilter()
{
public boolean accept(File pathname)
{
boolean accept = false;
String name = pathname.getName();
for(int n = 0; accept == false && n < descriptorNames.length; n ++)
{
String d = descriptorNames[n];
accept = name.endsWith(d);
}
return accept;
}
}
);
log.debug("XML entries found: " + entries.length);
return entries.length == 0;
} // end of if ()
else if (ddDir.getProtocol().equals("jar") == true)
{
log.trace("jar protocol: " + ddDir);
JarFile jarFile = null;
try
{
URLConnection con = ddDir.openConnection();
JarURLConnection jarConn = (JarURLConnection) con;
/* Need to set caching to false otherwise closing the jarfile
ends up conflicting with other users of the cached jar.
*/
jarConn.setUseCaches(false);
jarFile = jarConn.getJarFile();
// Scan for any xml files in the META-INF dir
if (trace)
log.trace("Descriptor names=" + Arrays.asList(descriptorNames));
for (Enumeration e = jarFile.entries(); e.hasMoreElements();)
{
JarEntry entry = (JarEntry)e.nextElement();
String name = entry.getName();
if (trace)
log.trace("Looking at entry: '" + name + "'");
// JBAS-2949 - Look for xml descriptors directly
// under META-INF/, not in META-INF/ subdirectories
if (name.startsWith("META-INF/") && Strings.count(name, "/") == 1)
{
for (int n = 0; n < descriptorNames.length; n ++)
{
if (name.endsWith(descriptorNames[n]))
{
log.debug("Found entry: '" + name + "', matching: '"
+ descriptorNames[n] + "', rejecting jar");
// Do not accept this as jar file
return false;
}
}
}
}
}
catch (Exception e)
{
log.warn("Looking inside jar failed; ignoring", e);
return false;
}
finally
{
if (jarFile != null)
jarFile.close();
jarFile = null;
}
log.debug("No xml files found");
return true;
}
else
{
log.debug("Unrecognized protocol: " + ddDir.getProtocol());
}
return false;
}
catch (Exception e)
{
log.trace("Ignored error", e);
return false;
}
}
The accepts method is called by MainDeployer to
determine which deployer is suitable for a DeploymentInfo. |