Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-03-02 09:59:04 -0500
committerJoakim Erdfelt2015-03-02 09:59:11 -0500
commitc2b365a5236a91e4ffac259703a81f36a3c71a64 (patch)
tree343b9eac09b679abc5f3118439232f7379d01c8d
parent63deccb65bcaca18f8f18f8505ad44ff56842a60 (diff)
downloadorg.eclipse.jetty.toolchain-c2b365a5236a91e4ffac259703a81f36a3c71a64.tar.gz
org.eclipse.jetty.toolchain-c2b365a5236a91e4ffac259703a81f36a3c71a64.tar.xz
org.eclipse.jetty.toolchain-c2b365a5236a91e4ffac259703a81f36a3c71a64.zip
Adding JDK utility class
-rw-r--r--jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/JDK.java57
-rw-r--r--jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/JDKTest.java70
2 files changed, 127 insertions, 0 deletions
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/JDK.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/JDK.java
new file mode 100644
index 0000000..1ae48b2
--- /dev/null
+++ b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/JDK.java
@@ -0,0 +1,57 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.toolchain.test;
+
+public class JDK
+{
+ public static final boolean IS_5 = isJavaVersionAtLeast(1,5);
+ public static final boolean IS_6 = isJavaVersionAtLeast(1,6);
+ public static final boolean IS_7 = isJavaVersionAtLeast(1,7);
+ public static final boolean IS_8 = isJavaVersionAtLeast(1,8);
+ public static final boolean IS_9 = isJavaVersionAtLeast(1,9);
+
+ private static boolean isJavaVersionAtLeast(int maj, int min)
+ {
+ String jver = System.getProperty("java.version");
+ if (jver == null)
+ {
+ System.err.println("## ERROR: System.getProperty('java.version') == null !?");
+ return false;
+ }
+ String vparts[] = jver.split("\\.");
+ if (vparts.length < 2)
+ {
+ System.err.println("## ERROR: Invalid java version format '" + jver + "'");
+ return false;
+ }
+ return (toInt(vparts[0]) >= maj && toInt(vparts[1]) >= min);
+ }
+
+ private static int toInt(String val)
+ {
+ try
+ {
+ return Integer.parseInt(val);
+ }
+ catch (NumberFormatException e)
+ {
+ return 0;
+ }
+ }
+}
diff --git a/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/JDKTest.java b/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/JDKTest.java
new file mode 100644
index 0000000..9a0a15d
--- /dev/null
+++ b/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/JDKTest.java
@@ -0,0 +1,70 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.toolchain.test;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class JDKTest
+{
+ @Test
+ public void testJdk()
+ {
+ // Running version of Java
+ String ver = System.getProperty("java.version");
+ if (ver.startsWith("1.5."))
+ {
+ System.err.println("Testing JDK.IS_5 - " + ver);
+ assertThat("JVM(" + ver + ") / JDK.IS_5",JDK.IS_5,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_6",JDK.IS_6,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_7",JDK.IS_7,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_8",JDK.IS_8,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_9",JDK.IS_9,is(false));
+ }
+ else if (ver.startsWith("1.6."))
+ {
+ System.err.println("Testing JDK.IS_6 - " + ver);
+ assertThat("JVM(" + ver + ") / JDK.IS_5",JDK.IS_5,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_6",JDK.IS_6,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_7",JDK.IS_7,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_8",JDK.IS_8,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_9",JDK.IS_9,is(false));
+ }
+ else if (ver.startsWith("1.7."))
+ {
+ System.err.println("Testing JDK.IS_7 - " + ver);
+ assertThat("JVM(" + ver + ") / JDK.IS_5",JDK.IS_5,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_6",JDK.IS_6,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_7",JDK.IS_7,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_8",JDK.IS_8,is(false));
+ assertThat("JVM(" + ver + ") / JDK.IS_9",JDK.IS_9,is(false));
+ }
+ else if (ver.startsWith("1.8."))
+ {
+ System.err.println("Testing JDK.IS_8 - " + ver);
+ assertThat("JVM(" + ver + ") / JDK.IS_5",JDK.IS_5,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_6",JDK.IS_6,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_7",JDK.IS_7,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_8",JDK.IS_8,is(true));
+ assertThat("JVM(" + ver + ") / JDK.IS_9",JDK.IS_9,is(false));
+ }
+ }
+}

Back to the top