1 7 package org.jboss.ant.taskdefs; 8 9 import org.apache.tools.ant.Task; 10 import org.apache.tools.ant.BuildException; 11 import org.apache.tools.ant.DirectoryScanner; 12 import org.apache.tools.ant.taskdefs.Ant; 13 import org.apache.tools.ant.taskdefs.Property; 14 import org.apache.tools.ant.util.SourceFileScanner; 15 import org.apache.tools.ant.util.FlatFileNameMapper; 16 import org.apache.tools.ant.types.DirSet; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.io.File ; 21 22 23 28 public class AntCallOnDirectoryList extends Task 29 { 30 ArrayList list = new ArrayList (); 31 32 String targetToExecute; 33 34 String directoryProperty; 35 String versionNameProperty; 36 37 Ant ant = null; 38 39 public String getVersionNameProperty() 40 { 41 return versionNameProperty; 42 } 43 44 public void setVersionNameProperty(String versionNameProperty) 45 { 46 this.versionNameProperty = versionNameProperty; 47 } 48 49 public String getTargetToExecute() 50 { 51 return targetToExecute; 52 } 53 54 public void setTargetToExecute(String targetToExecute) 55 { 56 this.targetToExecute = targetToExecute; 57 } 58 59 public String getDirectoryProperty() 60 { 61 return directoryProperty; 62 } 63 64 public void setDirectoryProperty(String directoryProperty) 65 { 66 this.directoryProperty = directoryProperty; 67 } 68 69 70 public void init() 71 { 72 super.init(); 73 ant = (Ant) this.getProject().createTask("ant"); 74 ant.setAntfile(this.getProject().getProperty("ant.file")); 75 ant.setOwningTarget(getOwningTarget()); 76 ant.setTaskName(getTaskName()); 77 ant.setLocation(getLocation()); 78 ant.init(); 79 } 80 81 82 public void addDirSet(DirSet dirSet) 83 { 84 list.add(dirSet); 85 } 86 87 public void execute() throws BuildException 88 { 89 init(); 90 ant.setTarget(getTargetToExecute()); 91 Property parameterDirectory = ant.createProperty(); 92 parameterDirectory.setName(this.getDirectoryProperty()); 93 94 Property parameterName = ant.createProperty(); 95 parameterName.setName(this.getVersionNameProperty()); 96 97 98 Iterator iter = list.iterator(); 99 while (iter.hasNext()) 100 { 101 DirSet dirSet = (DirSet) iter.next(); 102 File currentDir = dirSet.getDir(this.getProject()); 103 DirectoryScanner scanner = dirSet.getDirectoryScanner(this.getProject()); 104 105 SourceFileScanner sourceScanner = new SourceFileScanner(this); 106 String [] strfiles = scanner.getIncludedDirectories(); 107 ArrayList files = new ArrayList (); 108 for (int i = 0; i < strfiles.length; i++) 109 { 110 File currentFile = new File (currentDir, strfiles[i]); 111 if (currentFile.getParentFile().getAbsolutePath().equals(currentDir.getAbsolutePath())) 112 { 113 files.add(currentFile); 114 parameterDirectory.setValue(currentFile.getAbsolutePath()); 115 parameterName.setValue(currentFile.getName()); 116 ant.execute(); 117 } 118 } 119 120 } 121 } 122 } 123 | Popular Tags |