Java源码示例:org.apache.tomcat.JarScanner

示例1
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
 
示例2
private synchronized void init() throws JasperException {
    if (initialized) return;
    try {
        tldScanWebXml();
        tldScanResourcePaths(WEB_INF);
        
        JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
        if (jarScanner != null) {
            jarScanner.scan(ctxt,
                    Thread.currentThread().getContextClassLoader(),
                    new TldJarScannerCallback(), noTldJars);
        }

        initialized = true;
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage(
                "jsp.error.internal.tldinit", ex.getMessage()), ex);
    }
}
 
示例3
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
 
示例4
private synchronized void init() throws JasperException {
    if (initialized) return;
    try {
        tldScanWebXml();
        tldScanResourcePaths(WEB_INF);
        
        JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
        jarScanner.scan(ctxt,
                Thread.currentThread().getContextClassLoader(),
                new TldJarScannerCallback(), noTldJars);

        initialized = true;
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage(
                "jsp.error.internal.tldinit", ex.getMessage()), ex);
    }
}
 
示例5
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @param application The main web.xml metadata
 * @param webXmlParser The parser to use to process the web.xml file
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application,
        WebXmlParser webXmlParser) {

    JarScanner jarScanner = context.getJarScanner();
    boolean delegate = false;
    if (context instanceof StandardContext) {
        delegate = ((StandardContext) context).getDelegate();
    }
    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(webXmlParser, delegate, parseRequired);

    jarScanner.scan(JarScanType.PLUGGABILITY,
            context.getServletContext(), callback);

    if (!callback.isOk()) {
        ok = false;
    }
    return callback.getFragments();
}
 
示例6
/**
 * Scan for TLDs in JARs in /WEB-INF/lib.
 */
public void scanJars() {
    JarScanner scanner = JarScannerFactory.getJarScanner(context);
    TldScannerCallback callback = new TldScannerCallback();
    scanner.scan(JarScanType.TLD, context, callback);
    if (callback.scanFoundNoTLDs()) {
        log.info(Localizer.getMessage("jsp.tldCache.noTldSummary"));
    }
}
 
示例7
public void onDeployUAVApp(Object... args) {
    
    if(UAVServer.ServerVendor.SPRINGBOOT!=UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR)) {
        return;
    }
    
    Tomcat tomcat=(Tomcat) args[0];
    String mofRoot=(String) args[1];
    
    //add uavApp
    StandardContext context=new StandardContext();
    context.setName("com.creditease.uav");
    context.setPath("/com.creditease.uav");
    context.setDocBase(mofRoot + "/com.creditease.uav");
    context.addLifecycleListener(new Tomcat.FixContextListener());
    tomcat.getHost().addChild(context);
    
    //add default servlet
    Wrapper servlet = context.createWrapper();
    servlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
    servlet.setName("default");
    context.addChild(servlet);    
    servlet.setOverridable(true);
    context.addServletMapping("/", "default");
    
    //init webapp classloader
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
    context.setDelegate(true);
    
    //after tomcat8, skip jarscan
    Object obj=ReflectionHelper.newInstance("org.apache.tomcat.util.scan.StandardJarScanner", Thread.currentThread().getContextClassLoader());
    if(obj!=null) {
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllFiles", new Class<?>[]{Boolean.class}, new Object[] { false}, Thread.currentThread().getContextClassLoader());
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanClassPath", new Class<?>[]{Boolean.class}, new Object[] { false}, Thread.currentThread().getContextClassLoader());
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllDirectories", new Class<?>[]{Boolean.class}, new Object[] { false}, Thread.currentThread().getContextClassLoader());            
        
        context.setJarScanner((JarScanner) obj);      
    }        
}
 
示例8
@Bean
public ServletContextInitializer servletContextInitializer() {
    return context -> context.setAttribute(
            JarScanner.class.getName(),
            new StandardJarScanner() {{
                setScanManifest(false);
            }}
    );
}
 
