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

📄 delete.java

📁 java ant的源码!非常值得看的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant.taskdefs;import java.io.File;import java.util.Arrays;import java.util.Vector;import java.util.Iterator;import java.util.Comparator;import org.apache.tools.ant.Project;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.taskdefs.condition.Os;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.PatternSet;import org.apache.tools.ant.types.ResourceCollection;import org.apache.tools.ant.types.resources.Sort;import org.apache.tools.ant.types.resources.Restrict;import org.apache.tools.ant.types.resources.Resources;import org.apache.tools.ant.types.resources.FileResource;import org.apache.tools.ant.types.resources.FileResourceIterator;import org.apache.tools.ant.types.resources.comparators.Reverse;import org.apache.tools.ant.types.resources.comparators.FileSystem;import org.apache.tools.ant.types.resources.comparators.ResourceComparator;import org.apache.tools.ant.types.resources.selectors.Exists;import org.apache.tools.ant.types.resources.selectors.ResourceSelector;import org.apache.tools.ant.types.selectors.OrSelector;import org.apache.tools.ant.types.selectors.AndSelector;import org.apache.tools.ant.types.selectors.NotSelector;import org.apache.tools.ant.types.selectors.DateSelector;import org.apache.tools.ant.types.selectors.FileSelector;import org.apache.tools.ant.types.selectors.NoneSelector;import org.apache.tools.ant.types.selectors.SizeSelector;import org.apache.tools.ant.types.selectors.DepthSelector;import org.apache.tools.ant.types.selectors.DependSelector;import org.apache.tools.ant.types.selectors.ExtendSelector;import org.apache.tools.ant.types.selectors.SelectSelector;import org.apache.tools.ant.types.selectors.PresentSelector;import org.apache.tools.ant.types.selectors.ContainsSelector;import org.apache.tools.ant.types.selectors.FilenameSelector;import org.apache.tools.ant.types.selectors.MajoritySelector;import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;/** * Deletes a file or directory, or set of files defined by a fileset. * The original delete task would delete a file, or a set of files * using the include/exclude syntax.  The deltree task would delete a * directory tree.  This task combines the functionality of these two * originally distinct tasks. * <p>Currently Delete extends MatchingTask.  This is intended <i>only</i> * to provide backwards compatibility for a release.  The future position * is to use nested filesets exclusively.</p> * * @since Ant 1.2 * * @ant.task category="filesystem" */public class Delete extends MatchingTask {    private static final int DELETE_RETRY_SLEEP_MILLIS = 10;    private static final ResourceComparator REVERSE_FILESYSTEM = new Reverse(new FileSystem());    private static final ResourceSelector EXISTS = new Exists();    private static class ReverseDirs implements ResourceCollection {        static final Comparator REVERSE = new Comparator() {            public int compare(Object foo, Object bar) {                return ((Comparable) foo).compareTo(bar) * -1;            }        };        private File basedir;        private String[] dirs;        ReverseDirs(File basedir, String[] dirs) {            this.basedir = basedir;            this.dirs = dirs;            Arrays.sort(this.dirs, REVERSE);        }        public Iterator iterator() {            return new FileResourceIterator(basedir, dirs);        }        public boolean isFilesystemOnly() { return true; }        public int size() { return dirs.length; }    }    // CheckStyle:VisibilityModifier OFF - bc    protected File file = null;    protected File dir = null;    protected Vector filesets = new Vector();    protected boolean usedMatchingTask = false;    // by default, remove matching empty dirs    protected boolean includeEmpty = false;    private int verbosity = Project.MSG_VERBOSE;    private boolean quiet = false;    private boolean failonerror = true;    private boolean deleteOnExit = false;    private Resources rcs = null;    // CheckStyle:VisibilityModifier ON    /**     * Set the name of a single file to be removed.     *     * @param file the file to be deleted     */    public void setFile(File file) {        this.file = file;    }    /**     * Set the directory from which files are to be deleted     *     * @param dir the directory path.     */    public void setDir(File dir) {        this.dir = dir;        getImplicitFileSet().setDir(dir);    }    /**     * If true, list all names of deleted files.     *     * @param verbose "true" or "on"     */    public void setVerbose(boolean verbose) {        if (verbose) {            this.verbosity = Project.MSG_INFO;        } else {            this.verbosity = Project.MSG_VERBOSE;        }    }    /**     * If true and the file does not exist, do not display a diagnostic     * message or modify the exit status to reflect an error.     * This means that if a file or directory cannot be deleted,     * then no error is reported. This setting emulates the     * -f option to the Unix &quot;rm&quot; command.     * Default is false meaning things are &quot;noisy&quot;     * @param quiet "true" or "on"     */    public void setQuiet(boolean quiet) {        this.quiet = quiet;        if (quiet) {            this.failonerror = false;        }    }    /**     * If false, note errors but continue.     *     * @param failonerror true or false     */     public void setFailOnError(boolean failonerror) {         this.failonerror = failonerror;     }    /**     * If true, on failure to delete, note the error and set     * the deleteonexit flag, and continue     *     * @param deleteOnExit true or false     */     public void setDeleteOnExit(boolean deleteOnExit) {         this.deleteOnExit = deleteOnExit;     }    /**     * If true, delete empty directories.     * @param includeEmpty if true delete empty directories (only     *                     for filesets). Default is false.     */    public void setIncludeEmptyDirs(boolean includeEmpty) {        this.includeEmpty = includeEmpty;    }   /**    * Adds a set of files to be deleted.    * @param set the set of files to be deleted    */    public void addFileset(FileSet set) {        filesets.addElement(set);    }    /**     * Add an arbitrary ResourceCollection to be deleted.     * @param rc the filesystem-only ResourceCollection.     */    public void add(ResourceCollection rc) {        if (rc == null) {            return;        }        rcs = (rcs == null) ? new Resources() : rcs;        rcs.add(rc);    }    /**     * add a name entry on the include list     * @return a NameEntry object to be configured     */    public PatternSet.NameEntry createInclude() {        usedMatchingTask = true;        return super.createInclude();    }    /**     * add a name entry on the include files list     * @return an NameEntry object to be configured     */    public PatternSet.NameEntry createIncludesFile() {        usedMatchingTask = true;        return super.createIncludesFile();    }    /**     * add a name entry on the exclude list     * @return an NameEntry object to be configured     */    public PatternSet.NameEntry createExclude() {        usedMatchingTask = true;        return super.createExclude();    }    /**     * add a name entry on the include files list     * @return an NameEntry object to be configured     */    public PatternSet.NameEntry createExcludesFile() {        usedMatchingTask = true;        return super.createExcludesFile();    }    /**     * add a set of patterns     * @return PatternSet object to be configured     */    public PatternSet createPatternSet() {        usedMatchingTask = true;        return super.createPatternSet();    }    /**     * Sets the set of include patterns. Patterns may be separated by a comma     * or a space.     *     * @param includes the string containing the include patterns     */    public void setIncludes(String includes) {        usedMatchingTask = true;        super.setIncludes(includes);    }    /**     * Sets the set 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) {        usedMatchingTask = true;        super.setExcludes(excludes);    }    /**     * Sets whether default exclusions should be used or not.     *     * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions     *                           should be used, "false"|"off"|"no" when they     *                           shouldn't be used.     */    public void setDefaultexcludes(boolean useDefaultExcludes) {        usedMatchingTask = true;        super.setDefaultexcludes(useDefaultExcludes);    }    /**     * Sets the name of the file containing the includes patterns.     *     * @param includesfile A string containing the filename to fetch     * the include patterns from.     */    public void setIncludesfile(File includesfile) {        usedMatchingTask = true;        super.setIncludesfile(includesfile);    }    /**     * Sets the name of the file containing the includes patterns.     *     * @param excludesfile A string containing the filename to fetch     * the include patterns from.     */    public void setExcludesfile(File excludesfile) {        usedMatchingTask = true;        super.setExcludesfile(excludesfile);    }    /**     * Sets case sensitivity of the file system     *     * @param isCaseSensitive "true"|"on"|"yes" if file system is case     *                           sensitive, "false"|"off"|"no" when not.     */    public void setCaseSensitive(boolean isCaseSensitive) {        usedMatchingTask = true;        super.setCaseSensitive(isCaseSensitive);    }    /**     * Sets whether or not symbolic links should be followed.     *     * @param followSymlinks whether or not symbolic links should be followed     */    public void setFollowSymlinks(boolean followSymlinks) {        usedMatchingTask = true;        super.setFollowSymlinks(followSymlinks);    }    /**     * add a "Select" selector entry on the selector list     * @param selector the selector to be added     */    public void addSelector(SelectSelector selector) {        usedMatchingTask = true;        super.addSelector(selector);    }    /**     * add an "And" selector entry on the selector list     * @param selector the selector to be added     */    public void addAnd(AndSelector selector) {        usedMatchingTask = true;        super.addAnd(selector);    }    /**     * add an "Or" selector entry on the selector list     * @param selector the selector to be added     */    public void addOr(OrSelector selector) {        usedMatchingTask = true;        super.addOr(selector);    }    /**     * add a "Not" selector entry on the selector list     * @param selector the selector to be added     */    public void addNot(NotSelector selector) {        usedMatchingTask = true;        super.addNot(selector);    }

⌨️ 快捷键说明

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