| 1 package org.antmod.tasks; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 6 import org.apache.tools.ant.BuildException; 7 import org.apache.tools.ant.DirectoryScanner; 8 import org.apache.tools.ant.Project; 9 import org.apache.tools.ant.Task; 10 import org.apache.tools.ant.taskdefs.CallTarget; 11 import org.apache.tools.ant.types.FileSet; 12 13 21 public class FileIteratorTask extends Task { 22 private String target; 23 24 25 protected ArrayList fileSets = new ArrayList (); 26 27 28 31 public FileIteratorTask() { 32 } 33 34 37 public void setTarget(String target) { 38 this.target = target; 39 } 40 41 public void addFileSet(FileSet set) { 42 fileSets.add(set); 43 } 44 45 public void execute() throws BuildException { 46 int nrFileSets = fileSets.size(); 48 for (int i = 0; i < nrFileSets; i++) { 49 FileSet fileSet = (FileSet) fileSets.get(i); 50 runTarget(fileSet); 51 } 52 } 53 54 private void runTarget(FileSet fileSet) throws BuildException { 55 Project project = getProject(); 56 File dir = fileSet.getDir(project); 57 DirectoryScanner scanner = fileSet.getDirectoryScanner(project); 58 59 String [] files = scanner.getIncludedFiles(); 60 for (int i = 0; i < files.length; i++) { 61 String file = files[i]; 62 File fileObject = new File (dir, file); 63 64 CallTarget antcall = new CallTarget(); 65 antcall.setInheritAll(true); 66 antcall.setProject(getProject()); 67 antcall.setTaskName(getTaskName()); 68 antcall.setTarget(this.target); 69 ModuleIteratorTask.createInvokeParam(antcall, "antmod.fileiterator.file.name", fileObject.getName()); 70 ModuleIteratorTask.createInvokeParam(antcall, "antmod.fileiterator.file.path", fileObject.getPath()); 71 ModuleIteratorTask.createInvokeParam(antcall, "antmod.fileiterator.file.absolutepath", fileObject.getAbsolutePath()); 72 antcall.execute(); 73 } 74 } 75 } 76 | Popular Tags |