1 18 package org.apache.tools.ant.taskdefs.condition; 19 import org.apache.tools.ant.BuildException; 20 import org.apache.tools.ant.util.FileUtils; 21 import java.io.File ; 22 import org.apache.tools.ant.types.selectors.FileSelector; 23 import org.apache.tools.ant.types.selectors.AbstractSelectorContainer; 24 25 28 public class IsFileSelected extends AbstractSelectorContainer implements Condition { 29 30 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 31 32 private File file; 33 private File baseDir; 34 35 39 public void setFile(File file) { 40 this.file = file; 41 } 42 43 48 public void setBaseDir(File baseDir) { 49 this.baseDir = baseDir; 50 } 51 52 55 public void validate() { 56 if (selectorCount() != 1) { 57 throw new BuildException("Only one selector allowed"); 58 } 59 super.validate(); 60 } 61 62 66 public boolean eval() { 67 if (file == null) { 68 throw new BuildException("file attribute not set"); 69 } 70 validate(); 71 File myBaseDir = baseDir; 72 if (myBaseDir == null) { 73 myBaseDir = getProject().getBaseDir(); 74 } 75 76 FileSelector f = getSelectors(getProject())[0]; 77 return f.isSelected( 78 myBaseDir, FILE_UTILS.removeLeadingPath(myBaseDir, file), file); 79 } 80 } 81 | Popular Tags |