1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import java.io.File ; 32 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.Project; 35 import org.apache.tools.ant.types.Path; 36 import org.apache.tools.ant.types.Reference; 37 38 import com.idaremedia.antx.AntX; 39 import com.idaremedia.antx.ExportedProperties; 40 import com.idaremedia.antx.FlexString; 41 import com.idaremedia.antx.NoiseLevel; 42 import com.idaremedia.antx.condition.ShortHandConditions; 43 import com.idaremedia.antx.parameters.Handling; 44 import com.idaremedia.antx.parameters.IsA; 45 46 91 92 public class PreferTask extends RuleTask implements ShortHandConditions 93 { 94 97 public PreferTask() 98 { 99 super(AntX.rules+"prefer"); 100 } 101 102 103 107 public PreferTask(String iam) 108 { 109 super(iam); 110 } 111 112 113 118 protected PreferTask(String iam, boolean embedded) 119 { 120 super(iam, embedded); 121 } 122 123 124 128 public void setProject(Project project) 129 { 130 super.setProject(project); 131 m_shh.setProject(project); 132 } 133 134 135 139 143 public final void setFalseProperty(String propertyName) 144 { 145 setUpdateProperty(propertyName); 146 } 147 148 149 153 public final String getFalseProperty() 154 { 155 return getUpdateProperty(); 156 } 157 158 159 164 public final void setFalseVariable(String variable) 165 { 166 setUpdateVariable(variable); 167 } 168 169 170 173 public final void setFalseVar(String variable) 174 { 175 setFalseVariable(variable); 176 } 177 178 179 183 public final String getFalseVariable() 184 { 185 return getUpdateVariable(); 186 } 187 188 189 194 public final void setDefault(String value) 195 { 196 setUpdatePropertyValue(value); 197 } 198 199 200 206 public final void setDefaultProperty(String property) 207 { 208 require_(property!=null && property.length()>0,"setDfltProp- nonwspc name"); 209 checkModify("setDfltProp"); 210 211 FlexString upv = getUpdatePropertyFlexValue(); 212 upv.set(property); 213 upv.setIsProperty(true); 214 } 215 216 217 222 public final String getDefault() 223 { 224 return getUpdatePropertyValue(); 225 } 226 227 228 236 public final void setRuleId(Reference ruleId) 237 { 238 setReferralReference(ruleId); 239 } 240 241 242 246 251 protected boolean isIncompatibleReferral(ShareableCondition rule) 252 { 253 NoiseLevel effect = rule.getFailureEffect(); 254 if (effect==null || effect.isAsBadAs(NoiseLevel.ERROR)) { 255 return true; 256 } 257 return false; 258 } 259 260 261 266 public NoiseLevel getPreferredMsgLevel() 267 { 268 return BooleanRule.getPreferenceMsgLevel(getProject()); 269 } 270 271 272 279 protected void setEvalResult(boolean istrue, final String listing) 280 { 281 if (!istrue) { 282 String msg = getMsg(newMsgGetter(listing)); 283 if (msg.length()>0) { 284 log(msg, getPreferredMsgLevel().getNativeIndex()); 285 } 286 287 boolean told = false; 288 String what = getUpdatePropertyValue(); 289 String prop = getUpdateProperty(); 290 291 if (prop!=null) { 292 log("Prefer condition false; setting '"+prop+ 293 "' property to "+what, Project.MSG_DEBUG); 294 295 getProject().setInheritedProperty(prop, what); 296 told=true; 297 298 } 299 prop = getUpdateVariable(); 300 if (prop!=null) { 301 log("Prefer condition false; setting '"+prop+ 302 "' variable to "+what, Project.MSG_DEBUG); 303 304 ExportedProperties.set(prop,what); 305 told=true; 306 } 307 308 if (!told) { 309 log("Prefer condition false; logged '"+msg+"'", 310 Project.MSG_DEBUG); 311 } 312 } else { 313 log("Prefer condition true so ignored", Project.MSG_DEBUG); 314 } 315 } 316 317 318 323 public boolean eval() throws BuildException 324 { 325 if (runReferral()) { 326 return getReferral().eval(new Referee()); 327 } 328 329 verifyCanExecute_("eval"); 330 331 return defaultSingleConditionEval(); 332 } 333 334 335 339 343 public void setIsTrue(String value) 344 { 345 m_shh.setIsTrue(value); 346 } 347 348 349 353 public void setIsFalse(String value) 354 { 355 m_shh.setIsFalse(value); 356 } 357 358 359 363 public void setIsSet(String property) 364 { 365 m_shh.setIsSet(property); 366 } 367 368 369 374 public void setIsSetTrue(String property) 375 { 376 m_shh.setIsSetTrue(property); 377 } 378 379 380 384 public void setIsNotSet(String property) 385 { 386 m_shh.setIsNotSet(property); 387 } 388 389 390 395 public void setIsA(IsA isa) 396 { 397 m_shh.setIsA(isa); 398 } 399 400 401 406 public void setVarSet(String variable) 407 { 408 m_shh.setVarSet(variable); 409 } 410 411 412 416 public void setVarNotSet(String variable) 417 { 418 m_shh.setVarNotSet(variable); 419 } 420 421 422 427 public void setVarSetTrue(String variable) 428 { 429 m_shh.setVarSetTrue(variable); 430 } 431 432 433 438 public void setAnySet(String properties) 439 { 440 m_shh.setAnySet(properties); 441 } 442 443 444 449 public void setAllSet(String properties) 450 { 451 m_shh.setAllSet(properties); 452 } 453 454 455 461 public void setNoneSet(String properties) 462 { 463 m_shh.setNoneSet(properties); 464 } 465 466 468 473 public void setIsBoolean(String value) 474 { 475 m_shh.setIsBoolean(value); 476 } 477 478 479 483 public void setIsNumeric(String value) 484 { 485 m_shh.setIsNumeric(value); 486 } 487 488 489 494 public void setIsFile(File file) 495 { 496 m_shh.setIsFile(file); 497 } 498 499 500 503 public void setIsDirectory(File directory) 504 { 505 m_shh.setIsDirectory(directory); 506 } 507 508 509 515 public void setIsResource(String resource) 516 { 517 m_shh.setIsResource(resource); 518 } 519 520 521 526 public void setIsClass(String classname) 527 { 528 m_shh.setIsClass(classname); 529 } 530 531 532 537 public void setClasspath(Path clsp) 538 { 539 m_shh.setClasspath(clsp); 540 } 541 542 543 548 public void setFilepath(Path filp) 549 { 550 m_shh.setFilepath(filp); 551 } 552 553 554 559 public void setClasspathRef(Reference cpr) 560 { 561 m_shh.setClasspathRef(cpr); 562 } 563 564 565 572 public void setSystemClasses(boolean included) 573 { 574 m_shh.setSystemClasses(included); 575 } 576 577 579 584 public void setHttpAlive(String url) 585 { 586 m_shh.setHttpAlive(url); 587 } 588 589 590 594 public void setOSFamily(String family) 595 { 596 m_shh.setOSFamily(family); 597 } 598 599 600 public void setOS(String selector) 601 { 602 m_shh.setOS(selector); 603 } 604 605 606 608 614 public void setIsNotWhitespace(String value) 615 { 616 m_shh.setIsNotWhitespace(value); 617 } 618 619 620 626 public void setMatches(String pattern) 627 { 628 m_shh.setMatches(pattern); 629 } 630 631 632 637 public void setValue(String value) 638 { 639 m_shh.setValue(value); 640 } 641 642 643 650 public void setVariable(String variable) 651 { 652 m_shh.setVariable(variable); 653 } 654 655 656 659 public final void setVar(String variable) 660 { 661 setVariable(variable); 662 } 663 664 665 671 public void setProperty(String property) 672 { 673 m_shh.setProperty(property); 674 } 675 676 677 683 public void setReference(String refid) 684 { 685 m_shh.setReference(refid); 686 } 687 688 689 691 695 public void setIgnoreCase(boolean ignore) 696 { 697 m_shh.setIgnoreCase(ignore); 698 } 699 700 701 706 public boolean isIgnoreCase() 707 { 708 return m_shh.isIgnoreCase(); 709 } 710 711 712 716 public void setTrim(boolean trim) 717 { 718 m_shh.setTrim(trim); 719 } 720 721 722 727 public boolean willTrim() 728 { 729 return m_shh.willTrim(); 730 } 731 732 733 738 public void setWhitespace(Handling response) 739 { 740 m_shh.setWhitespace(response); 741 } 742 743 744 749 public boolean ignoreWhitespace() 750 { 751 return m_shh.ignoreWhitespace(); 752 } 753 754 755 760 public void setSynonyms(boolean allowAll) 761 { 762 m_shh.setSynonyms(allowAll); 763 } 764 765 766 771 public void setMalformed(Handling response) 772 { 773 m_shh.setMalformed(response); 774 } 775 776 777 782 public Handling getMalformedHandling() 783 { 784 return m_shh.getMalformedHandling(); 785 } 786 787 788 794 public final void setCheckBadSubst(boolean check) 795 { 796 log(uistrs().get("cv.deprecated", getTaskName(), 797 "checkbadsubst"), Project.MSG_WARN); 798 m_shh.setMalformed(check ? Handling.REJECT : Handling.ACCEPT); 799 } 800 801 802 804 private final ShortHandHelper m_shh = new ShortHandHelper(this); 805 } 806 807 808 | Popular Tags |