diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index 6a8aed13c..588249c44 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -154,6 +154,21 @@ public final class JavaEnvUtils { return javaVersion.equals(version); } + /** + * Compares the current Java version to the passed in String - + * assumes the argument is one of the constants defined in this + * class. + * Note that Ant now requires JDK 1.2+ so {@link #JAVA_1_0} and + * {@link #JAVA_1_1} need no longer be tested for. + * @param version the version to check against the current version. + * @return true if the version of Java is the same or higher than the + * given version. + * @since Ant 1.7 + */ + public static boolean isAtLeastJavaVersion(String version) { + return javaVersion.compareTo(version) >= 0; + } + /** * Checks whether the current Java VM is Kaffe. * @return true if the current Java VM is Kaffe. diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java index 87208b782..8d43c7f9b 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.taskdefs.condition.Os; +import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.BuildFileTest; /** @@ -133,7 +134,7 @@ public class ManifestClassPathTest "../../resources/dsp-void/"); } public void testInternationalGerman() { - if (System.getProperty("java.vm.version").compareTo("1.4") < 0) + if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_4)) { System.out.println("Test with international characters skipped under pre 1.4 jvm."); return; @@ -143,8 +144,7 @@ public class ManifestClassPathTest } public void testInternationalHebrew() { - if (System.getProperty("java.vm.version").compareTo("1.4") < 0) - { + if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_4)) { System.out.println("Test with international characters skipped under pre 1.4 jvm."); return; } diff --git a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java index 4ee47ea77..2c25fc26b 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java @@ -127,4 +127,14 @@ public class JavaEnvUtilsTest extends TestCase { } + public void testIsAtLeastJavaVersion() + { + assertTrue( + "Current java version is not at least the current java version...", + JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.getJavaVersion())); + assertFalse( + "In case the current java version is higher than 9.0 definitely a new algorithem will be needed", + JavaEnvUtils.isAtLeastJavaVersion("9.0")); + } + }