use of org.apache.tomcat.util.scan.Jar in project tomcat70 by apache.
the class TesterPerformance method testClassParserPerformance.
@Test
public void testClassParserPerformance() throws IOException {
File libDir = new File(JAR_LOCATION);
String[] libs = libDir.list();
Assert.assertNotNull(libs);
Set<URL> jarURLs = new HashSet<URL>();
for (String lib : libs) {
if (!lib.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
continue;
}
jarURLs.add(new URL("jar:" + new File(libDir, lib).toURI().toURL().toExternalForm() + "!/"));
}
long duration = 0;
for (URL jarURL : jarURLs) {
Jar jar = JarFactory.newInstance(jarURL);
try {
jar.nextEntry();
String jarEntryName = jar.getEntryName();
while (jarEntryName != null) {
if (jarEntryName.endsWith(".class")) {
InputStream is = jar.getEntryInputStream();
long start = System.nanoTime();
ClassParser cp = new ClassParser(is);
cp.parse();
duration += System.nanoTime() - start;
}
jar.nextEntry();
jarEntryName = jar.getEntryName();
}
} finally {
jar.close();
}
}
System.out.println("ClassParser performance test took: " + duration + " ns");
}
use of org.apache.tomcat.util.scan.Jar in project tomcat70 by apache.
the class TldLocationsCache method tldScanJar.
/*
* Scans the given JarURLConnection for TLD files located in META-INF
* (or a subdirectory of it), adding an implicit map entry to the taglib
* map for any TLD that has a <uri> element.
*
* @param jarConn The JarURLConnection to the JAR file to scan
*
* Keep in sync with o.a.c.startup.TldConfig
*/
private void tldScanJar(JarURLConnection jarConn) throws IOException {
Jar jar = null;
InputStream is;
boolean foundTld = false;
URL resourceURL = jarConn.getJarFileURL();
String resourcePath = resourceURL.toString();
try {
jar = JarFactory.newInstance(jarConn.getURL());
jar.nextEntry();
String entryName = jar.getEntryName();
while (entryName != null) {
if (entryName.startsWith("META-INF/") && entryName.endsWith(".tld")) {
is = null;
try {
is = jar.getEntryInputStream();
foundTld = true;
tldScanStream(resourcePath, entryName, is);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
// Ignore
}
}
}
}
jar.nextEntry();
entryName = jar.getEntryName();
}
} finally {
if (jar != null) {
jar.close();
}
}
if (!foundTld) {
if (log.isDebugEnabled()) {
log.debug(Localizer.getMessage("jsp.tldCache.noTldInJar", resourcePath));
} else if (showTldScanWarning) {
// Not entirely thread-safe but a few duplicate log messages are
// not a huge issue
showTldScanWarning = false;
log.info(Localizer.getMessage("jsp.tldCache.noTldSummary"));
}
}
}
use of org.apache.tomcat.util.scan.Jar in project tomcat70 by apache.
the class ContextConfig method processAnnotationsJar.
protected void processAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly) {
Jar jar = null;
InputStream is;
try {
jar = JarFactory.newInstance(url);
if (log.isDebugEnabled()) {
log.debug(sm.getString("contextConfig.processAnnotationsJar.debug", url));
}
jar.nextEntry();
String entryName = jar.getEntryName();
while (entryName != null) {
if (entryName.endsWith(".class")) {
is = null;
try {
is = jar.getEntryInputStream();
processAnnotationsStream(is, fragment, handlesTypesOnly);
} catch (IOException e) {
log.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
} catch (ClassFormatException e) {
log.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
// Ignore
}
}
}
}
jar.nextEntry();
entryName = jar.getEntryName();
}
} catch (IOException e) {
log.error(sm.getString("contextConfig.jarFile", url), e);
} finally {
if (jar != null) {
jar.close();
}
}
}
use of org.apache.tomcat.util.scan.Jar in project tomcat70 by apache.
the class ContextConfig method processResourceJARs.
/**
* Scan JARs that contain web-fragment.xml files that will be used to
* configure this application to see if they also contain static resources.
* If static resources are found, add them to the context. Resources are
* added in web-fragment.xml priority order.
*/
protected void processResourceJARs(Set<WebXml> fragments) {
for (WebXml fragment : fragments) {
URL url = fragment.getURL();
Jar jar = null;
try {
// Note: Ignore file URLs for now since only jar URLs will be accepted
if ("jar".equals(url.getProtocol())) {
jar = JarFactory.newInstance(url);
jar.nextEntry();
String entryName = jar.getEntryName();
while (entryName != null) {
if (entryName.startsWith("META-INF/resources/")) {
context.addResourceJarUrl(url);
break;
}
jar.nextEntry();
entryName = jar.getEntryName();
}
} else if ("file".equals(url.getProtocol())) {
FileDirContext fileDirContext = new FileDirContext();
fileDirContext.setDocBase(new File(url.toURI()).getAbsolutePath());
try {
fileDirContext.lookup("META-INF/resources/");
// lookup succeeded
if (context instanceof StandardContext) {
((StandardContext) context).addResourcesDirContext(fileDirContext);
}
} catch (NamingException e) {
// not found, ignore
}
}
} catch (IOException ioe) {
log.error(sm.getString("contextConfig.resourceJarFail", url, context.getName()));
} catch (URISyntaxException e) {
log.error(sm.getString("contextConfig.resourceJarFail", url, context.getName()));
} finally {
if (jar != null) {
jar.close();
}
}
}
}
use of org.apache.tomcat.util.scan.Jar in project tomcat70 by apache.
the class TldConfig method tldScanJar.
/*
* Scans the given JarURLConnection for TLD files located in META-INF
* (or a sub-directory of it).
*
* @param jarConn The JarURLConnection to the JAR file to scan
*
* Keep in sync with o.a.j.comiler.TldLocationsCache
*/
private boolean tldScanJar(JarURLConnection jarConn) {
Jar jar = null;
InputStream is;
boolean isFound = false;
try {
jar = JarFactory.newInstance(jarConn.getURL());
jar.nextEntry();
String entryName = jar.getEntryName();
while (entryName != null) {
if (entryName.startsWith("META-INF/") && entryName.endsWith(".tld")) {
isFound = true;
is = null;
try {
is = jar.getEntryInputStream();
XmlErrorHandler handler = tldScanStream(is);
handler.logFindings(log, jarConn.getURL() + entryName);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
// Ignore
}
}
}
}
jar.nextEntry();
entryName = jar.getEntryName();
}
if (!isFound) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("tldConfig.noTldInJar", jarConn.getURL().getFile()));
}
}
} catch (IOException ioe) {
log.warn(sm.getString("tldConfig.jarFail", jarConn.getURL()), ioe);
} finally {
if (jar != null) {
jar.close();
}
}
return isFound;
}
Aggregations