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

📄 depend.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (classpathDependencies != null) {            log("Classpath file dependencies (Forward):", Project.MSG_DEBUG);            Enumeration classpathEnum = classpathDependencies.keys();            while (classpathEnum.hasMoreElements()) {                String className = (String) classpathEnum.nextElement();                log(" Class " + className + " depends on:", Project.MSG_DEBUG);                Hashtable dependencies                    = (Hashtable) classpathDependencies.get(className);                Enumeration classpathFileEnum = dependencies.elements();                while (classpathFileEnum.hasMoreElements()) {                    File classpathFile = (File) classpathFileEnum.nextElement();                    log("    " + classpathFile.getPath(), Project.MSG_DEBUG);                }            }        }    }    private void determineOutOfDateClasses() {        outOfDateClasses = new Hashtable();        for (int i = 0; i < srcPathList.length; i++) {            File srcDir = getProject().resolveFile(srcPathList[i]);            if (srcDir.exists()) {                DirectoryScanner ds = this.getDirectoryScanner(srcDir);                String[] files = ds.getIncludedFiles();                scanDir(srcDir, files);            }        }        // now check classpath file dependencies        if (classpathDependencies == null) {            return;        }        Enumeration classpathDepsEnum = classpathDependencies.keys();        while (classpathDepsEnum.hasMoreElements()) {            String className = (String) classpathDepsEnum.nextElement();            if (outOfDateClasses.containsKey(className)) {                continue;            }            ClassFileInfo info                = (ClassFileInfo) classFileInfoMap.get(className);            // if we have no info about the class - it may have been deleted already and we            // are using cached info.            if (info != null) {                Hashtable dependencies                    = (Hashtable) classpathDependencies.get(className);                for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements();) {                    File classpathFile = (File) e2.nextElement();                    if (classpathFile.lastModified()                        > info.absoluteFile.lastModified()) {                        log("Class " + className                            + " is out of date with respect to "                            + classpathFile, Project.MSG_DEBUG);                        outOfDateClasses.put(className, className);                        break;                    }                }            }        }    }    /**     * Does the work.     *     * @exception BuildException Thrown in case of an unrecoverable error.     */    public void execute() throws BuildException {        try {            long start = System.currentTimeMillis();            if (srcPath == null) {                throw new BuildException("srcdir attribute must be set",                                         getLocation());            }            srcPathList = srcPath.list();            if (srcPathList.length == 0) {                throw new BuildException("srcdir attribute must be non-empty",                                         getLocation());            }            if (destPath == null) {                destPath = srcPath;            }            if (cache != null && cache.exists() && !cache.isDirectory()) {                throw new BuildException("The cache, if specified, must "                    + "point to a directory");            }            if (cache != null && !cache.exists()) {                cache.mkdirs();            }            determineDependencies();            if (dump) {                dumpDependencies();            }            determineOutOfDateClasses();            int count = deleteAllAffectedFiles();            long duration = (System.currentTimeMillis() - start) / ONE_SECOND;            final int summaryLogLevel;            if (count > 0) {                summaryLogLevel = Project.MSG_INFO;            }  else {                summaryLogLevel = Project.MSG_DEBUG;            }            log("Deleted " + count + " out of date files in "                + duration + " seconds", summaryLogLevel);        } catch (Exception e) {            throw new BuildException(e);        }    }    /**     * Scans the directory looking for source files that are newer than     * their class files. The results are returned in the class variable     * compileList     *     * @param srcDir the source directory     * @param files the names of the files in the source dir which are to be     *      checked.     */    protected void scanDir(File srcDir, String[] files) {        for (int i = 0; i < files.length; i++) {            File srcFile = new File(srcDir, files[i]);            if (files[i].endsWith(".java")) {                String filePath = srcFile.getPath();                String className                    = filePath.substring(srcDir.getPath().length() + 1,                        filePath.length() - ".java".length());                className = ClassFileUtils.convertSlashName(className);                ClassFileInfo info                    = (ClassFileInfo) classFileInfoMap.get(className);                if (info == null) {                    // there was no class file. add this class to the list                    outOfDateClasses.put(className, className);                } else {                    if (srcFile.lastModified()                        > info.absoluteFile.lastModified()) {                        outOfDateClasses.put(className, className);                    }                }            }        }    }    /**     * Get the list of class files we are going to analyse.     *     * @param classLocations a path structure containing all the directories     *      where classes can be found.     * @return a vector containing the classes to analyse.     */    private Vector getClassFiles(Path classLocations) {        // break the classLocations into its components.        String[] classLocationsList = classLocations.list();        Vector classFileList = new Vector();        for (int i = 0; i < classLocationsList.length; ++i) {            File dir = new File(classLocationsList[i]);            if (dir.isDirectory()) {                addClassFiles(classFileList, dir, dir);            }        }        return classFileList;    }    /**     * Find the source file for a given class     *     * @param classname the classname in slash format.     * @param sourceFileKnownToExist if not null, a file already known to exist     *                               (saves call to .exists())     */    private File findSourceFile(String classname, File sourceFileKnownToExist) {        String sourceFilename;        int innerIndex = classname.indexOf("$");        if (innerIndex != -1) {            sourceFilename = classname.substring(0, innerIndex) + ".java";        } else {            sourceFilename = classname + ".java";        }        // search the various source path entries        for (int i = 0; i < srcPathList.length; ++i) {            File sourceFile = new File(srcPathList[i], sourceFilename);            if (sourceFile.equals(sourceFileKnownToExist) || sourceFile.exists()) {                return sourceFile;            }        }        return null;    }    /**     * Add the list of class files from the given directory to the class     * file vector, including any subdirectories.     *     * @param classFileList a list of ClassFileInfo objects for all the     *      files in the directory tree     * @param dir the directory tree to be searched, recursively, for class     *      files     * @param root the root of the source tree. This is used to determine     *      the absolute class name from the relative position in the     *      source tree     */    private void addClassFiles(Vector classFileList, File dir, File root) {        String[] filesInDir = dir.list();        if (filesInDir == null) {            return;        }        int length = filesInDir.length;        int rootLength = root.getPath().length();        File sourceFileKnownToExist = null; // speed optimization        for (int i = 0; i < length; ++i) {            File file = new File(dir, filesInDir[i]);            if (filesInDir[i].endsWith(".class")) {                ClassFileInfo info = new ClassFileInfo();                info.absoluteFile = file;                String relativeName = file.getPath().substring(                    rootLength + 1,                    file.getPath().length() - ".class".length());                info.className                    = ClassFileUtils.convertSlashName(relativeName);                info.sourceFile = sourceFileKnownToExist = findSourceFile(                    relativeName, sourceFileKnownToExist);                classFileList.addElement(info);            } else {                addClassFiles(classFileList, file, root);            }        }    }    /**     * Set the directories path to find the Java source files.     *     * @param srcPath the source path     */    public void setSrcdir(Path srcPath) {        this.srcPath = srcPath;    }    /**     * Set the destination directory where the compiled Java files exist.     *     * @param destPath the destination areas where build files are written     */    public void setDestDir(Path destPath) {        this.destPath = destPath;    }    /**     * Sets the dependency cache file.     *     * @param cache the dependency cache file     */    public void setCache(File cache) {        this.cache = cache;    }    /**     * If true, transitive dependencies are followed until the     * closure of the dependency set if reached.     * When not set, the depend task will only follow     * direct dependencies between classes.     *     * @param closure indicate if dependency closure is required.     */    public void setClosure(boolean closure) {        this.closure = closure;    }    /**     * If true, the dependency information will be written     * to the debug level log.     *     * @param dump set to true to dump dependency information to the log     */    public void setDump(boolean dump) {        this.dump = dump;    }}

⌨️ 快捷键说明

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