示例9
public static void configureJarScanner(final Context standardContext) {
    try { // override only if default
        final JarScanner originalJarScanner = standardContext.getJarScanner();
        if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.tomcat.override.jar-scanner", "true"))
                && !TomEEJarScanner.class.isInstance(originalJarScanner)
                && StandardJarScanner.class.isInstance(originalJarScanner)) {
            final TomEEJarScanner jarScanner = new TomEEJarScanner();

            final Properties properties = SystemInstance.get().getProperties();
            final String scanClasspath = properties.getProperty(TomEEJarScanner.class.getName() + ".scanClassPath");
            if (scanClasspath != null) {
                jarScanner.setScanClassPath(Boolean.parseBoolean(scanClasspath));
            }
            final String scanBootstrap = properties.getProperty(TomEEJarScanner.class.getName() + ".scanBootstrapClassPath");
            if (scanBootstrap != null) {
                jarScanner.setScanBootstrapClassPath(Boolean.parseBoolean(scanBootstrap));
            }
            final JarScanFilter jarScanFilter = originalJarScanner.getJarScanFilter();
            if (jarScanFilter != null && Boolean.parseBoolean(properties.getProperty(TomEEJarScanner.class.getName() + ".useOriginalJarScannerFilter", "true"))) {
                jarScanner.setJarScanFilter(jarScanFilter);
            }
            standardContext.setJarScanner(jarScanner);
        }
    } catch (final Exception e) {
        // ignore
    }
}
 
示例10
@Override
public JarScanner getJarScanner() { return null; }
 
示例11
@Override
public void setJarScanner(JarScanner jarScanner) { /* NO-OP */ }
 
示例12
/**
 * Store the specified context element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aContext Context to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext,
        StoreDescription parentDesc) throws Exception {
    if (aContext instanceof StandardContext) {
        StandardContext context = (StandardContext) aContext;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = context.findLifecycleListeners();
        ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
        for (LifecycleListener listener : listeners) {
            if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
                listenersArray.add(listener);
            }
        }
        storeElementArray(aWriter, indent, listenersArray.toArray());

        // Store nested <Valve> elements
        Valve valves[] = context.getPipeline().getValves();
        storeElementArray(aWriter, indent, valves);

        // Store nested <Loader> elements
        Loader loader = context.getLoader();
        storeElement(aWriter, indent, loader);

        // Store nested <Manager> elements
        if (context.getCluster() == null || !context.getDistributable()) {
            Manager manager = context.getManager();
            storeElement(aWriter, indent, manager);
        }

        // Store nested <Realm> element
        Realm realm = context.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            // @TODO is this case possible?
            if (context.getParent() != null) {
                parentRealm = context.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested resources
        WebResourceRoot resources = context.getResources();
        storeElement(aWriter, indent, resources);

        // Store nested <WrapperListener> elements
        String wLifecycles[] = context.findWrapperLifecycles();
        getStoreAppender().printTagArray(aWriter, "WrapperListener",
                indent + 2, wLifecycles);
        // Store nested <WrapperLifecycle> elements
        String wListeners[] = context.findWrapperListeners();
        getStoreAppender().printTagArray(aWriter, "WrapperLifecycle",
                indent + 2, wListeners);

        // Store nested <Parameter> elements
        ApplicationParameter[] appParams = context
                .findApplicationParameters();
        storeElementArray(aWriter, indent, appParams);

        // Store nested naming resources elements (EJB,Resource,...)
        NamingResourcesImpl nresources = context.getNamingResources();
        storeElement(aWriter, indent, nresources);

        // Store nested watched resources <WatchedResource>
        String[] wresources = context.findWatchedResources();
        wresources = filterWatchedResources(context, wresources);
        getStoreAppender().printTagArray(aWriter, "WatchedResource",
                indent + 2, wresources);

        // Store nested <JarScanner> elements
        JarScanner jarScanner = context.getJarScanner();
        storeElement(aWriter, indent, jarScanner);

        // Store nested <CookieProcessor> elements
        CookieProcessor cookieProcessor = context.getCookieProcessor();
        storeElement(aWriter, indent, cookieProcessor);
    }
}
 
示例13
@Override
public JarScanner getJarScanner() {
    return null;
}
 
示例14
@Override
public void setJarScanner(JarScanner jarScanner) {
    // NO-OP
}
 
示例15
@Override
public JarScanner getJarScanner() { return null; }
 
示例16
@Override
public void setJarScanner(JarScanner jarScanner) { /* NO-OP */ }
 
