Author: jhm Date: Thu Dec 21 05:16:52 2006 New Revision: 489345 URL: http://svn.apache.org/viewvc?view=rev&rev=489345 Log: Make <antversion> available as Task.
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties ant/core/trunk/src/tests/antunit/taskdefs/condition/antversion-test.xml Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java?view=diff&rev=489345&r1=489344&r2=489345 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java Thu Dec 21 05:16:52 2006 @@ -20,25 +20,38 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; import org.apache.tools.ant.util.DeweyDecimal; /** * An Ant version condition. * @since Ant 1.7 */ -public class AntVersion implements Condition { +public class AntVersion extends Task implements Condition { private String atLeast = null; private String exactly = null; + private String propertyname = null; + /** * Evalute the condition. * @return true if the condition is true. * @throws BuildException if an error occurs. */ + public void execute() throws BuildException { + if (propertyname == null) { + throw new BuildException("'property' must be set."); + } + getProject().setNewProperty(propertyname, getVersion().toString()); + } + public boolean eval() throws BuildException { validate(); DeweyDecimal actual = getVersion(); + + System.out.println("AntVersion::actual = " + actual); + if (null != atLeast) { return actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast)); } @@ -123,4 +136,13 @@ public void setExactly(String exactly) { this.exactly = exactly; } + + public String getProperty() { + return propertyname; + } + + public void setProperty(String propertyname) { + this.propertyname = propertyname; + } + } Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties?view=diff&rev=489345&r1=489344&r2=489345 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties Thu Dec 21 05:16:52 2006 @@ -2,6 +2,7 @@ ant=org.apache.tools.ant.taskdefs.Ant antcall=org.apache.tools.ant.taskdefs.CallTarget antstructure=org.apache.tools.ant.taskdefs.AntStructure +antversion=org.apache.tools.ant.taskdefs.condition.AntVersion apply=org.apache.tools.ant.taskdefs.Transform available=org.apache.tools.ant.taskdefs.Available basename=org.apache.tools.ant.taskdefs.Basename Modified: ant/core/trunk/src/tests/antunit/taskdefs/condition/antversion-test.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/condition/antversion-test.xml?view=diff&rev=489345&r1=489344&r2=489345 ============================================================================== --- ant/core/trunk/src/tests/antunit/taskdefs/condition/antversion-test.xml (original) +++ ant/core/trunk/src/tests/antunit/taskdefs/condition/antversion-test.xml Thu Dec 21 05:16:52 2006 @@ -3,6 +3,7 @@ <target name="test-atleast"> <au:assertTrue> + <!-- AntVersion was introduced like AntUnit in 1.7 - so this must be true --> <antversion atleast="1.7.0"/> </au:assertTrue> </target> @@ -19,6 +20,11 @@ <antversion atleast="1.9.0"/> </au:assertFalse> </target> + + <target name="test-task"> + <antversion property="antversion"/> + <au:assertPropertyEquals name="antversion" value="1.7.1"/> + </target> <target name="all"> <au:antunit> @@ -27,4 +33,4 @@ </au:antunit> </target> -</project> \ No newline at end of file +</project> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]