01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package net.sf.cglib.transform;
17:
18: import java.io.File;
19: import java.util.*;
20: import org.apache.tools.ant.BuildException;
21: import org.apache.tools.ant.DirectoryScanner;
22: import org.apache.tools.ant.Project;
23: import org.apache.tools.ant.Task;
24: import org.apache.tools.ant.types.FileSet;
25:
26: abstract public class AbstractProcessTask extends Task {
27: private Vector filesets = new Vector();
28:
29: public void addFileset(FileSet set) {
30: filesets.addElement(set);
31: }
32:
33: protected Collection getFiles() {
34: Map fileMap = new HashMap();
35: Project p = getProject();
36: for (int i = 0; i < filesets.size(); i++) {
37: FileSet fs = (FileSet) filesets.elementAt(i);
38: DirectoryScanner ds = fs.getDirectoryScanner(p);
39: String[] srcFiles = ds.getIncludedFiles();
40: File dir = fs.getDir(p);
41: for (int j = 0; j < srcFiles.length; j++) {
42: File src = new File(dir, srcFiles[j]);
43: fileMap.put(src.getAbsolutePath(), src);
44: }
45: }
46: return fileMap.values();
47: }
48:
49: public void execute() throws BuildException {
50: beforeExecute();
51: for (Iterator it = getFiles().iterator(); it.hasNext();) {
52: try {
53: processFile((File) it.next());
54: } catch (Exception e) {
55: throw new BuildException(e);
56: }
57: }
58: }
59:
60: protected void beforeExecute() throws BuildException {
61: }
62:
63: abstract protected void processFile(File file) throws Exception;
64: }
|