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.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 class AntVersion implements Condition {
public void setExactly(String 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
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


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

@@ -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>
</project>

Loading…
Cancel
Save