示例17
/**
 * Scan for and configure all tag library descriptors found in this
 * web application.
 * 
 * This supports a Tomcat-specific extension to the TLD search
 * order defined in the JSP spec. It allows tag libraries packaged as JAR
 * files to be shared by web applications by simply dropping them in a 
 * location that all web applications have access to (e.g.,
 * <CATALINA_HOME>/lib). It also supports some of the weird and
 * wonderful arrangements present when Tomcat gets embedded.
 *
 * The set of shared JARs to be scanned for TLDs is narrowed down by
 * the <tt>noTldJars</tt> class variable, which contains the names of JARs
 * that are known not to contain any TLDs.
 */
@SuppressWarnings("deprecation") // Context.addApplicationListener(ApplicationListener) is deprecated.
public void execute() {
    long t1=System.currentTimeMillis();

    /*
     * Priority order of URIs required by spec is:
     * 1. J2EE platform taglibs - Tomcat doesn't provide these
     * 2. web.xml entries
     * 3. JARS in WEB-INF/lib & TLDs under WEB-INF (equal priority)
     * 4. Additional entries from the container
     * 
     * Keep processing order in sync with o.a.j.compiler.TldLocationsCache
     */
    
    // Stage 2 - web.xml entries
    tldScanWebXml();
    
    // Stage 3a - TLDs under WEB-INF (not lib or classes)
    tldScanResourcePaths(WEB_INF);

    // Stages 3b & 4
    JarScanner jarScanner = context.getJarScanner();
    
    TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
    jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(),
            tldCallBack, noTldJars);
    if(tldCallBack.scanFoundNoTLDs()){
        log.info(sm.getString("tldConfig.noTldSummary"));
    }
    // Now add all the listeners we found to the listeners for this context
    String list[] = getTldListeners();

    if( log.isDebugEnabled() )
        log.debug(sm.getString("tldConfig.addListeners",
                Integer.valueOf(list.length)));

    for( int i=0; list!=null && i<list.length; i++ ) {
        context.addApplicationListener(
                new ApplicationListener(list[i], true));
    }

    long t2=System.currentTimeMillis();
    if( context instanceof StandardContext ) {
        ((StandardContext)context).setTldScanTime(t2-t1);
    }

}
 
示例18
@Override
public JarScanner getJarScanner() {
    return null;
}
 
示例19
@Override
public void setJarScanner(JarScanner jarScanner) {
    // NO-OP
}
 
示例20
@Override
public JarScanner getJarScanner() { return null; }
 
示例21
@Override
public void setJarScanner(JarScanner jarScanner) { /* NO-OP */ }
 
示例22
/**
 * Scan for and configure all tag library descriptors found in this
 * web application.
 * 
 * This supports a Tomcat-specific extension to the TLD search
 * order defined in the JSP spec. It allows tag libraries packaged as JAR
 * files to be shared by web applications by simply dropping them in a 
 * location that all web applications have access to (e.g.,
 * <CATALINA_HOME>/lib). It also supports some of the weird and
 * wonderful arrangements present when Tomcat gets embedded.
 *
 * The set of shared JARs to be scanned for TLDs is narrowed down by
 * the <tt>noTldJars</tt> class variable, which contains the names of JARs
 * that are known not to contain any TLDs.
 */
@SuppressWarnings("deprecation") // Context.addApplicationListener(ApplicationListener) is deprecated.
public void execute() {
    long t1=System.currentTimeMillis();

    /*
     * Priority order of URIs required by spec is:
     * 1. J2EE platform taglibs - Tomcat doesn't provide these
     * 2. web.xml entries
     * 3. JARS in WEB-INF/lib & TLDs under WEB-INF (equal priority)
     * 4. Additional entries from the container
     * 
     * Keep processing order in sync with o.a.j.compiler.TldLocationsCache
     */
    
    // Stage 2 - web.xml entries
    tldScanWebXml();
    
    // Stage 3a - TLDs under WEB-INF (not lib or classes)
    tldScanResourcePaths(WEB_INF);

    // Stages 3b & 4
    JarScanner jarScanner = context.getJarScanner();
    
    TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
    jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(),
            tldCallBack, noTldJars);
    if(tldCallBack.scanFoundNoTLDs()){
        log.info(sm.getString("tldConfig.noTldSummary"));
    }
    // Now add all the listeners we found to the listeners for this context
    String list[] = getTldListeners();

    if( log.isDebugEnabled() )
        log.debug(sm.getString("tldConfig.addListeners",
                Integer.valueOf(list.length)));

    for( int i=0; i<list.length; i++ ) {
        context.addApplicationListener(
                new ApplicationListener(list[i], true));
    }

    long t2=System.currentTimeMillis();
    if( context instanceof StandardContext ) {
        ((StandardContext)context).setTldScanTime(t2-t1);
    }

}
 
