1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Project; 23 import org.apache.tools.ant.taskdefs.condition.Condition; 24 import org.apache.tools.ant.taskdefs.condition.ConditionBase; 25 26 40 public class ConditionTask extends ConditionBase { 41 42 private String property = null; 43 private String value = "true"; 44 private String alternative = null; 45 46 49 public ConditionTask() { 50 super("condition"); 51 } 52 53 58 public void setProperty(String p) { 59 property = p; 60 } 61 62 68 public void setValue(String v) { 69 value = v; 70 } 71 72 78 public void setElse(String e) { 79 alternative = e; 80 } 81 82 88 public void execute() throws BuildException { 89 if (countConditions() > 1) { 90 throw new BuildException("You must not nest more than one " 91 + "condition into <" 92 + getTaskName() + ">"); 93 } 94 if (countConditions() < 1) { 95 throw new BuildException("You must nest a condition into <" 96 + getTaskName() + ">"); 97 } 98 if (property == null) { 99 throw new BuildException("The property attribute is required."); 100 } 101 Condition c = (Condition) getConditions().nextElement(); 102 if (c.eval()) { 103 log("Condition true; setting " + property + " to " + value, 104 Project.MSG_DEBUG); 105 getProject().setNewProperty(property, value); 106 } else if (alternative != null) { 107 log("Condition false; setting " + property + " to " + alternative, 108 Project.MSG_DEBUG); 109 getProject().setNewProperty(property, alternative); 110 } else { 111 log("Condition false; not setting " + property, 112 Project.MSG_DEBUG); 113 } 114 } 115 } 116 | Popular Tags |