1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import java.util.Iterator ; 32 import java.util.Stack ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.Task; 37 38 import com.idaremedia.antx.AntX; 39 import com.idaremedia.antx.ExportedProperties; 40 import com.idaremedia.antx.NoiseLevel; 41 import com.idaremedia.antx.apis.BuildAssertionException; 42 import com.idaremedia.antx.apis.Requester; 43 import com.idaremedia.antx.starters.StrictOuterTask; 44 45 155 156 public class BuildRule extends RuleType implements StrictOuterTask 157 { 158 161 public BuildRule() 162 { 163 super(AntX.rules); 164 } 165 166 167 171 public BuildRule(String iam) 172 { 173 super(iam); 174 } 175 176 177 181 185 public BooleanRule createRequire() 186 { 187 Requirement requirement = new Requirement(); 188 includeRule(requirement); 189 requirement.setEnclosingTask(this); 190 return requirement; 191 } 192 193 194 198 public BooleanRule createPrefer() 199 { 200 Preference preference = new Preference(); 201 includeRule(preference); 202 preference.setEnclosingTask(this); 203 return preference; 204 } 205 206 207 213 public BooleanRule createFixtureCheck() 214 { 215 return new VerifyFixture(true); 216 } 217 218 219 224 public NoiseLevel getFailureEffect() 225 { 226 return m_failureEffect; 227 } 228 229 230 237 private void includeRule(BooleanRule rule) 238 throws BuildException 239 { 240 boolean isRequire = (rule instanceof Requirement); 241 if (m_failureEffect!=null) { 242 checkAcceptable(this,isRequire,m_failureEffect); 243 } else if (isRequire) { 244 m_failureEffect = NoiseLevel.ERROR; 245 setStopQuickEvaluation(true); 246 } else { 247 m_failureEffect = NoiseLevel.WARNING; 248 setStopQuickEvaluation(false); 249 } 250 xaddCondition(rule); 251 } 252 253 254 260 static void checkAcceptable(Task from, boolean isRequire, 261 NoiseLevel failureEffect) 262 { 263 if ((isRequire && (!failureEffect.isAsBadAs(NoiseLevel.ERROR))) || 264 (!isRequire && (failureEffect.isAsBadAs(NoiseLevel.ERROR)))) { String id= from.getTaskName()!=null ? from.getTaskName() : "build-rules"; 266 String ermsg = AntX.uistrs().get("brul.only.onekind",id); 267 from.log(ermsg, Project.MSG_ERR); 268 throw new BuildException(ermsg, from.getLocation()); 269 } 270 } 271 272 276 284 public void verifyNoCircularDependency(Stack stk, Requester clnt) 285 { 286 if (!m_circularityChecked) { 287 if (!isEmpty()) { 288 Iterator itr= getConditions().iterator(); 289 if (clnt==null) { 290 clnt = new Requester.ForComponent(this); 291 } 292 while (itr.hasNext()) { 293 Stack itemstk = new Stack (); 294 itemstk.addAll(stk); 295 Object oc = itr.next(); 296 if (oc instanceof BooleanRule) { 297 ((BooleanRule)oc).verifyNoCircularDependency(itemstk, clnt); 298 } 299 itemstk.clear(); 300 } 301 } 302 m_circularityChecked = true; 303 } 304 } 305 306 307 308 313 public final boolean eval() 314 { 315 log(uistrs().get("brul.only.shareabl.apis"),Project.MSG_WARN); 317 return false; 318 } 319 320 321 322 329 protected void setEvalResult(boolean istrue, final String listing) 330 throws BuildException 331 { 332 boolean likePrefer= likePrefer(); 333 334 if (!istrue) { 335 String what = getUpdatePropertyValue(); 336 String prop; 337 338 prop = getUpdateProperty(); 339 if (prop!=null) { 340 if (likePrefer) { 341 getProject().setInheritedProperty(prop,what); 342 } else { 343 checkIfProperty_(prop,true); 344 getProject().setNewProperty(prop,what); 345 } 346 347 log("Build rule (preference="+likePrefer+") was false; have set '" 348 +prop+"' property to "+what, Project.MSG_DEBUG); 349 } 350 351 prop = getUpdateVariable(); 352 if (prop!=null) { 353 log("Build rule (preference="+likePrefer+") was false; setting '" 354 +prop+"' variable to "+what, Project.MSG_DEBUG); 355 356 ExportedProperties.set(prop,what); 357 } 358 359 String errmsg; 360 if (getMsgId()==null) { 361 errmsg = uistrs().get("brul.failed",getId(),listing); 362 } else { 363 errmsg = getMsg(newMsgGetter(getId(),listing)); 364 } 365 366 violationOccured(errmsg); 367 368 if (!likePrefer) { 369 throw new BuildAssertionException(errmsg, getLocation()); 370 } 371 } 372 } 373 374 375 381 protected void violationOccured(String ermsg) 382 { 383 if (ermsg==null) { 384 ermsg= uistrs().get("brul.failed.default"); 385 } 386 387 int noiselevel = getFailureEffect().isAsBadAs(NoiseLevel.ERROR) 388 ? Project.MSG_ERR 389 : BooleanRule.getPreferenceMsgLevel(getProject()).getNativeIndex(); 390 391 log(ermsg, noiselevel); 392 } 393 394 395 401 protected final boolean likePrefer() 402 { 403 return !isStopQuickEvaluation(); 404 } 405 406 407 private NoiseLevel m_failureEffect=null;} 410 411 412 | Popular Tags |