Package org.apache.tomcat.util.scan

Examples of org.apache.tomcat.util.scan.Jar


        if (tldResourcePath == null) {
            // The URI points to the TLD itself or to a JAR file in which the TLD is stored
            tldResourcePath = generateTldResourcePath(uri, ctxt);
        }

        Jar jar;
        try {
            jar = tldResourcePath.getJar();
        } catch (IOException ioe) {
            throw new JasperException(ioe);
        }

        // Add the dependencies on the TLD to the referencing page
        PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
        if (pageInfo != null) {
            // If the TLD is in a JAR, that JAR may not be part of the web
            // application
            String path = tldResourcePath.getWebappPath();
            if (path != null) {
                // Add TLD (jar==null) / JAR (jar!=null) file to dependency list
                pageInfo.addDependant(path, ctxt.getLastModified(path));
            }
            if (jar != null) {
                if (path == null) {
                    // JAR not in the web application so add it directly
                    URL jarUrl = jar.getJarFileURL();
                    long lastMod = -1;
                    URLConnection urlConn = null;
                    try {
                        urlConn = jarUrl.openConnection();
                        lastMod = urlConn.getLastModified();
                    } catch (IOException ioe) {
                        throw new JasperException(ioe);
                    } finally {
                        if (urlConn != null) {
                            try {
                                urlConn.getInputStream().close();
                            } catch (IOException e) {
                                // Ignore
                            }
                        }
                    }
                    pageInfo.addDependant(jarUrl.toExternalForm(),
                            Long.valueOf(lastMod));
                }
                // Add TLD within the JAR to the dependency list
                String entryName = tldResourcePath.getEntryName();
                try {
                    pageInfo.addDependant(jar.getURL(entryName),
                            Long.valueOf(jar.getLastModified(entryName)));
                } catch (IOException ioe) {
                    throw new JasperException(ioe);
                }
            }
        }
