⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jspc.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void setWebxml(File webxml) {        this.webxml = webxml;    }    /**     * Filename for web.xml.     * @return The filename for web.xml.     */    public File getWebxml() {        return this.webxml;    }    /**     *  output filename for the fraction of web.xml that lists     *  servlets.     * @param  webinc  The new Webinc value     */    public void setWebinc(File webinc) {        this.webinc = webinc;    }    /**     * Get the webinc attribute.     * @return the webinc attribute.     */    public File getWebinc() {        return this.webinc;    }    /**     * Adds a single webapp.     *     * @param  webappParam  add a web app parameter     * @throws BuildException if more than one webapp is specified.     */    public void addWebApp(WebAppParameter webappParam)        throws BuildException {        //demand create vector of filesets        if (webApp == null) {            webApp = webappParam;        } else {            throw new BuildException("Only one webapp can be specified");        }    }    /**     * Get the web app.     * @return the web app attribute.     */    public WebAppParameter getWebApp() {        return webApp;    }    /**     * Class name of a JSP compiler adapter.     * @param compiler the compiler class name.     */    public void setCompiler(String compiler) {        this.compilerName = compiler;    }    /**    * get the list of files to compile    * @return the list of files.    */    public Vector getCompileList() {        return compileList;    }    /**     * execute by building up a list of files that     * have changed and hand them off to a jsp compiler     * @throws BuildException on error.     */    public void execute()        throws BuildException {        // make sure that we've got a destdir        if (destDir == null) {            throw new BuildException("destdir attribute must be set!",                                     getLocation());        }        if (!destDir.isDirectory()) {            throw new BuildException("destination directory \"" + destDir                    + "\" does not exist or is not a directory", getLocation());        }        File dest = getActualDestDir();        //bind to a compiler        JspCompilerAdapter compiler =            JspCompilerAdapterFactory.getCompiler(compilerName, this,                getProject().createClassLoader(compilerClasspath));        //if we are a webapp, hand off to the compiler, which had better handle it        if (webApp != null) {            doCompilation(compiler);            return;        }        // make sure that we've got a srcdir        if (src == null) {            throw new BuildException("srcdir attribute must be set!",                                     getLocation());        }        String [] list = src.list();        if (list.length == 0) {            throw new BuildException("srcdir attribute must be set!",                    getLocation());        }        // if the compiler does its own dependency stuff, we just call it right now        if (compiler.implementsOwnDependencyChecking()) {            doCompilation(compiler);            return;        }        //the remainder of this method is only for compilers that need their dependency work done        JspMangler mangler = compiler.createMangler();        // scan source directories and dest directory to build up both copy        // lists and compile lists        resetFileLists();        int filecount = 0;        for (int i = 0; i < list.length; i++) {            File srcDir = getProject().resolveFile(list[i]);            if (!srcDir.exists()) {                throw new BuildException("srcdir \"" + srcDir.getPath()                    + "\" does not exist!", getLocation());            }            DirectoryScanner ds = this.getDirectoryScanner(srcDir);            String[] files = ds.getIncludedFiles();            filecount = files.length;            scanDir(srcDir, dest, mangler, files);        }        // compile the source files        log("compiling " + compileList.size() + " files", Project.MSG_VERBOSE);        if (compileList.size() > 0) {            log("Compiling " + compileList.size() + " source file"                + (compileList.size() == 1 ? "" : "s")                + " to "                + dest);            doCompilation(compiler);        } else {            if (filecount == 0) {                log("there were no files to compile", Project.MSG_INFO);            } else {                log("all files are up to date", Project.MSG_VERBOSE);            }        }    }    /**     * calculate where the files will end up:     * this is destDir or it id destDir + the package name     */    private File getActualDestDir() {        File dest = null;        if (packageName == null) {            dest = destDir;        } else {            String path = destDir.getPath() + File.separatorChar                + packageName.replace('.', File.separatorChar);            dest = new File(path);        }        return dest;    }    /**     * do the compile     */    private void doCompilation(JspCompilerAdapter compiler)            throws BuildException {        // now we need to populate the compiler adapter        compiler.setJspc(this);        // finally, lets execute the compiler!!        if (!compiler.execute()) {            if (failOnError) {                throw new BuildException(FAIL_MSG, getLocation());            } else {                log(FAIL_MSG, Project.MSG_ERR);            }        }    }    /**     * Clear the list of files to be compiled and copied..     */    protected void resetFileLists() {        compileList.removeAllElements();    }    /**     * Scans the directory looking for source files to be compiled.     * The results are returned in the class variable compileList     * @param srcDir the source directory.     * @param dest   the destination directory.     * @param mangler the jsp filename mangler.     * @param files   the file names to mangle.     */    protected void scanDir(        File srcDir, File dest, JspMangler mangler, String[] files) {        long now = (new Date()).getTime();        for (int i = 0; i < files.length; i++) {            String filename = files[i];            File srcFile = new File(srcDir, filename);            File javaFile = mapToJavaFile(mangler, srcFile, srcDir, dest);            if (javaFile == null) {                continue;            }            if (srcFile.lastModified() > now) {                log("Warning: file modified in the future: " + filename,                        Project.MSG_WARN);            }            boolean shouldCompile = false;            shouldCompile = isCompileNeeded(srcFile, javaFile);            if (shouldCompile) {               compileList.addElement(srcFile.getAbsolutePath());               javaFiles.addElement(javaFile);            }        }    }    /**     * Test whether or not compilation is needed. A return value of     * <code>true<code> means yes, <code>false</code> means     * our tests do not indicate this, but as the TLDs are     * not used for dependency checking this is not guaranteed.     * The current tests are     * <ol>     * <li>no dest file     * <li>dest file out of date w.r.t source     * <li>dest file zero bytes long     * </ol>     * @param srcFile JSP source file     * @param javaFile JSP dest file     * @return true if a compile is definately needed.     *     */    private boolean isCompileNeeded(File srcFile, File javaFile) {        boolean shouldCompile = false;        if (!javaFile.exists()) {            shouldCompile = true;            log("Compiling " + srcFile.getPath()                + " because java file " + javaFile.getPath()                + " does not exist", Project.MSG_VERBOSE);            } else {                if (srcFile.lastModified() > javaFile.lastModified()) {                    shouldCompile = true;                    log("Compiling " + srcFile.getPath()                        + " because it is out of date with respect to "                        + javaFile.getPath(),                        Project.MSG_VERBOSE);                } else {                    if (javaFile.length() == 0) {                        shouldCompile = true;                        log("Compiling " + srcFile.getPath()                            + " because java file " + javaFile.getPath()                            + " is empty", Project.MSG_VERBOSE);                    }                }        }        return shouldCompile;    }    /**     * get a filename from our jsp file.     * @param mangler the jsp filename managler.     * @param srcFile the source file.     * @param srcDir  the source directory.     * @param dest    the destination directory.     * @return the filename.     * @todo support packages and subdirs     */    protected File mapToJavaFile(JspMangler mangler, File srcFile, File srcDir, File dest) {        if (!srcFile.getName().endsWith(".jsp")) {            return null;        }        String javaFileName = mangler.mapJspToJavaName(srcFile);//        String srcFileDir=srcFile.getParent();        return new File(dest, javaFileName);    }    /**     * delete any java output files that are empty     * this is to get around a little defect in jasper: when it     * fails, it leaves incomplete files around.     */    public void deleteEmptyJavaFiles() {        if (javaFiles != null) {            Enumeration e = javaFiles.elements();            while (e.hasMoreElements()) {                File file = (File) e.nextElement();                if (file.exists() && file.length() == 0) {                    log("deleting empty output file " + file);                    file.delete();                }            }        }    }    /**     * static inner class used as a parameter element     */    public static class WebAppParameter {        /**         * the sole option         */        private File directory;        /**         * query current directory         * @return the directory.         */        public File getDirectory() {            return directory;        }        /**         * set directory; alternate syntax         * @param directory the base dir.         */        public void setBaseDir(File directory) {            this.directory = directory;        }    //end inner class    }//end class}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -