1 54 55 package org.apache.tools.ant.taskdefs; 56 57 58 import org.apache.tools.ant.Task; 59 import org.apache.tools.ant.BuildException; 60 import org.apache.tools.ant.types.Path; 61 import org.apache.tools.ant.DirectoryScanner; 62 63 import java.util.Vector ; 64 import java.util.Iterator ; 65 import java.io.File ; 66 67 public class Find extends Task { 68 69 71 private Vector foundFiles = new Vector (); 72 73 75 private String file; 76 private String location; 77 private Vector paths = new Vector (); 78 private String delimiter = null; 79 80 public void setFile(String file) { 81 this.file = file; 82 } 83 84 public void setLocation(String location) { 85 this.location = location; 86 } 87 88 public void addPath(Path path) { 89 paths.add(path); 90 } 91 92 public void setDelimiter(String delim) { 93 delimiter = delim; 94 } 95 96 98 protected void validate() { 99 if (file==null) throw new BuildException("file not set"); 100 if (location==null) throw new BuildException("location not set"); 101 if (paths.size()<1) throw new BuildException("path not set"); 102 } 103 104 public void execute() { 105 validate(); 106 for(Iterator itPaths = paths.iterator(); itPaths.hasNext(); ) { 108 Path path = (Path)itPaths.next(); 109 String [] includedFiles = path.list(); 110 for(int i=0; i<includedFiles.length; i++) { 111 String filename = includedFiles[i].replace('\\','/'); 112 filename = filename.substring(filename.lastIndexOf("/")+1); 113 if (file.equals(filename) && !foundFiles.contains(includedFiles[i])) { 114 foundFiles.add(includedFiles[i]); 115 } 116 } 117 } 118 119 String rv = null; 121 if (foundFiles.size() > 0) { 122 if (delimiter==null) { 123 rv = (String )foundFiles.elementAt(0); 125 } else { 126 StringBuffer list = new StringBuffer (); 128 for(Iterator it=foundFiles.iterator(); it.hasNext(); ) { 129 list.append(it.next()); 130 if (it.hasNext()) list.append(delimiter); 131 } 132 rv = list.toString(); 133 } 134 } 135 136 if (rv!=null) 138 getProject().setNewProperty(location, rv); 139 } 140 141 } | Popular Tags |