1 28 29 package com.idaremedia.antx.condition; 30 31 import java.io.File ; 32 33 import org.apache.tools.ant.Project; 34 import org.apache.tools.ant.taskdefs.condition.Condition; 35 36 import com.idaremedia.antx.AntX; 37 import com.idaremedia.antx.AssertableProjectComponent; 38 import com.idaremedia.antx.helpers.Strings; 39 40 53 54 public class FileNotEmpty extends AssertableProjectComponent 55 implements Condition, URIable 56 { 57 60 public FileNotEmpty() 61 { 62 super(AntX.rules+"filenotempty"); 63 } 64 65 66 71 public FileNotEmpty(String path, Project P) 72 { 73 super(AntX.rules+"filenotempty"); 74 setProject(P); 75 setPath(path); 76 } 77 78 79 84 public FileNotEmpty(File file, Project P) 85 { 86 super(AntX.rules+"filenotempty"); 87 setProject(P); 88 setFile(file); 89 } 90 91 92 97 public void setPath(String path) 98 { 99 require_(path!=null,"setpath- nonzro"); 100 m_filepath = path; 101 } 102 103 104 108 public final String getPath() 109 { 110 return m_filepath; 111 } 112 113 114 120 public void setFile(File file) 121 { 122 require_(file!=null,"setfile- nonzro"); 123 m_file = file; 124 } 125 126 127 131 public final File getFile() 132 { 133 return m_file; 134 } 135 136 137 142 public void setTrueProperty(String property) 143 { 144 require_(property!=null,"setTrueProp- nonzro name"); 145 m_updateProperty = property; 146 } 147 148 149 154 public final String getTrueProperty() 155 { 156 return m_updateProperty; 157 } 158 159 160 164 public boolean eval() 165 { 166 if (getTrueProperty()!=null) { 167 verifyInProject_("eval"); 168 } 169 170 File thefile = getFile(); 171 172 if (thefile==null && getPath()==null) { 173 return false; 174 } 175 176 boolean istrue=false; 177 try { 178 if (thefile==null) { 179 if (getProject()!=null) { 180 thefile = getProject().resolveFile(getPath()); 181 } else { 182 thefile = new File (getPath()); 183 } 184 } 185 if (!thefile.isDirectory()) { 186 istrue = thefile.length()>0L; } 188 } catch (SecurityException secX) { 189 log(secX.getMessage(),Project.MSG_WARN); 190 } 191 192 if (istrue && getTrueProperty()!=null) { 193 String prop = getTrueProperty(); 194 log("FileNotEmpty was true; setting true-property '"+prop+ 195 "' property", Project.MSG_DEBUG); 196 getProject().setNewProperty(prop,Strings.TRUE); 197 } 198 199 return istrue; 200 } 201 202 203 204 209 public void xsetFromURI(String fragment) 210 { 211 setPath(fragment); 212 } 213 214 215 private String m_filepath; 216 private File m_file; 217 private String m_updateProperty; 218 } 219 220 221 | Popular Tags |