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 import org.apache.tools.ant.Task; 34 35 import com.idaremedia.antx.FixtureOverlay; 36 import com.idaremedia.antx.ownhelpers.TaskExaminer; 37 import com.idaremedia.antx.parameters.RecoveryEnabled; 38 import com.idaremedia.antx.starters.StrictOuterTask; 39 import com.idaremedia.antx.starters.TaskSet; 40 41 52 53 public abstract class TolerantTaskSet extends TaskSet 54 implements StrictOuterTask, RecoveryEnabled, FixtureOverlay 55 { 56 59 protected TolerantTaskSet(String iam) 60 { 61 super(iam); 62 } 63 64 65 68 protected TolerantTaskSet(String iam, boolean delayConfiguration) 69 { 70 super(iam, delayConfiguration); 71 } 72 73 74 79 public void setHaltIfError(boolean balk) 80 { 81 m_haltIfError = balk; 82 } 83 84 85 89 public final boolean isHaltIfError() 90 { 91 return m_haltIfError; 92 } 93 94 95 102 public void setAgainstAll(boolean allRTX) 103 { 104 m_allRTX = allRTX; 105 } 106 107 108 109 115 public final boolean willCaptureAllRuntimeExceptions() 116 { 117 return m_allRTX; 118 } 119 120 121 122 126 protected void maybeConfigureSpecialTasks() 127 { 128 if (m_iferrorTask!=null) { 129 m_iferrorTask.maybeConfigure(); 130 } 131 if (m_alwaysTask!=null) { 132 m_alwaysTask.maybeConfigure(); 133 } 134 } 135 136 137 147 public void addTask(Task task) 148 { 149 require_(task!=null,"addTsk- nonzro task"); 150 151 task = TaskExaminer.trueTask(task,getCOI(),this); 153 if (!addSpecialTask(task)) { 154 super.addTask(task); 155 } else { 156 addedTask(); 157 } 158 } 159 160 161 169 protected boolean addSpecialTask(Task task) 170 { 171 boolean wasSpecial=true; 172 173 if (task instanceof IfErrorTask) { 174 addTheIfErrorTaskset((IfErrorTask)task); 175 } else if (task instanceof AlwaysTask) { 176 addTheAlwaysTaskset((AlwaysTask)task); 177 } else { 178 wasSpecial = false; 179 } 180 return wasSpecial; 181 } 182 183 184 191 protected void performNestedTasks() 192 { 193 try { 194 performTheProtectedTasksList(); 196 197 } catch(RuntimeException rtX) { 198 if (rtX instanceof BuildException && (rtX.getCause() instanceof Error )) { 200 throw (Error )rtX.getCause(); 201 } 202 203 if (!willCaptureAllRuntimeExceptions() && 205 !(rtX instanceof BuildException)) { 206 throw rtX; 207 } 208 209 RuntimeException rethrowX; 210 211 if (m_iferrorTask!=null) { 213 rethrowX = m_iferrorTask.throwOccured(rtX); 214 m_iferrorTask.perform(); 215 } else { 216 rethrowX = recordThrowOccured(rtX); 218 } 219 if (isHaltIfError()) { 221 if (rethrowX!=rtX) { 222 rethrowX.fillInStackTrace(); 223 } 224 throw rethrowX; 225 } 226 log("'"+getTaskName()+"' consuming build exception", 227 Project.MSG_VERBOSE); 228 } finally { 229 if (m_alwaysTask!=null) { 231 m_alwaysTask.perform(); 232 } 233 } 234 } 235 236 237 245 protected void performTheProtectedTasksList() 246 throws BuildException 247 { 248 performTheTasksList(); 249 } 250 251 252 253 257 protected final IfErrorTask getIfErrorTaskset() 258 { 259 return m_iferrorTask; 260 } 261 262 263 267 protected final AlwaysTask getAlwaysTaskset() 268 { 269 return m_alwaysTask; 270 } 271 272 273 276 protected final void addTheIfErrorTaskset(IfErrorTask task) 277 { 278 verifyIsUndefined_(m_iferrorTask, task); 279 task.setEnclosingTask(this); 280 m_iferrorTask = task; 281 if (task.getProject()==null) { 282 task.setProject(getProject()); 283 } 284 } 285 286 287 290 protected final void addTheAlwaysTaskset(AlwaysTask task) 291 { 292 verifyIsUndefined_(m_alwaysTask, task); 293 task.setEnclosingTask(this); 294 m_alwaysTask = task; 295 if (task.getProject()==null) { 296 task.setProject(getProject()); 297 } 298 } 299 300 301 306 private RuntimeException recordThrowOccured(RuntimeException rtX) 307 { 308 int loglevel = Project.MSG_ERR; 309 if (!isHaltIfError()) { 310 loglevel = Project.MSG_INFO; 311 } 312 log(uistrs().get("flow.caught.failure", 313 getOwningTarget().getName(), rtX.getMessage()), 314 loglevel); 315 return rtX; 316 } 317 318 319 320 private boolean m_haltIfError= true; private boolean m_allRTX; private IfErrorTask m_iferrorTask; 323 private AlwaysTask m_alwaysTask; 324 325 326 331 private static final Class [] COI_= { 332 IfErrorTask.class, AlwaysTask.class 333 }; 334 335 336 341 protected Class [] getCOI() 342 { 343 return COI_; 344 } 345 } 346 347 348 | Popular Tags |