Search in sources :

Example 1 with JarScanner

use of org.eclipse.jetty.webapp.JarScanner in project jetty.project by eclipse.

the class AnnotationParser method parse.

/**
     * Parse classes in the supplied classloader. 
     * Only class files in jar files will be scanned.
     * 
     * @param handlers the handlers to look for classes in 
     * @param loader the classloader for the classes
     * @param visitParents if true, visit parent classloaders too
     * @param nullInclusive if true, an empty pattern means all names match, if false, none match
     * @throws Exception if unable to parse
     */
public void parse(final Set<? extends Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive) throws Exception {
    if (loader == null)
        return;
    if (!(loader instanceof URLClassLoader))
        //can't extract classes?
        return;
    final MultiException me = new MultiException();
    JarScanner scanner = new JarScanner() {

        @Override
        public void processEntry(URI jarUri, JarEntry entry) {
            try {
                parseJarEntry(handlers, Resource.newResource(jarUri), entry);
            } catch (Exception e) {
                me.add(new RuntimeException("Error parsing entry " + entry.getName() + " from jar " + jarUri, e));
            }
        }
    };
    scanner.scan(null, loader, nullInclusive, visitParents);
    me.ifExceptionThrow();
}
Also used : URLClassLoader(java.net.URLClassLoader) JarEntry(java.util.jar.JarEntry) MultiException(org.eclipse.jetty.util.MultiException) JarScanner(org.eclipse.jetty.webapp.JarScanner) URI(java.net.URI) MultiException(org.eclipse.jetty.util.MultiException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 URLClassLoader (java.net.URLClassLoader)1 JarEntry (java.util.jar.JarEntry)1 MultiException (org.eclipse.jetty.util.MultiException)1 JarScanner (org.eclipse.jetty.webapp.JarScanner)1