KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > transform > AbstractProcessTask


1 /*
2  * Copyright 2003 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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 JavaDoc[] srcFiles = ds.getIncludedFiles();
40             File JavaDoc dir = fs.getDir(p);
41             for (int j = 0; j < srcFiles.length; j++) {
42                  File JavaDoc src = new File JavaDoc(dir, srcFiles[j]);
43                  fileMap.put(src.getAbsolutePath(), src);
44             }
45         }
46         return fileMap.values();
47     }
48
49     
50     
51     public void execute() throws BuildException {
52         beforeExecute();
53         for (Iterator it = getFiles().iterator(); it.hasNext();) {
54             try {
55                 processFile((File JavaDoc)it.next());
56             } catch (Exception JavaDoc e) {
57                  throw new BuildException(e);
58             }
59         }
60     }
61
62     protected void beforeExecute() throws BuildException { }
63     abstract protected void processFile(File JavaDoc file) throws Exception JavaDoc;
64 }
65
Popular Tags