1 18 19 package org.apache.tools.ant.util; 20 21 import java.io.File ; 22 import java.util.Vector ; 23 import org.apache.tools.ant.Task; 24 import org.apache.tools.ant.types.Resource; 25 import org.apache.tools.ant.types.ResourceFactory; 26 import org.apache.tools.ant.types.resources.FileResource; 27 28 37 public class SourceFileScanner implements ResourceFactory { 38 39 protected Task task; 41 43 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 44 private File destDir; 46 50 public SourceFileScanner(Task task) { 51 this.task = task; 52 } 53 54 66 public String [] restrict(String [] files, File srcDir, File destDir, 67 FileNameMapper mapper) { 68 return restrict(files, srcDir, destDir, mapper, 69 FILE_UTILS.getFileTimestampGranularity()); 70 } 71 72 88 public String [] restrict(String [] files, File srcDir, File destDir, 89 FileNameMapper mapper, long granularity) { 90 this.destDir = destDir; 92 Vector v = new Vector (); 93 for (int i = 0; i < files.length; i++) { 94 File src = FILE_UTILS.resolveFile(srcDir, files[i]); 95 v.addElement(new Resource(files[i], src.exists(), 96 src.lastModified(), src.isDirectory())); 97 } 98 Resource[] sourceresources = new Resource[v.size()]; 99 v.copyInto(sourceresources); 100 101 Resource[] outofdate = 104 ResourceUtils.selectOutOfDateSources(task, sourceresources, 105 mapper, this, granularity); 106 String [] result = new String [outofdate.length]; 107 for (int counter = 0; counter < outofdate.length; counter++) { 108 result[counter] = outofdate[counter].getName(); 109 } 110 return result; 111 } 112 113 125 public File [] restrictAsFiles(String [] files, File srcDir, File destDir, 126 FileNameMapper mapper) { 127 return restrictAsFiles(files, srcDir, destDir, mapper, 128 FILE_UTILS.getFileTimestampGranularity()); 129 } 130 131 147 public File [] restrictAsFiles(String [] files, File srcDir, File destDir, 148 FileNameMapper mapper, long granularity) { 149 String [] res = restrict(files, srcDir, destDir, mapper, granularity); 150 File [] result = new File [res.length]; 151 for (int i = 0; i < res.length; i++) { 152 result[i] = new File (srcDir, res[i]); 153 } 154 return result; 155 } 156 157 164 public Resource getResource(String name) { 165 return new FileResource(destDir, name); 166 } 167 168 } 169 170 | Popular Tags |