示例23
@Override
public JarScanner getJarScanner() {
    return null;
}
 
示例24
@Override
public void setJarScanner(JarScanner jarScanner) {
    // NO-OP
}
 
示例25
@Override
protected void webConfig() {
    if (context.getServletContext().getAttribute("meecrowave.configuration") == null) { // redeploy
        context.getServletContext().setAttribute("meecrowave.configuration",
                Meecrowave.Builder.class.isInstance(configuration) ? configuration : new Meecrowave.Builder(configuration));
        context.addServletContainerInitializer(intializer, emptySet());
    }

    if (!configuration.isTomcatScanning()) {
        super.webConfig();
        return;
    }

    // eagerly start CDI to scan only once and not twice (tomcat+CDI)
    final ClassLoader loader = context.getLoader().getClassLoader(); // should already be started at that point
    final Thread thread = Thread.currentThread();
    final ClassLoader old = thread.getContextClassLoader();
    thread.setContextClassLoader(loader);
    try {
        final OWBTomcatWebScannerService scannerService = OWBTomcatWebScannerService.class.cast(WebBeansContext.getInstance().getScannerService());
        scannerService.setFilter(ofNullable(context.getJarScanner()).map(JarScanner::getJarScanFilter).orElse(null), context.getServletContext());
        scannerService.setDocBase(context.getDocBase());
        scannerService.setShared(configuration.getSharedLibraries());
        if (configuration.getWatcherBouncing() > 0) { // note that caching should be disabled with this config in most of the times
            watcher = new ReloadOnChangeController(context, configuration.getWatcherBouncing());
            scannerService.setFileVisitor(f -> watcher.register(f));
        }
        scannerService.scan();
        finder = scannerService.getFinder();
        finder.link();
        final CdiArchive archive = CdiArchive.class.cast(finder.getArchive());
        Stream.of(WebServlet.class, WebFilter.class, WebListener.class)
                .forEach(marker -> finder.findAnnotatedClasses(marker).stream()
                        .filter(c -> !Modifier.isAbstract(c.getModifiers()) && Modifier.isPublic(c.getModifiers()))
                        .forEach(webComponent -> webClasses.computeIfAbsent(
                                archive.classesByUrl().entrySet().stream()
                                        .filter(e -> e.getValue().getClassNames().contains(webComponent.getName()))
                                        .findFirst().get().getKey(), k -> new HashSet<>())
                                .add(webComponent)));
    } finally {
        thread.setContextClassLoader(old);
    }
    try {
        super.webConfig();
    } finally {
        webClasses.clear();
        finder = null;
    }
}
 
示例26
/**
 * Store the specified JarScanner properties and children
 * (JarScannerFilter)
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aJarScanner
 *            JarScanner whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aJarScanner,
        StoreDescription parentDesc) throws Exception {
    if (aJarScanner instanceof JarScanner) {
        JarScanner jarScanner = (JarScanner) aJarScanner;
        // Store nested <JarScanFilter> element
        JarScanFilter jarScanFilter = jarScanner.getJarScanFilter();
        if (jarScanFilter != null) {
            storeElement(aWriter, indent, jarScanFilter);
        }
    }
}
 
示例27
/**
 * Get the Jar Scanner to be used to scan for JAR resources for this
 * context.
 * @return  The Jar Scanner configured for this context.
 */
public JarScanner getJarScanner();
 
示例28
/**
 * Set the Jar Scanner to be used to scan for JAR resources for this
 * context.
 * @param jarScanner    The Jar Scanner to be used for this context.
 */
public void setJarScanner(JarScanner jarScanner);
 
示例29
/**
 * Get the Jar Scanner to be used to scan for JAR resources for this
 * context.
 * @return  The Jar Scanner configured for this context.
 */
public JarScanner getJarScanner();
 
示例30
/**
 * Set the Jar Scanner to be used to scan for JAR resources for this
 * context.
 * @param jarScanner    The Jar Scanner to be used for this context.
 */
public void setJarScanner(JarScanner jarScanner);