KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > AbstractFileSet


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 package org.apache.tools.ant.types;
19
20 import java.io.File JavaDoc;
21 import java.util.Vector JavaDoc;
22 import java.util.Enumeration JavaDoc;
23
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.FileScanner;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.DirectoryScanner;
28 import org.apache.tools.ant.types.selectors.OrSelector;
29 import org.apache.tools.ant.types.selectors.AndSelector;
30 import org.apache.tools.ant.types.selectors.NotSelector;
31 import org.apache.tools.ant.types.selectors.DateSelector;
32 import org.apache.tools.ant.types.selectors.FileSelector;
33 import org.apache.tools.ant.types.selectors.NoneSelector;
34 import org.apache.tools.ant.types.selectors.SizeSelector;
35 import org.apache.tools.ant.types.selectors.TypeSelector;
36 import org.apache.tools.ant.types.selectors.DepthSelector;
37 import org.apache.tools.ant.types.selectors.DependSelector;
38 import org.apache.tools.ant.types.selectors.ExtendSelector;
39 import org.apache.tools.ant.types.selectors.SelectSelector;
40 import org.apache.tools.ant.types.selectors.PresentSelector;
41 import org.apache.tools.ant.types.selectors.SelectorScanner;
42 import org.apache.tools.ant.types.selectors.ContainsSelector;
43 import org.apache.tools.ant.types.selectors.FilenameSelector;
44 import org.apache.tools.ant.types.selectors.MajoritySelector;
45 import org.apache.tools.ant.types.selectors.DifferentSelector;
46 import org.apache.tools.ant.types.selectors.SelectorContainer;
47 import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
48 import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
49
50 /**
51  * Class that holds an implicit patternset and supports nested
52  * patternsets and creates a DirectoryScanner using these patterns.
53  *
54  * <p>Common base class for DirSet and FileSet.</p>
55  *
56  */

