1 18 package org.apache.tools.ant.taskdefs.condition; 19 20 import java.io.IOException ; 21 import java.util.Iterator ; 22 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.types.Resource; 25 import org.apache.tools.ant.types.ResourceCollection; 26 import org.apache.tools.ant.types.resources.Union; 27 import org.apache.tools.ant.util.ResourceUtils; 28 29 37 public class ResourcesMatch implements Condition { 38 39 private Union resources = null; 40 private boolean asText = false; 41 42 47 public void setAsText(boolean asText) { 48 this.asText = asText; 49 } 50 51 55 public void add(ResourceCollection rc) { 56 if (rc == null) { 57 return; 58 } 59 resources = resources == null ? new Union() : resources; 60 resources.add(rc); 61 } 62 63 68 public boolean eval() throws BuildException { 69 if (resources == null) { 70 throw new BuildException( 71 "You must specify one or more nested resource collections"); 72 } 73 if (resources.size() > 1) { 74 Iterator i = resources.iterator(); 75 Resource r1 = (Resource) i.next(); 76 Resource r2 = null; 77 78 while (i.hasNext()) { 79 r2 = (Resource) i.next(); 80 try { 81 if (!ResourceUtils.contentEquals(r1, r2, asText)) { 82 return false; 83 } 84 } catch (IOException ioe) { 85 throw new BuildException("when comparing resources " 86 + r1.toString() + " and " + r2.toString(), ioe); 87 } 88 r1 = r2; 89 } 90 } 91 return true; 92 } 93 } 94 | Popular Tags |