1 18 package org.apache.tools.ant.taskdefs.condition; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.util.FileUtils; 24 25 31 32 public class FilesMatch implements Condition { 33 34 37 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 38 39 42 private File file1, file2; 43 44 private boolean textfile = false; 45 46 47 52 public void setFile1(File file1) { 53 this.file1 = file1; 54 } 55 56 57 62 public void setFile2(File file2) { 63 this.file2 = file2; 64 } 65 66 70 public void setTextfile(boolean textfile) { 71 this.textfile = textfile; 72 } 73 74 80 public boolean eval() 81 throws BuildException { 82 83 if (file1 == null || file2 == null) { 85 throw new BuildException("both file1 and file2 are required in " 86 + "filesmatch"); 87 } 88 89 boolean matches = false; 91 try { 92 matches = FILE_UTILS.contentEquals(file1, file2, textfile); 93 } catch (IOException ioe) { 94 throw new BuildException("when comparing files: " 95 + ioe.getMessage(), ioe); 96 } 97 return matches; 98 } 99 } 100 101 | Popular Tags |