Save This Page
Home » apache-ant-1.8.1 » org.apache.tools » ant » taskdefs » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    *
   17    */
   18   
   19   package org.apache.tools.ant.taskdefs;
   20   
   21   import java.io.File;
   22   import java.util.Enumeration;
   23   import java.util.StringTokenizer;
   24   import org.apache.tools.ant.DirectoryScanner;
   25   import org.apache.tools.ant.Project;
   26   import org.apache.tools.ant.Task;
   27   import org.apache.tools.ant.types.FileSet;
   28   import org.apache.tools.ant.types.PatternSet;
   29   import org.apache.tools.ant.types.selectors.AndSelector;
   30   import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
   31   import org.apache.tools.ant.types.selectors.ContainsSelector;
   32   import org.apache.tools.ant.types.selectors.DateSelector;
   33   import org.apache.tools.ant.types.selectors.DependSelector;
   34   import org.apache.tools.ant.types.selectors.DepthSelector;
   35   import org.apache.tools.ant.types.selectors.DifferentSelector;
   36   import org.apache.tools.ant.types.selectors.ExtendSelector;
   37   import org.apache.tools.ant.types.selectors.FileSelector;
   38   import org.apache.tools.ant.types.selectors.FilenameSelector;
   39   import org.apache.tools.ant.types.selectors.MajoritySelector;
   40   import org.apache.tools.ant.types.selectors.NoneSelector;
   41   import org.apache.tools.ant.types.selectors.NotSelector;
   42   import org.apache.tools.ant.types.selectors.OrSelector;
   43   import org.apache.tools.ant.types.selectors.PresentSelector;
   44   import org.apache.tools.ant.types.selectors.SelectSelector;
   45   import org.apache.tools.ant.types.selectors.SelectorContainer;
   46   import org.apache.tools.ant.types.selectors.SizeSelector;
   47   import org.apache.tools.ant.types.selectors.TypeSelector;
   48   import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
   49   
   50   /**
   51    * This is an abstract task that should be used by all those tasks that
   52    * require to include or exclude files based on pattern matching.
   53    *
   54    * @since Ant 1.1
   55    */
   56   
   57   public abstract class MatchingTask extends Task implements SelectorContainer {
   58   
   59       // CheckStyle:VisibilityModifier OFF - bc
   60       protected FileSet fileset = new FileSet();
   61       // CheckStyle:VisibilityModifier ON
   62   
   63       /** {@inheritDoc}. */
   64       public void setProject(Project project) {
   65           super.setProject(project);
   66           fileset.setProject(project);
   67       }
   68   
   69       /**
   70        * add a name entry on the include list
   71        * @return a NameEntry object to be configured
   72        */
   73       public PatternSet.NameEntry createInclude() {
   74           return fileset.createInclude();
   75       }
   76   
   77       /**
   78        * add a name entry on the include files list
   79        * @return an NameEntry object to be configured
   80        */
   81       public PatternSet.NameEntry createIncludesFile() {
   82           return fileset.createIncludesFile();
   83       }
   84   
   85       /**
   86        * add a name entry on the exclude list
   87        * @return an NameEntry object to be configured
   88        */
   89       public PatternSet.NameEntry createExclude() {
   90           return fileset.createExclude();
   91       }
   92   
   93       /**
   94        * add a name entry on the include files list
   95        * @return an NameEntry object to be configured
   96        */
   97       public PatternSet.NameEntry createExcludesFile() {
   98           return fileset.createExcludesFile();
   99       }
  100   
  101       /**
  102        * add a set of patterns
  103        * @return PatternSet object to be configured
  104        */
  105       public PatternSet createPatternSet() {
  106           return fileset.createPatternSet();
  107       }
  108   
  109       /**
  110        * Sets the set of include patterns. Patterns may be separated by a comma
  111        * or a space.
  112        *
  113        * @param includes the string containing the include patterns
  114        */
  115       public void setIncludes(String includes) {
  116           fileset.setIncludes(includes);
  117       }
  118   
  119       // CheckStyle:MethodNameCheck OFF - bc
  120       /**
  121        * Set this to be the items in the base directory that you want to be
  122        * included. You can also specify "*" for the items (ie: items="*")
  123        * and it will include all the items in the base directory.
  124        *
  125        * @param itemString the string containing the files to include.
  126        */
  127       public void XsetItems(String itemString) {
  128           log("The items attribute is deprecated. "
  129               + "Please use the includes attribute.", Project.MSG_WARN);
  130           if (itemString == null || itemString.equals("*")
  131               || itemString.equals(".")) {
  132               createInclude().setName("**");
  133           } else {
  134               StringTokenizer tok = new StringTokenizer(itemString, ", ");
  135               while (tok.hasMoreTokens()) {
  136                   String pattern = tok.nextToken().trim();
  137                   if (pattern.length() > 0) {
  138                       createInclude().setName(pattern + "/**");
  139                   }
  140               }
  141           }
  142       }
  143   
  144       /**
  145        * Sets the set of exclude patterns. Patterns may be separated by a comma
  146        * or a space.
  147        *
  148        * @param excludes the string containing the exclude patterns
  149        */
  150       public void setExcludes(String excludes) {
  151           fileset.setExcludes(excludes);
  152       }
  153   
  154       /**
  155        * List of filenames and directory names to not include. They should be
  156        * either , or " " (space) separated. The ignored files will be logged.
  157        *
  158        * @param ignoreString the string containing the files to ignore.
  159        */
  160       public void XsetIgnore(String ignoreString) {
  161           log("The ignore attribute is deprecated."
  162               + "Please use the excludes attribute.", Project.MSG_WARN);
  163           if (ignoreString != null && ignoreString.length() > 0) {
  164               StringTokenizer tok = new StringTokenizer(ignoreString, ", ",
  165                                                         false);
  166               while (tok.hasMoreTokens()) {
  167                   createExclude().setName("**/" + tok.nextToken().trim() + "/**");
  168               }
  169           }
  170       }
  171   
  172       // CheckStyle:VisibilityModifier ON
  173   
  174       /**
  175        * Sets whether default exclusions should be used or not.
  176        *
  177        * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
  178        *                           should be used, "false"|"off"|"no" when they
  179        *                           shouldn't be used.
  180        */
  181       public void setDefaultexcludes(boolean useDefaultExcludes) {
  182           fileset.setDefaultexcludes(useDefaultExcludes);
  183       }
  184   
  185       /**
  186        * Returns the directory scanner needed to access the files to process.
  187        * @param baseDir the base directory to use with the fileset
  188        * @return a directory scanner
  189        */
  190       protected DirectoryScanner getDirectoryScanner(File baseDir) {
  191           fileset.setDir(baseDir);
  192           return fileset.getDirectoryScanner(getProject());
  193       }
  194   
  195       /**
  196        * Sets the name of the file containing the includes patterns.
  197        *
  198        * @param includesfile A string containing the filename to fetch
  199        * the include patterns from.
  200        */
  201       public void setIncludesfile(File includesfile) {
  202           fileset.setIncludesfile(includesfile);
  203       }
  204   
  205       /**
  206        * Sets the name of the file containing the includes patterns.
  207        *
  208        * @param excludesfile A string containing the filename to fetch
  209        * the include patterns from.
  210        */
  211       public void setExcludesfile(File excludesfile) {
  212           fileset.setExcludesfile(excludesfile);
  213       }
  214   
  215       /**
  216        * Sets case sensitivity of the file system
  217        *
  218        * @param isCaseSensitive "true"|"on"|"yes" if file system is case
  219        *                           sensitive, "false"|"off"|"no" when not.
  220        */
  221       public void setCaseSensitive(boolean isCaseSensitive) {
  222           fileset.setCaseSensitive(isCaseSensitive);
  223       }
  224   
  225       /**
  226        * Sets whether or not symbolic links should be followed.
  227        *
  228        * @param followSymlinks whether or not symbolic links should be followed
  229        */
  230       public void setFollowSymlinks(boolean followSymlinks) {
  231           fileset.setFollowSymlinks(followSymlinks);
  232       }
  233   
  234       /**
  235        * Indicates whether there are any selectors here.
  236        *
  237        * @return whether any selectors are in this container
  238        */
  239       public boolean hasSelectors() {
  240           return fileset.hasSelectors();
  241       }
  242   
  243       /**
  244        * Gives the count of the number of selectors in this container
  245        *
  246        * @return the number of selectors in this container
  247        */
  248       public int selectorCount() {
  249           return fileset.selectorCount();
  250       }
  251   
  252       /**
  253        * Returns the set of selectors as an array.
  254        * @param p the current project
  255        * @return an array of selectors in this container
  256        */
  257       public FileSelector[] getSelectors(Project p) {
  258           return fileset.getSelectors(p);
  259       }
  260   
  261       /**
  262        * Returns an enumerator for accessing the set of selectors.
  263        *
  264        * @return an enumerator that goes through each of the selectors
  265        */
  266       public Enumeration selectorElements() {
  267           return fileset.selectorElements();
  268       }
  269   
  270       /**
  271        * Add a new selector into this container.
  272        *
  273        * @param selector the new selector to add
  274        */
  275       public void appendSelector(FileSelector selector) {
  276           fileset.appendSelector(selector);
  277       }
  278   
  279       /* Methods below all add specific selectors */
  280   
  281       /**
  282        * add a "Select" selector entry on the selector list
  283        * @param selector the selector to add
  284        */
  285       public void addSelector(SelectSelector selector) {
  286           fileset.addSelector(selector);
  287       }
  288   
  289       /**
  290        * add an "And" selector entry on the selector list
  291        * @param selector the selector to add
  292        */
  293       public void addAnd(AndSelector selector) {
  294           fileset.addAnd(selector);
  295       }
  296   
  297       /**
  298        * add an "Or" selector entry on the selector list
  299        * @param selector the selector to add
  300        */
  301       public void addOr(OrSelector selector) {
  302           fileset.addOr(selector);
  303       }
  304   
  305       /**
  306        * add a "Not" selector entry on the selector list
  307        * @param selector the selector to add
  308        */
  309       public void addNot(NotSelector selector) {
  310           fileset.addNot(selector);
  311       }
  312   
  313       /**
  314        * add a "None" selector entry on the selector list
  315        * @param selector the selector to add
  316        */
  317       public void addNone(NoneSelector selector) {
  318           fileset.addNone(selector);
  319       }
  320   
  321       /**
  322        * add a majority selector entry on the selector list
  323        * @param selector the selector to add
  324        */
  325       public void addMajority(MajoritySelector selector) {
  326           fileset.addMajority(selector);
  327       }
  328   
  329       /**
  330        * add a selector date entry on the selector list
  331        * @param selector the selector to add
  332        */
  333       public void addDate(DateSelector selector) {
  334           fileset.addDate(selector);
  335       }
  336   
  337       /**
  338        * add a selector size entry on the selector list
  339        * @param selector the selector to add
  340        */
  341       public void addSize(SizeSelector selector) {
  342           fileset.addSize(selector);
  343       }
  344   
  345       /**
  346        * add a selector filename entry on the selector list
  347        * @param selector the selector to add
  348        */
  349       public void addFilename(FilenameSelector selector) {
  350           fileset.addFilename(selector);
  351       }
  352   
  353       /**
  354        * add an extended selector entry on the selector list
  355        * @param selector the selector to add
  356        */
  357       public void addCustom(ExtendSelector selector) {
  358           fileset.addCustom(selector);
  359       }
  360   
  361       /**
  362        * add a contains selector entry on the selector list
  363        * @param selector the selector to add
  364        */
  365       public void addContains(ContainsSelector selector) {
  366           fileset.addContains(selector);
  367       }
  368   
  369       /**
  370        * add a present selector entry on the selector list
  371        * @param selector the selector to add
  372        */
  373       public void addPresent(PresentSelector selector) {
  374           fileset.addPresent(selector);
  375       }
  376   
  377       /**
  378        * add a depth selector entry on the selector list
  379        * @param selector the selector to add
  380        */
  381       public void addDepth(DepthSelector selector) {
  382           fileset.addDepth(selector);
  383       }
  384   
  385       /**
  386        * add a depends selector entry on the selector list
  387        * @param selector the selector to add
  388        */
  389       public void addDepend(DependSelector selector) {
  390           fileset.addDepend(selector);
  391       }
  392   
  393       /**
  394        * add a regular expression selector entry on the selector list
  395        * @param selector the selector to add
  396        */
  397       public void addContainsRegexp(ContainsRegexpSelector selector) {
  398           fileset.addContainsRegexp(selector);
  399       }
  400   
  401       /**
  402        * add a type selector entry on the type list
  403        * @param selector the selector to add
  404        * @since ant 1.6
  405        */
  406       public void addDifferent(DifferentSelector selector) {
  407           fileset.addDifferent(selector);
  408       }
  409   
  410       /**
  411        * add a type selector entry on the type list
  412        * @param selector the selector to add
  413        * @since ant 1.6
  414        */
  415       public void addType(TypeSelector selector) {
  416           fileset.addType(selector);
  417       }
  418   
  419       /**
  420        * add the modified selector
  421        * @param selector the selector to add
  422        * @since ant 1.6
  423        */
  424       public void addModified(ModifiedSelector selector) {
  425           fileset.addModified(selector);
  426       }
  427   
  428       /**
  429        * add an arbitary selector
  430        * @param selector the selector to add
  431        * @since Ant 1.6
  432        */
  433       public void add(FileSelector selector) {
  434           fileset.add(selector);
  435       }
  436   
  437       /**
  438        * Accessor for the implicit fileset.
  439        * @return the implicit fileset
  440        * @since Ant 1.5.2
  441        */
  442       protected final FileSet getImplicitFileSet() {
  443           return fileset;
  444       }
  445   }

Save This Page
Home » apache-ant-1.8.1 » org.apache.tools » ant » taskdefs » [javadoc | source]