diff --git a/WHATSNEW b/WHATSNEW index 1c6e28c48..15ab13410 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -6,6 +6,11 @@ Fixed bugs: * SCP (with sftp=true) task would fail if fetching file located in root directory Bugzilla Report 64742 +Other changes: +-------------- + + * javaversion condition now has a new "atmost" attribute. See the javaversion + manual for more details Changes from Ant 1.10.8 TO Ant 1.10.9 ===================================== diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html index 846733f58..247f2dd29 100644 --- a/manual/Tasks/conditions.html +++ b/manual/Tasks/conditions.html @@ -945,11 +945,19 @@ are supported, the property attribute is redundant and will be ignore Required - atleast + atleast The version that this JVM is of at least. The format is major.minor.point. Starting with Java 9 really only the major number is determined. - Exactly one of the two + Exactly one of the three + + + atmost + The version that this JVM is of at most. The format + is major.minor.point. Starting with Java 9 really only the major number is + determined.
+ Since Ant 1.10.10 + exactly diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java b/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java index e121c3063..a2214950d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/JavaVersion.java @@ -23,10 +23,11 @@ import org.apache.tools.ant.util.JavaEnvUtils; /** * An Java version condition. - * @since Java 1.10.2 + * @since Ant 1.10.2 */ public class JavaVersion implements Condition { + private String atMost = null; private String atLeast = null; private String exactly = null; @@ -44,16 +45,19 @@ public class JavaVersion implements Condition { if (null != exactly) { return actual.isEqual(new DeweyDecimal(exactly)); } + if (atMost != null) { + return actual.isLessThanOrEqual(new DeweyDecimal(atMost)); + } //default return false; } private void validate() throws BuildException { - if (atLeast != null && exactly != null) { - throw new BuildException("Only one of atleast or exactly may be set."); + if (atLeast != null && exactly != null && atMost != null) { + throw new BuildException("Only one of atleast or atmost or exactly may be set."); } - if (null == atLeast && null == exactly) { - throw new BuildException("One of atleast or exactly must be set."); + if (null == atLeast && null == exactly && atMost == null) { + throw new BuildException("One of atleast or atmost or exactly must be set."); } if (atLeast != null) { try { @@ -64,6 +68,14 @@ public class JavaVersion implements Condition { "The 'atleast' attribute is not a Dewey Decimal eg 1.1.0 : " + atLeast); } + } else if (atMost != null) { + try { + new DeweyDecimal(atMost); //NOSONAR + } catch (NumberFormatException e) { + throw new BuildException( + "The 'atmost' attribute is not a Dewey Decimal eg 1.1.0 : " + + atMost); + } } else { try { // only created for side effect @@ -88,12 +100,32 @@ public class JavaVersion implements Condition { * Set the atleast attribute. * This is of the form major.minor.point. * For example 1.7.0. - * @param atLeast the version to check against. + * @param atLeast the version to set */ public void setAtLeast(String atLeast) { this.atLeast = atLeast; } + /** + * Get the atmost attribute. + * @return the atmost attribute. + * @since Ant 1.10.10 + */ + public String getAtMost() { + return atMost; + } + + /** + * Set the atmost attribute. + * This is of the form major.minor.point. + * For example 11.0.2 + * @param atMost the version to set + * @since Ant 1.10.10 + */ + public void setAtMost(String atMost) { + this.atMost = atMost; + } + /** * Get the exactly attribute. * @return the exactly attribute. diff --git a/src/tests/antunit/taskdefs/condition/javaversion-test.xml b/src/tests/antunit/taskdefs/condition/javaversion-test.xml index a5d9a2190..586cad0b7 100644 --- a/src/tests/antunit/taskdefs/condition/javaversion-test.xml +++ b/src/tests/antunit/taskdefs/condition/javaversion-test.xml @@ -25,6 +25,20 @@ + + + + + + + + + + + + + +