Browse Source

Make <antversion> available as Task.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@489345 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 18 years ago
parent
commit
fefdb7bc0d
3 changed files with 31 additions and 2 deletions
  1. +23
    -1
      src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
  2. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/defaults.properties
  3. +7
    -1
      src/tests/antunit/taskdefs/condition/antversion-test.xml

+ 23
- 1
src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java View File

@@ -20,25 +20,38 @@ package org.apache.tools.ant.taskdefs.condition;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.DeweyDecimal; import org.apache.tools.ant.util.DeweyDecimal;


/** /**
* An Ant version condition. * An Ant version condition.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public class AntVersion implements Condition {
public class AntVersion extends Task implements Condition {


private String atLeast = null; private String atLeast = null;
private String exactly = null; private String exactly = null;
private String propertyname = null;


/** /**
* Evalute the condition. * Evalute the condition.
* @return true if the condition is true. * @return true if the condition is true.
* @throws BuildException if an error occurs. * @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 { public boolean eval() throws BuildException {
validate(); validate();
DeweyDecimal actual = getVersion(); DeweyDecimal actual = getVersion();
System.out.println("AntVersion::actual = " + actual);
if (null != atLeast) { if (null != atLeast) {
return actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast)); return actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast));
} }
@@ -123,4 +136,13 @@ public class AntVersion implements Condition {
public void setExactly(String exactly) { public void setExactly(String exactly) {
this.exactly = exactly; this.exactly = exactly;
} }

public String getProperty() {
return propertyname;
}

public void setProperty(String propertyname) {
this.propertyname = propertyname;
}

} }

+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/defaults.properties View File

@@ -2,6 +2,7 @@
ant=org.apache.tools.ant.taskdefs.Ant ant=org.apache.tools.ant.taskdefs.Ant
antcall=org.apache.tools.ant.taskdefs.CallTarget antcall=org.apache.tools.ant.taskdefs.CallTarget
antstructure=org.apache.tools.ant.taskdefs.AntStructure antstructure=org.apache.tools.ant.taskdefs.AntStructure
antversion=org.apache.tools.ant.taskdefs.condition.AntVersion
apply=org.apache.tools.ant.taskdefs.Transform apply=org.apache.tools.ant.taskdefs.Transform
available=org.apache.tools.ant.taskdefs.Available available=org.apache.tools.ant.taskdefs.Available
basename=org.apache.tools.ant.taskdefs.Basename basename=org.apache.tools.ant.taskdefs.Basename


+ 7
- 1
src/tests/antunit/taskdefs/condition/antversion-test.xml View File

@@ -3,6 +3,7 @@
<target name="test-atleast"> <target name="test-atleast">
<au:assertTrue> <au:assertTrue>
<!-- AntVersion was introduced like AntUnit in 1.7 - so this must be true -->
<antversion atleast="1.7.0"/> <antversion atleast="1.7.0"/>
</au:assertTrue> </au:assertTrue>
</target> </target>
@@ -19,6 +20,11 @@
<antversion atleast="1.9.0"/> <antversion atleast="1.9.0"/>
</au:assertFalse> </au:assertFalse>
</target> </target>
<target name="test-task">
<antversion property="antversion"/>
<au:assertPropertyEquals name="antversion" value="1.7.1"/>
</target>
<target name="all"> <target name="all">
<au:antunit> <au:antunit>
@@ -27,4 +33,4 @@
</au:antunit> </au:antunit>
</target> </target>
</project>
</project>

Loading…
Cancel
Save