1 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 50 51 public void execute() throws BuildException { 52 beforeExecute(); 53 for (Iterator it = getFiles().iterator(); it.hasNext();) { 54 try { 55 processFile((File )it.next()); 56 } catch (Exception e) { 57 throw new BuildException(e); 58 } 59 } 60 } 61 62 protected void beforeExecute() throws BuildException { } 63 abstract protected void processFile(File file) throws Exception ; 64 } 65 | Popular Tags |