1 28 29 package com.idaremedia.antx.flowcontrol.wrap; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 34 import com.idaremedia.antx.AntX; 35 import com.idaremedia.antx.ErrorSnapshot; 36 import com.idaremedia.antx.ExportedProperties; 37 import com.idaremedia.antx.FixtureExaminer; 38 import com.idaremedia.antx.apis.BuildAssertionException; 39 import com.idaremedia.antx.ownhelpers.LocalTk; 40 import com.idaremedia.antx.parameters.PropertySource; 41 import com.idaremedia.antx.starters.StrictInnerTaskSet; 42 import com.idaremedia.antx.starters.Quiet; 43 44 60 61 public final class IfErrorTask extends StrictInnerTaskSet implements Quiet 62 { 63 66 public IfErrorTask() 67 { 68 super(AntX.flow+"protect"); 69 } 70 71 72 78 public void setFailProperty(String property) 79 { 80 require_(property!=null,"setFailProp- nonzro propnam"); 81 m_failProperty = property; 82 } 83 84 85 90 public final String getFailProperty() 91 { 92 return m_failProperty; 93 } 94 95 96 103 public void setFailVariable(String variable) 104 { 105 require_(variable!=null,"setFailVar- nonzro varnam"); 106 m_failVar = variable; 107 } 108 109 110 115 public final String getFailVariable() 116 { 117 return m_failVar; 118 } 119 120 121 126 public void setFailValue(String value) 127 { 128 require_(value!=null,"setfailV- nonzro valu"); 129 m_failValue = value; 130 } 131 132 133 138 public final String getFailValue() 139 { 140 return m_failValue; 141 } 142 143 144 150 public void setCaptureSnapshotRefId(String reference) 151 { 152 m_failSnapshotRefId= reference; 153 } 154 155 156 160 public final String getCaptureSnapshotRefId() 161 { 162 return m_failSnapshotRefId; 163 } 164 165 166 170 public final void setCaptureSnapshot(String newRefId) 171 { 172 setCaptureSnapshotRefId(newRefId); 173 } 174 175 176 181 public void setCaptureThrownRefId(String reference) 182 { 183 m_failThrownRefId = reference; 184 } 185 186 187 191 public final void setCaptureThrown(String thrownRefId) 192 { 193 setCaptureThrownRefId(thrownRefId); 194 } 195 196 197 201 public final String getCaptureThrownRefId() 202 { 203 return m_failThrownRefId; 204 } 205 206 207 217 public void setCapturePropertyNames(String namesList) 218 { 219 require_(namesList!=null,"setCapturPs- nonzro list"); 220 m_propertyNames= namesList; 221 } 222 223 224 229 public final String getCapturePropertyNames() 230 { 231 return m_propertyNames; 232 } 233 234 235 239 public final void setCaptureProperties(String namesList) 240 { 241 setCapturePropertyNames(namesList); 242 } 243 244 245 246 252 public void setConvertTo(String what) 253 { 254 require_(what!=null,"setCvtTo- nonzro target"); 255 m_convertTo= what; 256 } 257 258 259 260 266 public final void setQuiet(boolean quiet) 267 { 268 m_tellCaught = quiet ? Boolean.FALSE : Boolean.TRUE; 269 } 270 271 272 273 278 public final Boolean getQuietFlag() 279 { 280 return m_tellCaught; 281 } 282 283 284 290 final RuntimeException throwOccured(RuntimeException rtX) 291 { 292 final Project P= getProject(); 293 TolerantTaskSet wrt= (TolerantTaskSet)getEnclosingTask(); 294 295 if (tellCaught()) { 296 int loglevel = Project.MSG_ERR; 297 if (!wrt.isHaltIfError()) { 298 loglevel = Project.MSG_INFO; 299 } 300 log(uistrs().get("flow.caught.failure", 301 wrt.getOwningTarget().getName(), rtX.getMessage()), 302 loglevel); 303 } 304 305 String what= getFailValue(); 306 if (what==null) { 307 what= rtX.getMessage(); 308 } 309 310 if (getFailProperty()!=null) { 311 P.setNewProperty(getFailProperty(), what); 312 } 313 if (getFailVariable()!=null) { 314 ExportedProperties.set(getFailVariable(), what); 315 } 316 317 rtX = getPreferredX(rtX); 318 319 if (getCaptureThrownRefId()!=null) { 320 String refid= getCaptureThrownRefId(); 321 322 if (P.getReference(refid)!=null) { 323 log(uistrs().get("task.warn.refid.exists",refid),Project.MSG_WARN); 324 } 325 P.addReference(refid,rtX); 326 } 327 328 if (getCaptureSnapshotRefId()!=null) { 329 String refid = getCaptureSnapshotRefId(); 330 331 if (P.getReference(refid)!=null) { 332 log(uistrs().get("task.warn.refid.exists",refid),Project.MSG_WARN); 333 } 334 335 ErrorSnapshot es= new ErrorSnapshot(wrt, rtX); 336 es.setName(refid); 337 338 String nl= getCapturePropertyNames(); 339 if (nl!=null) { 340 PropertySource domain = PropertySource.from(nl); 341 if (domain!=null) { 342 es.captureProperties 343 (FixtureExaminer.copyOfProperties(domain,P)); 344 } else { 345 es.captureProperties(nl); 346 } 347 } 348 P.addReference(refid,es); 349 } 350 351 return rtX; 352 } 353 354 355 356 364 private RuntimeException getPreferredX(RuntimeException rtX) 365 { 366 if (m_convertTo!=null) { 367 if ("new".equals(m_convertTo)) { 368 rtX = new BuildException(rtX.getMessage(),rtX,getLocation()); 369 } 370 else 371 if ("assert".equals(m_convertTo)) { 372 if (!(rtX instanceof BuildAssertionException)) { 373 rtX = (RuntimeException )LocalTk.replaceError 374 (rtX, getLocation(), BuildAssertionException.class); 375 } 376 } 377 else { 378 rtX = (RuntimeException )LocalTk.replaceError 379 (rtX, getLocation(), m_convertTo); 380 } 381 } 382 return rtX; 383 } 384 385 386 387 private boolean tellCaught() 388 { 389 return m_tellCaught==null || m_tellCaught==Boolean.TRUE; 390 } 391 392 393 private String m_failProperty, m_failVar; 394 private String m_failValue; 395 private String m_failSnapshotRefId, m_failThrownRefId; 396 private String m_propertyNames; 397 private String m_convertTo; 398 private Boolean m_tellCaught;} 400 401 402 | Popular Tags |