57 public abstract class AbstractFileSet extends DataType
58     implements Cloneable JavaDoc, SelectorContainer {
59
60     private PatternSet defaultPatterns = new PatternSet();
61     private Vector JavaDoc additionalPatterns = new Vector JavaDoc();
62     private Vector JavaDoc selectors = new Vector JavaDoc();
63
64     private File JavaDoc dir;
65     private boolean useDefaultExcludes = true;
66     private boolean caseSensitive = true;
67     private boolean followSymlinks = true;
68
69     /* cached DirectoryScanner instance for our own Project only */
70     private DirectoryScanner directoryScanner = null;
71
72     /**
73      * Construct a new <code>AbstractFileSet</code>.
74      */

75     public AbstractFileSet() {
76         super();
77     }
78
79     /**
80      * Construct a new <code>AbstractFileSet</code>, shallowly cloned
81      * from the specified <code>AbstractFileSet</code>.
82      * @param fileset the <code>AbstractFileSet</code> to use as a template.
83      */

84     protected AbstractFileSet(AbstractFileSet fileset) {
85         this.dir = fileset.dir;
86         this.defaultPatterns = fileset.defaultPatterns;
87         this.additionalPatterns = fileset.additionalPatterns;
88         this.selectors = fileset.selectors;
89         this.useDefaultExcludes = fileset.useDefaultExcludes;
90         this.caseSensitive = fileset.caseSensitive;
91         this.followSymlinks = fileset.followSymlinks;
92         setProject(fileset.getProject());
93     }
94
95     /**
96      * Makes this instance in effect a reference to another instance.
97      *
98      * <p>You must not set another attribute or nest elements inside
99      * this element if you make it a reference.</p>
100      * @param r the <code>Reference</code> to use.
101      * @throws BuildException on error
102      */

103     public void setRefid(Reference r) throws BuildException {
104         if (dir != null || defaultPatterns.hasPatterns(getProject())) {
105             throw tooManyAttributes();
106         }
107         if (!additionalPatterns.isEmpty()) {
108             throw noChildrenAllowed();
109         }
110         if (!selectors.isEmpty()) {
111             throw noChildrenAllowed();
112         }
113         super.setRefid(r);
114     }
115
116     /**
117      * Sets the base-directory for this instance.
118      * @param dir the directory's <code>File</code> instance.
119      * @throws BuildException on error
120      */

121     public synchronized void setDir(File JavaDoc dir) throws BuildException {
122         if (isReference()) {
123             throw tooManyAttributes();
124         }
125         this.dir = dir;
126         directoryScanner = null;
127     }
128
129     /**
130      * Retrieves the base-directory for this instance.
131      * @return <code>File</code>.
132      */

133     public File JavaDoc getDir() {
134         return getDir(getProject());
135     }
136
137     /**
138      * Retrieves the base-directory for this instance.
139      * @param p the <code>Project</code> against which the
140      * reference is resolved, if set.
141      * @return <code>File</code>.
142      */

143     public synchronized File JavaDoc getDir(Project p) {
144         return (isReference()) ? getRef(p).getDir(p) : dir;
145     }
146
147     /**
148      * Creates a nested patternset.
149      * @return <code>PatternSet</code>.
150      */

151     public synchronized PatternSet createPatternSet() {
152         if (isReference()) {
153             throw noChildrenAllowed();
154         }
155         PatternSet patterns = new PatternSet();
156         additionalPatterns.addElement(patterns);
157         directoryScanner = null;
158         return patterns;
159     }
160
161     /**
162      * Add a name entry to the include list.
163      * @return <code>PatternSet.NameEntry</code>.
164      */

165     public synchronized PatternSet.NameEntry createInclude() {
166         if (isReference()) {
167             throw noChildrenAllowed();
168         }
169         directoryScanner = null;
170         return defaultPatterns.createInclude();
171     }
172
173     /**
174      * Add a name entry to the include files list.
175      * @return <code>PatternSet.NameEntry</code>.
176      */

177     public synchronized PatternSet.NameEntry createIncludesFile() {
178         if (isReference()) {
179             throw noChildrenAllowed();
180         }
181         directoryScanner = null;
182         return defaultPatterns.createIncludesFile();
183     }
184
185     /**
186      * Add a name entry to the exclude list.
187      * @return <code>PatternSet.NameEntry</code>.
188      */

189     public synchronized PatternSet.NameEntry createExclude() {
190         if (isReference()) {
191             throw noChildrenAllowed();
192         }
193         directoryScanner = null;
194         return defaultPatterns.createExclude();
195     }
196
197     /**
198      * Add a name entry to the excludes files list.
199      * @return <code>PatternSet.NameEntry</code>.
200      */

201     public synchronized PatternSet.NameEntry createExcludesFile() {
202         if (isReference()) {
203             throw noChildrenAllowed();
204         }
205         directoryScanner = null;
206         return defaultPatterns.createExcludesFile();
207     }
208
209     /**
210      * Creates a single file fileset.
211      * @param file the single <code>File</code> included in this
212      * <code>AbstractFileSet</code>.
213      */

214     public synchronized void setFile(File JavaDoc file) {
215         if (isReference()) {
216             throw tooManyAttributes();
217         }
218         setDir(file.getParentFile());
219         createInclude().setName(file.getName());
220     }
221
222     /**
223      * Appends <code>includes</code> to the current list of include
224      * patterns.
225      *
226      * <p>Patterns may be separated by a comma or a space.</p>
227      *
228      * @param includes the <code>String</code> containing the include patterns.
229      */

230     public synchronized void setIncludes(String JavaDoc includes) {
231         if (isReference()) {
232             throw tooManyAttributes();
233         }
234         defaultPatterns.setIncludes(includes);
235         directoryScanner = null;
236     }
237
238     /**
239      * Appends <code>includes</code> to the current list of include
240      * patterns.
241      *
242      * @param includes array containing the include patterns.
243      * @since Ant 1.7
244      */

245     public synchronized void appendIncludes(String JavaDoc[] includes) {
246         if (isReference()) {
247             throw tooManyAttributes();
248         }
249         if (includes != null) {
250             for (int i = 0; i < includes.length; i++) {
251                 defaultPatterns.createInclude().setName(includes[i]);
252             }
253             directoryScanner = null;
254         }
255     }
256
257     /**
258      * Appends <code>excludes</code> to the current list of exclude
259      * patterns.
260      *
261      * <p>Patterns may be separated by a comma or a space.</p>
262      *
263      * @param excludes the <code>String</code> containing the exclude patterns.
264      */

265     public synchronized void setExcludes(String JavaDoc excludes) {
266         if (isReference()) {
267             throw tooManyAttributes();
268         }
269         defaultPatterns.setExcludes(excludes);
270         directoryScanner = null;
271     }
272
273     /**
274      * Appends <code>excludes</code> to the current list of include
275      * patterns.
276      *
277      * @param excludes array containing the exclude patterns.
278      * @since Ant 1.7
279      */

280     public synchronized void appendExcludes(String JavaDoc[] excludes) {
281         if (isReference()) {
282             throw tooManyAttributes();
283         }
284         if (excludes != null) {
285             for (int i = 0; i < excludes.length; i++) {
286                 defaultPatterns.createExclude().setName(excludes[i]);
287             }
288             directoryScanner = null;
289         }
290     }
291
292     /**
293      * Sets the <code>File</code> containing the includes patterns.
294      *
295      * @param incl <code>File</code> instance.
296      * @throws BuildException on error
297      */

298     public synchronized void setIncludesfile(File JavaDoc incl) throws BuildException {
299         if (isReference()) {
300             throw tooManyAttributes();
301         }
302         defaultPatterns.setIncludesfile(incl);
303         directoryScanner = null;
304     }
305
306     /**
307      * Sets the <code>File</code> containing the excludes patterns.
308      *
309      * @param excl <code>File</code> instance.
310      * @throws BuildException on error
311      */

312     public synchronized void setExcludesfile(File JavaDoc excl) throws BuildException {
313         if (isReference()) {
314             throw tooManyAttributes();
315         }
316         defaultPatterns.setExcludesfile(excl);
317         directoryScanner = null;
318     }
319
320     /**
321      * Sets whether default exclusions should be used or not.
322      *
323      * @param useDefaultExcludes <code>boolean</code>.
324      */

325     public synchronized void setDefaultexcludes(boolean useDefaultExcludes) {
326         if (isReference()) {
327             throw tooManyAttributes();
328         }
329         this.useDefaultExcludes = useDefaultExcludes;
330         directoryScanner = null;
331     }
332
333     /**
334      * Whether default exclusions should be used or not.
335      * @return the default exclusions value.
336      * @since Ant 1.6.3
337      */

338     public synchronized boolean getDefaultexcludes() {
339         return (isReference())
340             ? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes;
341     }
342
343     /**
344      * Sets case sensitivity of the file system.
345      *
346      * @param caseSensitive <code>boolean</code>.
347      */

348     public synchronized void setCaseSensitive(boolean caseSensitive) {
349         if (isReference()) {
350             throw tooManyAttributes();
351         }
352         this.caseSensitive = caseSensitive;
353         directoryScanner = null;
354     }
355
356     /**
357      * Find out if the fileset is case sensitive.
358      *
359      * @return <code>boolean</code> indicating whether the fileset is
360      * case sensitive.
361      *
362      * @since Ant 1.7
363      */

364     public synchronized boolean isCaseSensitive() {
365         return (isReference())
366             ? getRef(getProject()).isCaseSensitive() : caseSensitive;
367     }
368
369     /**
370      * Sets whether or not symbolic links should be followed.
371      *
372      * @param followSymlinks whether or not symbolic links should be followed.
373      */

374     public synchronized void setFollowSymlinks(boolean followSymlinks) {
375         if (isReference()) {
376             throw tooManyAttributes();
377         }
378         this.followSymlinks = followSymlinks;
379         directoryScanner = null;
380     }
381
382     /**
383      * Find out if the fileset wants to follow symbolic links.
384      *
385      * @return <code>boolean</code> indicating whether symbolic links
386      * should be followed.
387      *
388      * @since Ant 1.6
389      */

390     public synchronized boolean isFollowSymlinks() {
391         return (isReference())
392             ? getRef(getProject()).isFollowSymlinks() : followSymlinks;
393     }
394
395     /**
396      * Returns the directory scanner needed to access the files to process.
397      * @return a <code>DirectoryScanner</code> instance.
398      */

399     public DirectoryScanner getDirectoryScanner() {
400         return getDirectoryScanner(getProject());
401     }
402
403     /**
404      * Returns the directory scanner needed to access the files to process.
405      * @param p the Project against which the DirectoryScanner should be configured.
406      * @return a <code>DirectoryScanner</code> instance.
407      */

408     public DirectoryScanner getDirectoryScanner(Project p) {
409         if (isReference()) {
410             return getRef(p).getDirectoryScanner(p);
411         }
412         DirectoryScanner ds = null;
413         synchronized (this) {
414             if (directoryScanner != null && p == getProject()) {
415                 ds = directoryScanner;
416             } else {
417                 if (dir == null) {
418                     throw new BuildException("No directory specified for "
419                                              + getDataTypeName() + ".");
420                 }
421                 if (!dir.exists()) {
422                     throw new BuildException(dir.getAbsolutePath()
423                                              + " not found.");
424                 }
425                 if (!dir.isDirectory()) {
426                     throw new BuildException(dir.getAbsolutePath()
427                                              + " is not a directory.");
428                 }
429                 ds = new DirectoryScanner();
430                 setupDirectoryScanner(ds, p);
431                 ds.setFollowSymlinks(followSymlinks);
432                 directoryScanner = (p == getProject()) ? ds : directoryScanner;
433             }
434         }
435         ds.scan();
436         return ds;
437     }
438
439     /**
440      * Set up the specified directory scanner against this
441      * AbstractFileSet's Project.
442      * @param ds a <code>FileScanner</code> instance.
443      */

444     public void setupDirectoryScanner(FileScanner ds) {
445         setupDirectoryScanner(ds, getProject());
446     }
447
448     /**
449      * Set up the specified directory scanner against the specified project.
450      * @param ds a <code>FileScanner</code> instance.
451      * @param p an Ant <code>Project</code> instance.
452      */

453     public synchronized void setupDirectoryScanner(FileScanner ds, Project p) {
454         if (isReference()) {
455             getRef(p).setupDirectoryScanner(ds, p);
456             return;
457         }
458         if (ds == null) {
459             throw new IllegalArgumentException JavaDoc("ds cannot be null");
460         }
461         ds.setBasedir(dir);
462
463         PatternSet ps = mergePatterns(p);
464         p.log(getDataTypeName() + ": Setup scanner in dir " + dir
465             + " with " + ps, Project.MSG_DEBUG);
466
467         ds.setIncludes(ps.getIncludePatterns(p));
468         ds.setExcludes(ps.getExcludePatterns(p));
469         if (ds instanceof SelectorScanner) {
470             SelectorScanner ss = (SelectorScanner) ds;
471             ss.setSelectors(getSelectors(p));
472         }
473         if (useDefaultExcludes) {
474             ds.addDefaultExcludes();
475         }
476         ds.setCaseSensitive(caseSensitive);
477     }
478
479     /**
480      * Performs the check for circular references and returns the
481      * referenced FileSet.
482      * @param p the current project
483      * @return the referenced FileSet
484      */

485     protected AbstractFileSet getRef(Project p) {
486         return (AbstractFileSet) getCheckedRef(p);
487     }
488
489     // SelectorContainer methods
490

491     /**
492      * Indicates whether there are any selectors here.
493      *
494      * @return whether any selectors are in this container.
495      */

496     public synchronized boolean hasSelectors() {
497         return (isReference() && getProject() != null)
498             ? getRef(getProject()).hasSelectors() : !(selectors.isEmpty());
499     }
500
501     /**
502      * Indicates whether there are any patterns here.
503      *
504      * @return whether any patterns are in this container.
505      */

506     public synchronized boolean hasPatterns() {
507         if (isReference() && getProject() != null) {
508             return getRef(getProject()).hasPatterns();
509         }
510         if (defaultPatterns.hasPatterns(getProject())) {
511             return true;
512         }
513         Enumeration JavaDoc e = additionalPatterns.elements();
514         while (e.hasMoreElements()) {
515             PatternSet ps = (PatternSet) e.nextElement();
516             if (ps.hasPatterns(getProject())) {
517                 return true;
518             }
519         }
520         return false;
521     }
522
523     /**
524      * Gives the count of the number of selectors in this container.
525      *
526      * @return the number of selectors in this container as an <code>int</code>.
527      */

528     public synchronized int selectorCount() {
529         return (isReference() && getProject() != null)
530             ? getRef(getProject()).selectorCount() : selectors.size();
531     }
532
533     /**
534      * Returns the set of selectors as an array.
535      * @param p the current project
536      * @return a <code>FileSelector[]</code> of the selectors in this container.
537      */

538     public synchronized FileSelector[] getSelectors(Project p) {
539         return (isReference())
540             ? getRef(p).getSelectors(p) : (FileSelector[]) (selectors.toArray(
541             new FileSelector[selectors.size()]));
542     }
543
544     /**
545      * Returns an enumerator for accessing the set of selectors.
546      *
547      * @return an <code>Enumeration</code> of selectors.
548      */

549     public synchronized Enumeration JavaDoc selectorElements() {
550         return (isReference() && getProject() != null)
551             ? getRef(getProject()).selectorElements() : selectors.elements();
552     }
553
554     /**
555      * Add a new selector into this container.
556      *
557      * @param selector the new <code>FileSelector</code> to add.
558      */

559     public synchronized void appendSelector(FileSelector selector) {
560         if (isReference()) {
561             throw noChildrenAllowed();
562         }
563         selectors.addElement(selector);
564         directoryScanner = null;
565     }
566
567     /* Methods below all add specific selectors */
568
569     /**
570      * Add a "Select" selector entry on the selector list.
571      * @param selector the <code>SelectSelector</code> to add.
572      */

573     public void addSelector(SelectSelector selector) {
574         appendSelector(selector);
575     }
576
577     /**
578      * Add an "And" selector entry on the selector list.
579      * @param selector the <code>AndSelector</code> to add.
580      */

581     public void addAnd(AndSelector selector) {
582         appendSelector(selector);
583     }
584
585     /**
586      * Add an "Or" selector entry on the selector list.
587      * @param selector the <code>OrSelector</code> to add.
588      */

589     public void addOr(OrSelector selector) {
590         appendSelector(selector);
591     }
592
593     /**
594      * Add a "Not" selector entry on the selector list.
595      * @param selector the <code>NotSelector</code> to add.
596      */

597     public void addNot(NotSelector selector) {
598         appendSelector(selector);
599     }
600
601     /**
602      * Add a "None" selector entry on the selector list.
603      * @param selector the <code>NoneSelector</code> to add.
604      */

605     public void addNone(NoneSelector selector) {
606         appendSelector(selector);
607     }
608
609     /**
610      * Add a majority selector entry on the selector list.
611      * @param selector the <code>MajoritySelector</code> to add.
612      */

613     public void addMajority(MajoritySelector selector) {
614         appendSelector(selector);
615     }
616
617     /**
618      * Add a selector date entry on the selector list.
619      * @param selector the <code>DateSelector</code> to add.
620      */

621     public void addDate(DateSelector selector) {
622         appendSelector(selector);
623     }
624
625     /**
626      * Add a selector size entry on the selector list.
627      * @param selector the <code>SizeSelector</code> to add.
628      */

629     public void addSize(SizeSelector selector) {
630         appendSelector(selector);
631     }
632
633     /**
634      * Add a DifferentSelector entry on the selector list.
635      * @param selector the <code>DifferentSelector</code> to add.
636      */

637     public void addDifferent(DifferentSelector selector) {
638         appendSelector(selector);
639     }
640
641     /**
642      * Add a selector filename entry on the selector list.
643      * @param selector the <code>FilenameSelector</code> to add.
644      */

645     public void addFilename(FilenameSelector selector) {
646         appendSelector(selector);
647     }
648
649     /**
650      * Add a selector type entry on the selector list.
651      * @param selector the <code>TypeSelector</code> to add.
652      */

653     public void addType(TypeSelector selector) {
654         appendSelector(selector);
655     }
656
657     /**
658      * Add an extended selector entry on the selector list.
659      * @param selector the <code>ExtendSelector</code> to add.
660      */

661     public void addCustom(ExtendSelector selector) {
662         appendSelector(selector);
663     }
664
665     /**
666      * Add a contains selector entry on the selector list.
667      * @param selector the <code>ContainsSelector</code> to add.
668      */

669     public void addContains(ContainsSelector selector) {
670         appendSelector(selector);
671     }
672
673     /**
674      * Add a present selector entry on the selector list.
675      * @param selector the <code>PresentSelector</code> to add.
676      */

677     public void addPresent(PresentSelector selector) {
678         appendSelector(selector);
679     }
680
681     /**
682      * Add a depth selector entry on the selector list.
683      * @param selector the <code>DepthSelector</code> to add.
684      */

685     public void addDepth(DepthSelector selector) {
686         appendSelector(selector);
687     }
688
689     /**
690      * Add a depends selector entry on the selector list.
691      * @param selector the <code>DependSelector</code> to add.
692      */

693     public void addDepend(DependSelector selector) {
694         appendSelector(selector);
695     }
696
697     /**
698      * Add a regular expression selector entry on the selector list.
699      * @param selector the <code>ContainsRegexpSelector</code> to add.
700      */

701     public void addContainsRegexp(ContainsRegexpSelector selector) {
702         appendSelector(selector);
703     }
704
705     /**
706      * Add the modified selector.
707      * @param selector the <code>ModifiedSelector</code> to add.
708      * @since ant 1.6
709      */

710     public void addModified(ModifiedSelector selector) {
711         appendSelector(selector);
712     }
713
714     /**
715      * Add an arbitary selector.
716      * @param selector the <code>FileSelector</code> to add.
717      * @since Ant 1.6
718      */

719     public void add(FileSelector selector) {
720         appendSelector(selector);
721     }
722
723     /**
724      * Returns included files as a list of semicolon-separated filenames.
725      *
726      * @return a <code>String</code> of included filenames.
727      */

728     public String JavaDoc toString() {
729         DirectoryScanner ds = getDirectoryScanner(getProject());
730         String JavaDoc[] files = ds.getIncludedFiles();
731         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
732
733         for (int i = 0; i < files.length; i++) {
734             if (i > 0) {
735                 sb.append(';');
736             }
737             sb.append(files[i]);
738         }
739         return sb.toString();
740     }
741
742     /**
743      * Creates a deep clone of this instance, except for the nested
744      * selectors (the list of selectors is a shallow clone of this
745      * instance's list).
746      * @return the cloned object
747      * @since Ant 1.6
748      */

749     public synchronized Object JavaDoc clone() {
750         if (isReference()) {
751             return (getRef(getProject())).clone();
752         } else {
753             try {
754                 AbstractFileSet fs = (AbstractFileSet) super.clone();
755                 fs.defaultPatterns = (PatternSet) defaultPatterns.clone();
756                 fs.additionalPatterns = new Vector JavaDoc(additionalPatterns.size());
757                 Enumeration JavaDoc e = additionalPatterns.elements();
758                 while (e.hasMoreElements()) {
759                     fs.additionalPatterns
760                         .addElement(((PatternSet) e.nextElement()).clone());
761                 }
762                 fs.selectors = new Vector JavaDoc(selectors);
763                 return fs;
764             } catch (CloneNotSupportedException JavaDoc e) {
765                 throw new BuildException(e);
766             }
767         }
768     }
769
770     /**
771      * Get the merged include patterns for this AbstractFileSet.
772      * @param p the project to use.
773      * @return the include patterns of the default pattern set and all
774      * nested patternsets.
775      *
776      * @since Ant 1.7
777      */

778     public String JavaDoc[] mergeIncludes(Project p) {
779         return mergePatterns(p).getIncludePatterns(p);
780     }
781
782     /**
783      * Get the merged exclude patterns for this AbstractFileSet.
784      * @param p the project to use.
785      * @return the exclude patterns of the default pattern set and all
786      * nested patternsets.
787      *
788      * @since Ant 1.7
789      */

790     public String JavaDoc[] mergeExcludes(Project p) {
791         return mergePatterns(p).getExcludePatterns(p);
792     }
793
794     /**
795      * Get the merged patterns for this AbstractFileSet.
796      * @param p the project to use.
797      * @return the default patternset merged with the additional sets
798      * in a new PatternSet instance.
799      *
800      * @since Ant 1.7
801      */

802     public synchronized PatternSet mergePatterns(Project p) {
803         if (isReference()) {
804             return getRef(p).mergePatterns(p);
805         }
806         PatternSet ps = (PatternSet) defaultPatterns.clone();
807         final int count = additionalPatterns.size();
808         for (int i = 0; i < count; i++) {
809             Object JavaDoc o = additionalPatterns.elementAt(i);
810             ps.append((PatternSet) o, p);
811         }
812         return ps;
813     }
814
815 }
816
Popular Tags