You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jh...@apache.org on 2006/12/21 14:16:52 UTC
svn commit: r489345 - in /ant/core/trunk/src:
main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
main/org/apache/tools/ant/taskdefs/defaults.properties
tests/antunit/taskdefs/condition/antversion-test.xml
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: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r489345 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/condition/AntVersion.java main/org/apache/tools/ant/taskdefs/defaults.properties tests/antunit/taskdefs/condition/antversion-test.xml
Posted by Peter Reilly <pe...@gmail.com>.
It is not confusing?
<antversion atleast="2.0.0" property="it.is"/>
would be valid.
I would like:
<antversion property=".."/> - sets the proeprti
<antversion atleast="2.0.0"/> - throws a build error
<antversion atleast="1.7.0"/> - does not throw a build error
<antversion atleast="2.0.0" property=".."/> - does not set the property,
does not throw
<antversion atleast="1.7.0" property=".."/> - sets the property
Peter
On 12/21/06, jhm@apache.org <jh...@apache.org> wrote:
> 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: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org