1 11 12 package org.jivesoftware.ant; 13 14 import org.apache.tools.ant.Task; 15 import org.apache.tools.ant.BuildException; 16 import org.apache.tools.ant.Project; 17 18 import java.io.File ; 19 20 25 public class SubDirInfoTask extends Task { 26 27 public static final String DEFAULT_DELIM = ","; 28 29 private File dir; 30 private String property; 31 private String delimiter; 32 private String ifexists; 33 private String except; 34 35 public SubDirInfoTask() { 36 } 37 38 public File getDir() { 39 return dir; 40 } 41 42 public void setDir(File dir) { 43 this.dir = dir; 44 } 45 46 public String getProperty() { 47 return property; 48 } 49 50 public void setProperty(String property) { 51 this.property = property; 52 } 53 54 public String getDelimiter() { 55 if (delimiter == null) { 56 return DEFAULT_DELIM; 57 } 58 return delimiter; 59 } 60 61 public void setDelimiter(String delimiter) { 62 this.delimiter = delimiter; 63 } 64 65 public String getIfexists() { 66 return ifexists; 67 } 68 69 public void setIfexists(String ifexists) { 70 this.ifexists = ifexists; 71 } 72 73 public String getExcept() { 74 return except; 75 } 76 77 public void setExcept(String except) { 78 this.except = except; 79 } 80 81 public void execute() throws BuildException { 82 File [] subdirs = dir.listFiles(); 84 StringBuffer buf = new StringBuffer (); 85 String value = null; 86 String sep = ""; 87 if (subdirs != null) { 88 for (int i=0; i<subdirs.length; i++) { 89 File subdir = subdirs[i]; 90 boolean add = false; 91 if (subdir.isDirectory()) { 92 if (getIfexists() != null) { 93 File file = new File (subdir, getIfexists()); 94 if (file.exists()) { 95 add = true; 96 } 97 } 98 else { 99 add = true; 100 } 101 } 102 if (add && !subdir.getName().equals(except)) { 103 buf.append(sep).append(subdir.getName()); 104 sep = getDelimiter(); 105 } 106 } 107 } 108 if (buf.length() > 0) { 109 value = buf.toString(); 110 } 111 if (value == null) { 112 log("No tokens found.", Project.MSG_DEBUG); 113 } 114 else { 115 log("Setting property '" + property + "' to " + value, Project.MSG_DEBUG); 116 if (buf.length() >= 0) { 117 getProject().setProperty(property, value); 118 } 119 } 120 } 121 } 122 | Popular Tags |