Author: mbenson Date: Tue Jul 17 17:38:21 2007 New Revision: 557097 URL: http://svn.apache.org/viewvc?view=rev&rev=557097 Log: non-string properties
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java?view=diff&rev=557097&r1=557096&r2=557097 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Available.java Tue Jul 17 17:38:21 2007 @@ -22,6 +22,7 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.condition.Condition; import org.apache.tools.ant.types.EnumeratedAttribute; @@ -50,7 +51,7 @@ private FileDir type; private Path classpath; private AntClassLoader loader; - private String value = "true"; + private Object value = "true"; private boolean isTask = false; private boolean ignoreSystemclasses = false; private boolean searchParents = false; @@ -136,11 +137,21 @@ * * @param value the value to be given. */ - public void setValue(String value) { + public void setValue(Object value) { this.value = value; } /** + * Set the value to be given to the property if the desired resource is + * available. + * + * @param value the value to be given. + */ + public void setValue(String value) { + setValue((Object) value); + } + + /** * Set a classname of a class which must be available to set the given * property. * @@ -223,7 +234,8 @@ isTask = true; try { if (eval()) { - String oldvalue = getProject().getProperty(property); + PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject()); + Object oldvalue = ph.getProperty(property); if (null != oldvalue && !oldvalue.equals(value)) { log("DEPRECATED - <available> used to override an existing" + " property." @@ -234,7 +246,7 @@ } // NB: this makes use of Project#setProperty rather than Project#setNewProperty // due to backwards compatiblity reasons - getProject().setProperty(property, value); + ph.setProperty(property, value, true); } } finally { isTask = false; Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java?view=diff&rev=557097&r1=557096&r2=557097 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java Tue Jul 17 17:38:21 2007 @@ -15,11 +15,11 @@ * limitations under the License. * */ - package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; import org.apache.tools.ant.taskdefs.condition.Condition; import org.apache.tools.ant.taskdefs.condition.ConditionBase; @@ -40,8 +40,8 @@ public class ConditionTask extends ConditionBase { private String property = null; - private String value = "true"; - private String alternative = null; + private Object value = "true"; + private Object alternative = null; /** * Constructor, names this task "condition". @@ -62,11 +62,31 @@ /** * The value for the property to set, if condition evaluates to true. * Defaults to "true". + * @param v the (Object) value of the property + * @since Ant 1.8 + */ + public void setValue(Object value) { + this.value = value; + } + + /** + * The value for the property to set, if condition evaluates to true. + * Defaults to "true". * @param v the value of the property * @since Ant 1.4 */ public void setValue(String v) { - value = v; + setValue((Object) v); + } + + /** + * The value for the property to set, if condition evaluates to false. + * If this attribute is not specified, the property will not be set. + * @param e the alternate value of the property. + * @since Ant 1.8 + */ + public void setElse(Object alt) { + alternative = alt; } /** @@ -76,7 +96,7 @@ * @since Ant 1.6.3 */ public void setElse(String e) { - alternative = e; + setElse((Object) e); } /** @@ -87,29 +107,24 @@ */ public void execute() throws BuildException { if (countConditions() > 1) { - throw new BuildException("You must not nest more than one " - + "condition into <" - + getTaskName() + ">"); + throw new BuildException("You must not nest more than one condition into <" + + getTaskName() + ">"); } if (countConditions() < 1) { - throw new BuildException("You must nest a condition into <" - + getTaskName() + ">"); + throw new BuildException("You must nest a condition into <" + getTaskName() + ">"); } if (property == null) { throw new BuildException("The property attribute is required."); } Condition c = (Condition) getConditions().nextElement(); if (c.eval()) { - log("Condition true; setting " + property + " to " + value, - Project.MSG_DEBUG); - getProject().setNewProperty(property, value); + log("Condition true; setting " + property + " to " + value, Project.MSG_DEBUG); + PropertyHelper.getPropertyHelper(getProject()).setNewProperty(property, value); } else if (alternative != null) { - log("Condition false; setting " + property + " to " + alternative, - Project.MSG_DEBUG); - getProject().setNewProperty(property, alternative); + log("Condition false; setting " + property + " to " + alternative, Project.MSG_DEBUG); + PropertyHelper.getPropertyHelper(getProject()).setNewProperty(property, alternative); } else { - log("Condition false; not setting " + property, - Project.MSG_DEBUG); + log("Condition false; not setting " + property, Project.MSG_DEBUG); } } } Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java?view=diff&rev=557097&r1=557096&r2=557097 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java Tue Jul 17 17:38:21 2007 @@ -21,15 +21,27 @@ import org.apache.tools.ant.BuildException; /** - * Simple String comparison condition. + * Simple comparison condition. * * @since Ant 1.4 */ public class Equals implements Condition { + private static final int REQUIRED = 1 | 2; - private String arg1, arg2; + private Object arg1, arg2; private boolean trim = false; private boolean caseSensitive = true; + private int args; + + /** + * Set the first argument + * @param arg1 + * @since Ant 1.8 + */ + public void setArg1(Object arg1) { + this.arg1 = arg1; + args |= 1; + } /** * Set the first string @@ -37,7 +49,17 @@ * @param a1 the first string */ public void setArg1(String a1) { - arg1 = a1; + setArg1((Object) a1); + } + + /** + * Set the second argument + * @param arg2 + * @since Ant 1.8 + */ + public void setArg2(Object arg2) { + this.arg2 = arg2; + args |= 2; } /** @@ -46,7 +68,7 @@ * @param a2 the second string */ public void setArg2(String a2) { - arg2 = a2; + setArg2((Object) a2); } /** @@ -73,16 +95,19 @@ * @exception BuildException if the attributes are not set correctly */ public boolean eval() throws BuildException { - if (arg1 == null || arg2 == null) { - throw new BuildException("both arg1 and arg2 are required in " - + "equals"); + if ((args & REQUIRED) != REQUIRED) { + throw new BuildException("both arg1 and arg2 are required in equals"); } - if (trim) { - arg1 = arg1.trim(); - arg2 = arg2.trim(); + if (arg1 instanceof String && arg2 instanceof String) { + String s1 = (String) arg1; + String s2 = (String) arg2; + if (trim) { + s1 = s1.trim(); + s2 = s2.trim(); + } + return caseSensitive ? s1.equals(s2) : s1.equalsIgnoreCase(s2); } - - return caseSensitive ? arg1.equals(arg2) : arg1.equalsIgnoreCase(arg2); + return arg1 == arg2 || arg1 != null && arg1.equals(arg2); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]