KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > ant > types > CompositeFileset


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant.ant.types;
8
9
10 import java.io.File JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14
15 import org.apache.tools.ant.BuildException;
16 import org.apache.tools.ant.DirectoryScanner;
17 import org.apache.tools.ant.Project;
18 import org.apache.tools.ant.types.FileSet;
19 import org.apache.tools.ant.types.Resource;
20 import org.apache.tools.ant.types.selectors.FileSelector;
21 import org.apache.tools.ant.util.FileUtils;
22
23
24 /**
25  * <p>
26  * This class is a composite fileset for Ant 1.6.1 that allows
27  * filesets to be children of it.
28  * </p>
29  *
30  * @author Brian Pontarelli
31  */

32 public class CompositeFileset extends FileSet {
33
34     List JavaDoc filesets = new ArrayList JavaDoc();
35
36
37     public CompositeFileset() {
38     }
39
40     protected CompositeFileset(FileSet fileSet) {
41         super(fileSet);
42     }
43
44
45     public void addFileset(FileSet fs) throws BuildException {
46         filesets.add(fs);
47     }
48
49     public DirectoryScanner getDirectoryScanner(Project p) {
50         return new CompositeDirectoryScanner(filesets, p);
51     }
52
53
54     public static class CompositeDirectoryScanner extends DirectoryScanner {
55
56         private List JavaDoc fileList = new ArrayList JavaDoc();
57
58
59         public CompositeDirectoryScanner(List JavaDoc filesets, Project p) {
60             Iterator JavaDoc iter = filesets.iterator();
61             FileSet fs;
62             DirectoryScanner ds;
63             String JavaDoc[] files;
64             File JavaDoc dir;
65             while (iter.hasNext()) {
66                 fs = (FileSet) iter.next();
67                 ds = fs.getDirectoryScanner(p);
68
69                 files = ds.getIncludedFiles();
70                 dir = ds.getBasedir();
71                 for (int i = 0; i < files.length; i++) {
72                     fileList.add(dir.getAbsolutePath() + File.separator + files[i]);
73                     p.log("Added file: " + dir.getAbsolutePath() + File.separator +
74                         files[i], Project.MSG_DEBUG);
75                 }
76             }
77         }
78
79
80         /** Everything is absolute */
81         public File JavaDoc getBasedir() {
82             File JavaDoc here = new File JavaDoc(".");
83             File JavaDoc parent = null;
84             while (here.getParentFile() != null) {
85                 parent = here.getParentFile();
86             }
87
88             return parent;
89         }
90
91         public void setBasedir(String JavaDoc basedir) {
92             // No-op
93
}
94
95         public void setBasedir(File JavaDoc basedir) {
96             // No-op
97
}
98
99         public boolean isCaseSensitive() {
100             return true;
101         }
102
103         public void setCaseSensitive(boolean isCaseSensitive) {
104             // No-op
105
}
106
107         public boolean isFollowSymlinks() {
108             return true;
109         }
110
111         public void setFollowSymlinks(boolean followSymlinks) {
112             // No-op
113
}
114
115         public void setIncludes(String JavaDoc[] includes) {
116             // No-op
117
}
118
119         public void setExcludes(String JavaDoc[] excludes) {
120             // No-op
121
}
122
123         public void setSelectors(FileSelector[] selectors) {
124             // No-op
125
}
126
127         public boolean isEverythingIncluded() {
128             return true;
129         }
130
131         protected boolean isIncluded(String JavaDoc name) {
132             return fileList.contains(name);
133         }
134
135         protected boolean isExcluded(String JavaDoc name) {
136             return !fileList.contains(name);
137         }
138
139         protected boolean isSelected(String JavaDoc name, File JavaDoc file) {
140             return false;
141         }
142
143         public String JavaDoc[] getIncludedFiles() {
144             return (String JavaDoc[]) fileList.toArray(new String JavaDoc[fileList.size()]);
145         }
146
147         public String JavaDoc[] getNotIncludedFiles() {
148             return new String JavaDoc[0];
149         }
150
151         public String JavaDoc[] getExcludedFiles() {
152             return new String JavaDoc[0];
153         }
154
155         public String JavaDoc[] getDeselectedFiles() {
156             return new String JavaDoc[0];
157         }
158
159         public String JavaDoc[] getIncludedDirectories() {
160             return new String JavaDoc[0];
161         }
162
163         public String JavaDoc[] getNotIncludedDirectories() {
164             return new String JavaDoc[0];
165         }
166
167         public String JavaDoc[] getExcludedDirectories() {
168             return new String JavaDoc[0];
169         }
170
171         public String JavaDoc[] getDeselectedDirectories() {
172             return new String JavaDoc[0];
173         }
174
175         public Resource getResource(String JavaDoc name) {
176             File JavaDoc f = FileUtils.newFileUtils().resolveFile(basedir, name);
177             return new Resource(name, f.exists(), f.lastModified(),
178                                 f.isDirectory());
179         }
180
181         public void addDefaultExcludes() {
182             // No-op
183
}
184
185         protected boolean couldHoldIncluded(String JavaDoc name) {
186             return false;
187         }
188
189         public void scan() throws IllegalStateException JavaDoc {
190             // No-op
191
}
192
193         protected void slowScan() {
194             // No-op
195
}
196
197         protected void scandir(File JavaDoc dir, String JavaDoc vpath, boolean fast) {
198             // No-op
199
}
200     }
201 }
Popular Tags