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

📄 patternset.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /**     * Appends <code>excludes</code> to the current list of exclude patterns.     * Patterns may be separated by a comma or a space.     *     * @param excludes the string containing the exclude patterns     */    public void setExcludes(String excludes) {        if (isReference()) {            throw tooManyAttributes();        }        if (excludes != null && excludes.length() > 0) {            StringTokenizer tok = new StringTokenizer(excludes, ", ", false);            while (tok.hasMoreTokens()) {                createExclude().setName(tok.nextToken());            }        }    }    /**     * add a name entry to the given list     */    private NameEntry addPatternToList(Vector list) {        NameEntry result = new NameEntry();        list.addElement(result);        return result;    }    /**     * Sets the name of the file containing the includes patterns.     *     * @param includesFile The file to fetch the include patterns from.     * @throws BuildException on error.     */     public void setIncludesfile(File includesFile) throws BuildException {         if (isReference()) {             throw tooManyAttributes();         }         createIncludesFile().setName(includesFile.getAbsolutePath());     }    /**     * Sets the name of the file containing the excludes patterns.     *     * @param excludesFile The file to fetch the exclude patterns from.     * @throws BuildException on error.     */     public void setExcludesfile(File excludesFile) throws BuildException {         if (isReference()) {             throw tooManyAttributes();         }         createExcludesFile().setName(excludesFile.getAbsolutePath());     }    /**     *  Reads path matching patterns from a file and adds them to the     *  includes or excludes list (as appropriate).     */    private void readPatterns(File patternfile, Vector patternlist, Project p)        throws BuildException {        BufferedReader patternReader = null;        try {            // Get a FileReader            patternReader =                new BufferedReader(new FileReader(patternfile));            // Create one NameEntry in the appropriate pattern list for each            // line in the file.            String line = patternReader.readLine();            while (line != null) {                if (line.length() > 0) {                    line = p.replaceProperties(line);                    addPatternToList(patternlist).setName(line);                }                line = patternReader.readLine();            }        } catch (IOException ioe)  {            String msg = "An error occurred while reading from pattern file: "                + patternfile;            throw new BuildException(msg, ioe);        } finally {            if (null != patternReader) {                try {                    patternReader.close();                } catch (IOException ioe) {                    //Ignore exception                }            }        }    }    /**     * Adds the patterns of the other instance to this set.     * @param other the other PatternSet instance.     * @param p the current project.     */    public void append(PatternSet other, Project p) {        if (isReference()) {            throw new BuildException("Cannot append to a reference");        }        String[] incl = other.getIncludePatterns(p);        if (incl != null) {            for (int i = 0; i < incl.length; i++) {                createInclude().setName(incl[i]);            }        }        String[] excl = other.getExcludePatterns(p);        if (excl != null) {            for (int i = 0; i < excl.length; i++) {                createExclude().setName(excl[i]);            }        }    }    /**     * Returns the filtered include patterns.     * @param p the current project.     * @return the filtered included patterns.     */    public String[] getIncludePatterns(Project p) {        if (isReference()) {            return getRef(p).getIncludePatterns(p);        } else {            readFiles(p);            return makeArray(includeList, p);        }    }    /**     * Returns the filtered include patterns.     * @param p the current project.     * @return the filtered excluded patterns.     */    public String[] getExcludePatterns(Project p) {        if (isReference()) {            return getRef(p).getExcludePatterns(p);        } else {            readFiles(p);            return makeArray(excludeList, p);        }    }    /**     * Helper for FileSet classes.     * Check if there are patterns defined.     * @param p the current project.     * @return true if there are patterns.     */    public boolean hasPatterns(Project p) {        if (isReference()) {            return getRef(p).hasPatterns(p);        } else {            return includesFileList.size() > 0 || excludesFileList.size() > 0                || includeList.size() > 0 || excludeList.size() > 0;        }    }    /**     * Performs the check for circular references and returns the     * referenced PatternSet.     */    private PatternSet getRef(Project p) {        return (PatternSet) getCheckedRef(p);    }    /**     * Convert a vector of NameEntry elements into an array of Strings.     */    private String[] makeArray(Vector list, Project p) {        if (list.size() == 0) {            return null;        }        Vector tmpNames = new Vector();        for (Enumeration e = list.elements(); e.hasMoreElements();) {            NameEntry ne = (NameEntry) e.nextElement();            String pattern = ne.evalName(p);            if (pattern != null && pattern.length() > 0) {                tmpNames.addElement(pattern);            }        }        String[] result = new String[tmpNames.size()];        tmpNames.copyInto(result);        return result;    }    /**     * Read includesfile ot excludesfile if not already done so.     */    private void readFiles(Project p) {        if (includesFileList.size() > 0) {            Enumeration e = includesFileList.elements();            while (e.hasMoreElements()) {                NameEntry ne = (NameEntry) e.nextElement();                String fileName = ne.evalName(p);                if (fileName != null) {                    File inclFile = p.resolveFile(fileName);                    if (!inclFile.exists()) {                        throw new BuildException("Includesfile "                                                 + inclFile.getAbsolutePath()                                                 + " not found.");                    }                    readPatterns(inclFile, includeList, p);                }            }            includesFileList.removeAllElements();        }        if (excludesFileList.size() > 0) {            Enumeration e = excludesFileList.elements();            while (e.hasMoreElements()) {                NameEntry ne = (NameEntry) e.nextElement();                String fileName = ne.evalName(p);                if (fileName != null) {                    File exclFile = p.resolveFile(fileName);                    if (!exclFile.exists()) {                        throw new BuildException("Excludesfile "                                                 + exclFile.getAbsolutePath()                                                 + " not found.");                    }                    readPatterns(exclFile, excludeList, p);                }            }            excludesFileList.removeAllElements();        }    }    /**     * @return a printable form of this object.     */    public String toString() {        return "patternSet{ includes: " + includeList                + " excludes: " + excludeList + " }";    }    /**     * @since Ant 1.6     * @return a clone of this patternset.     */    public Object clone() {        try {            PatternSet ps = (PatternSet) super.clone();            ps.includeList = (Vector) includeList.clone();            ps.excludeList = (Vector) excludeList.clone();            ps.includesFileList = (Vector) includesFileList.clone();            ps.excludesFileList = (Vector) excludesFileList.clone();            return ps;        } catch (CloneNotSupportedException e) {            throw new BuildException(e);        }    }    /**     * Add an inverted patternset.     * @param p the pattern to invert and add.     */    public void addConfiguredInvert(PatternSet p) {        addConfiguredPatternset(new InvertedPatternSet(p));    }}

⌨️ 快捷键说明

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