|
| 1 | +/* |
| 2 | + * |
| 3 | + * * Copyright 2002-2018 the original author or authors. |
| 4 | + * * |
| 5 | + * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * * you may not use this file except in compliance with the License. |
| 7 | + * * You may obtain a copy of the License at |
| 8 | + * * |
| 9 | + * * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * * |
| 11 | + * * Unless required by applicable law or agreed to in writing, software |
| 12 | + * * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * * See the License for the specific language governing permissions and |
| 15 | + * * limitations under the License. |
| 16 | + * |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +package org.springframework.security.crypto.junit; |
| 21 | + |
| 22 | +/** |
| 23 | + * Internal helper class used to find the Java/JVM version that Spring is |
| 24 | + * operating on, to allow for automatically adapting to the present platform's |
| 25 | + * capabilities. |
| 26 | + * |
| 27 | + * <p>Note that Spring requires JVM 1.6 or higher, as of Spring 4.0. |
| 28 | + * |
| 29 | + * @author Rod Johnson |
| 30 | + * @author Juergen Hoeller |
| 31 | + * @author Rick Evans |
| 32 | + * @author Sam Brannen |
| 33 | + * @deprecated as of Spring 4.2.1, in favor of direct checks for the desired |
| 34 | + * JDK API variants via reflection |
| 35 | + */ |
| 36 | +public abstract class JdkVersion { |
| 37 | + |
| 38 | + /** |
| 39 | + * Constant identifying the 1.3.x JVM (JDK 1.3). |
| 40 | + */ |
| 41 | + public static final int JAVA_13 = 0; |
| 42 | + |
| 43 | + /** |
| 44 | + * Constant identifying the 1.4.x JVM (J2SE 1.4). |
| 45 | + */ |
| 46 | + public static final int JAVA_14 = 1; |
| 47 | + |
| 48 | + /** |
| 49 | + * Constant identifying the 1.5 JVM (Java 5). |
| 50 | + */ |
| 51 | + public static final int JAVA_15 = 2; |
| 52 | + |
| 53 | + /** |
| 54 | + * Constant identifying the 1.6 JVM (Java 6). |
| 55 | + */ |
| 56 | + public static final int JAVA_16 = 3; |
| 57 | + |
| 58 | + /** |
| 59 | + * Constant identifying the 1.7 JVM (Java 7). |
| 60 | + */ |
| 61 | + public static final int JAVA_17 = 4; |
| 62 | + |
| 63 | + /** |
| 64 | + * Constant identifying the 1.8 JVM (Java 8). |
| 65 | + */ |
| 66 | + public static final int JAVA_18 = 5; |
| 67 | + |
| 68 | + /** |
| 69 | + * Constant identifying the 1.9 JVM (Java 9). |
| 70 | + */ |
| 71 | + public static final int JAVA_19 = 6; |
| 72 | + |
| 73 | + |
| 74 | + private static final String javaVersion; |
| 75 | + |
| 76 | + private static final int majorJavaVersion; |
| 77 | + |
| 78 | + static { |
| 79 | + javaVersion = System.getProperty("java.version"); |
| 80 | + // version String should look like "1.4.2_10" |
| 81 | + if (javaVersion.contains("1.9.")) { |
| 82 | + majorJavaVersion = JAVA_19; |
| 83 | + } |
| 84 | + else if (javaVersion.contains("1.8.")) { |
| 85 | + majorJavaVersion = JAVA_18; |
| 86 | + } |
| 87 | + else if (javaVersion.contains("1.7.")) { |
| 88 | + majorJavaVersion = JAVA_17; |
| 89 | + } |
| 90 | + else { |
| 91 | + // else leave 1.6 as default (it's either 1.6 or unknown) |
| 92 | + majorJavaVersion = JAVA_16; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + |
| 97 | + /** |
| 98 | + * Return the full Java version string, as returned by |
| 99 | + * {@code System.getProperty("java.version")}. |
| 100 | + * @return the full Java version string |
| 101 | + * @see System#getProperty(String) |
| 102 | + */ |
| 103 | + public static String getJavaVersion() { |
| 104 | + return javaVersion; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Get the major version code. This means we can do things like |
| 109 | + * {@code if (getMajorJavaVersion() >= JAVA_17)}. |
| 110 | + * @return a code comparable to the {@code JAVA_XX} codes in this class |
| 111 | + * @see #JAVA_16 |
| 112 | + * @see #JAVA_17 |
| 113 | + * @see #JAVA_18 |
| 114 | + * @see #JAVA_19 |
| 115 | + */ |
| 116 | + public static int getMajorJavaVersion() { |
| 117 | + return majorJavaVersion; |
| 118 | + } |
| 119 | + |
| 120 | +} |
| 121 | + |
0 commit comments