View Full Code Here


                long includeLastModified = 0;
                if (key.startsWith("jar:jar:")) {
                    // Assume we constructed this correctly
                    int entryStart = key.lastIndexOf("!/");
                    String entry = key.substring(entryStart + 2);
                    Jar jar = JarFactory.newInstance(new URL(key.substring(4, entryStart)));
                    includeLastModified = jar.getLastModified(entry);
                } else {
                    if (key.startsWith("jar:") || key.startsWith("file:")) {
                        includeUrl = new URL(key);
                    } else {
                        includeUrl = ctxt.getResource(include.getKey());
View Full Code Here

     * Compiles and loads a tagfile.
     */
    private Class<?> loadTagFile(Compiler compiler, String tagFilePath,
            TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {

        Jar tagJar = null;
        if (tagFilePath.startsWith("/META-INF/")) {
            try {
                tagJar = compiler.getCompilationContext().getTldResourcePath(
                            tagInfo.getTagLibrary().getURI()).getJar();
            } catch (IOException ioe) {
                throw new JasperException(ioe);
            }
        }
        String wrapperUri;
        if (tagJar == null) {
            wrapperUri = tagFilePath;
        } else {
            wrapperUri = tagJar.getURL(tagFilePath);
        }

        JspCompilationContext ctxt = compiler.getCompilationContext();
        JspRuntimeContext rctxt = ctxt.getRuntimeContext();

View Full Code Here

                if (tagFilePath.startsWith("/META-INF/")) {
                    // For tags in JARs, add the TLD and the tag as a dependency
                    TldResourcePath tldResourcePath =
                        compiler.getCompilationContext().getTldResourcePath(
                            tagFileInfo.getTagInfo().getTagLibrary().getURI());
                    Jar jar;
                    try {
                        jar = tldResourcePath.getJar();
                    } catch (IOException ioe) {
                        throw new JasperException(ioe);
                    }
                    if (jar != null) {
                        try {
                            // Add TLD
                            pageInfo.addDependant(jar.getURL(tldResourcePath.getEntryName()),
                                    Long.valueOf(jar.getLastModified(tldResourcePath.getEntryName())));
                            // Add Tag
                            pageInfo.addDependant(jar.getURL(tagFilePath.substring(1)),
                                    Long.valueOf(jar.getLastModified(tagFilePath.substring(1))));
                        } catch (IOException ioe) {
                            throw new JasperException(ioe);
                        }
                    }
                    else {
View Full Code Here

    public void scan(JarURLConnection jarConn, String webappPath, boolean isWebapp)
            throws IOException {

        URL url = jarConn.getURL();
        URL resourceURL = jarConn.getJarFileURL();
        Jar jar = null;
        InputStream is = null;
        WebXml fragment = new WebXml();
        fragment.setWebappJar(isWebapp);
        fragment.setDelegate(delegate);

        try {
            // Only web application JARs are checked for web-fragment.xml
            // files.
            // web-fragment.xml files don't need to be parsed if they are never
            // going to be used.
            if (isWebapp && parseRequired) {
                jar = JarFactory.newInstance(url);
                is = jar.getInputStream(FRAGMENT_LOCATION);
            }

            if (is == null) {
                // If there is no web.xml, normal JAR no impact on
                // distributable
                fragment.setDistributable(true);
            } else {
                InputSource source = new InputSource(
                        "jar:" + resourceURL.toString() + "!/" + FRAGMENT_LOCATION);
                source.setByteStream(is);
                if (!webXmlParser.parseWebXml(source, fragment, true)) {
                    ok = false;
                }
            }
        } finally {
            if (jar != null) {
                jar.close();
            }
            fragment.setURL(url);
            if (fragment.getName() == null) {
                fragment.setName(fragment.getURL().toString());
            }
View Full Code Here

        }

        long duration = 0;

        for (URL jarURL : jarURLs) {
            Jar jar = JarFactory.newInstance(jarURL);
            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();
            }
        }

        System.out.println("ClassParser performance test took: " + duration + "ns");
    }
View Full Code Here

    protected void processServletContainerInitializers(
            Set<WebXml> fragments) {
       
        for (WebXml fragment : fragments) {
            URL url = fragment.getURL();
            Jar jar = null;
            InputStream is = null;
            ServletContainerInitializer sci = null;
            try {
                if ("jar".equals(url.getProtocol())) {
                    jar = JarFactory.newInstance(url);
                    is = jar.getInputStream(SCI_LOCATION);
                } else if ("file".equals(url.getProtocol())) {
                    String path = url.getPath();
                    File file = new File(path, SCI_LOCATION);
                    if (file.exists()) {
                        is = new FileInputStream(file);
                    }
                }
                if (is != null) {
                    sci = getServletContainerInitializer(is);
                }
            } catch (IOException ioe) {
                log.error(sm.getString(
                        "contextConfig.servletContainerInitializerFail", url,
                        context.getName()));
                ok = false;
                return;
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        // Ignore
                    }
                }
                if (jar != null) {
                    jar.close();
                }
            }
           
            if (sci == null) {
                continue;
View Full Code Here

     * 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);
                    if (jar.entryExists("META-INF/resources/")) {
                        context.addResourceJarUrl(url);
                    }
                } 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();
                }
            }
        }
    }
View Full Code Here

    }


    protected void processAnnotationsJar(URL url, WebXml fragment) {

        Jar jar = null;
        InputStream is;
       
        try {
            jar = JarFactory.newInstance(url);
           
            jar.nextEntry();
            String entryName = jar.getEntryName();
            while (entryName != null) {
                if (entryName.endsWith(".class")) {
                    is = null;
                    try {
                        is = jar.getEntryInputStream();
                        processAnnotationsStream(is, fragment);
                    } catch (IOException 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();
            }
        }
    }
View Full Code Here

        @Override
        public void scan(JarURLConnection jarConn) throws IOException {
           
            URL url = jarConn.getURL();
            URL resourceURL = jarConn.getJarFileURL();
            Jar jar = null;
            InputStream is = null;
            WebXml fragment = new WebXml();

            try {
                jar = JarFactory.newInstance(url);
                is = jar.getInputStream(FRAGMENT_LOCATION);

                if (is == null) {
                    // If there is no web.xml, normal JAR no impact on
                    // distributable
                    fragment.setDistributable(true);
                } else {
                    InputSource source = new InputSource(
                            resourceURL.toString() + "!/" + FRAGMENT_LOCATION);
                    source.setByteStream(is);
                    parseWebXml(source, fragment, true);
                }
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException ioe) {
                        // Ignore
                    }
                }
                if (jar != null) {
                    jar.close();
                }
                fragment.setURL(url);
                if (fragment.getName() == null) {
                    fragment.setName(fragment.getURL().toString());
                }
View Full Code Here

TOP

Related Classes of org.apache.tomcat.util.scan.Jar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.