001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.core;
018
019/**
020 * Internal helper class used to find the Java/JVM version that Spring is
021 * operating on, to allow for automatically adapting to the present platform's
022 * capabilities.
023 *
024 * <p>Note that Spring requires JVM 1.6 or higher, as of Spring 4.0.
025 *
026 * @author Rod Johnson
027 * @author Juergen Hoeller
028 * @author Rick Evans
029 * @author Sam Brannen
030 * @deprecated as of Spring 4.2.1, in favor of direct checks for the desired
031 * JDK API variants via reflection
032 */
033@Deprecated
034public abstract class JdkVersion {
035
036        /**
037         * Constant identifying the 1.3.x JVM (JDK 1.3).
038         */
039        public static final int JAVA_13 = 0;
040
041        /**
042         * Constant identifying the 1.4.x JVM (J2SE 1.4).
043         */
044        public static final int JAVA_14 = 1;
045
046        /**
047         * Constant identifying the 1.5 JVM (Java 5).
048         */
049        public static final int JAVA_15 = 2;
050
051        /**
052         * Constant identifying the 1.6 JVM (Java 6).
053         */
054        public static final int JAVA_16 = 3;
055
056        /**
057         * Constant identifying the 1.7 JVM (Java 7).
058         */
059        public static final int JAVA_17 = 4;
060
061        /**
062         * Constant identifying the 1.8 JVM (Java 8).
063         */
064        public static final int JAVA_18 = 5;
065
066        /**
067         * Constant identifying the 1.9 JVM (Java 9).
068         */
069        public static final int JAVA_19 = 6;
070
071
072        private static final String javaVersion;
073
074        private static final int majorJavaVersion;
075
076        static {
077                javaVersion = System.getProperty("java.version");
078                // version String should look like "1.4.2_10"
079                if (javaVersion.contains("1.9.")) {
080                        majorJavaVersion = JAVA_19;
081                }
082                else if (javaVersion.contains("1.8.")) {
083                        majorJavaVersion = JAVA_18;
084                }
085                else if (javaVersion.contains("1.7.")) {
086                        majorJavaVersion = JAVA_17;
087                }
088                else {
089                        // else leave 1.6 as default (it's either 1.6 or unknown)
090                        majorJavaVersion = JAVA_16;
091                }
092        }
093
094
095        /**
096         * Return the full Java version string, as returned by
097         * {@code System.getProperty("java.version")}.
098         * @return the full Java version string
099         * @see System#getProperty(String)
100         */
101        public static String getJavaVersion() {
102                return javaVersion;
103        }
104
105        /**
106         * Get the major version code. This means we can do things like
107         * {@code if (getMajorJavaVersion() >= JAVA_17)}.
108         * @return a code comparable to the {@code JAVA_XX} codes in this class
109         * @see #JAVA_16
110         * @see #JAVA_17
111         * @see #JAVA_18
112         * @see #JAVA_19
113         */
114        public static int getMajorJavaVersion() {
115                return majorJavaVersion;
116        }
117
118}