01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.types;
20:
21: import java.util.Iterator;
22:
23: import org.apache.tools.ant.types.resources.FileResourceIterator;
24:
25: /**
26: * Moved out of MatchingTask to make it a standalone object that could
27: * be referenced (by scripts for example).
28: *
29: */
30: public class FileSet extends AbstractFileSet implements
31: ResourceCollection {
32:
33: /**
34: * Constructor for FileSet.
35: */
36: public FileSet() {
37: super ();
38: }
39:
40: /**
41: * Constructor for FileSet, with FileSet to shallowly clone.
42: * @param fileset the fileset to clone
43: */
44: protected FileSet(FileSet fileset) {
45: super (fileset);
46: }
47:
48: /**
49: * Return a FileSet that has the same basedir and same patternsets
50: * as this one.
51: * @return the cloned fileset
52: */
53: public Object clone() {
54: if (isReference()) {
55: return ((FileSet) getRef(getProject())).clone();
56: } else {
57: return super .clone();
58: }
59: }
60:
61: /**
62: * Fulfill the ResourceCollection contract.
63: * @return an Iterator of Resources.
64: * @since Ant 1.7
65: */
66: public Iterator iterator() {
67: if (isReference()) {
68: return ((FileSet) getRef(getProject())).iterator();
69: }
70: return new FileResourceIterator(getDir(getProject()),
71: getDirectoryScanner(getProject()).getIncludedFiles());
72: }
73:
74: /**
75: * Fulfill the ResourceCollection contract.
76: * @return number of elements as int.
77: * @since Ant 1.7
78: */
79: public int size() {
80: if (isReference()) {
81: return ((FileSet) getRef(getProject())).size();
82: }
83: return getDirectoryScanner(getProject())
84: .getIncludedFilesCount();
85: }
86:
87: /**
88: * Always returns true.
89: * @return true indicating that all elements will be FileResources.
90: * @since Ant 1.7
91: */
92: public boolean isFilesystemOnly() {
93: return true;
94: }
95:
96: }
|