001/*
002 * Copyright 2002-2019 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
019import org.springframework.lang.Nullable;
020
021/**
022 * Class that exposes the Spring version. Fetches the
023 * "Implementation-Version" manifest attribute from the jar file.
024 *
025 * <p>Note that some ClassLoaders do not expose the package metadata,
026 * hence this class might not be able to determine the Spring version
027 * in all environments. Consider using a reflection-based check instead &mdash;
028 * for example, checking for the presence of a specific Spring 5.2
029 * method that you intend to call.
030 *
031 * @author Juergen Hoeller
032 * @since 1.1
033 */
034public final class SpringVersion {
035
036        private SpringVersion() {
037        }
038
039
040        /**
041         * Return the full version string of the present Spring codebase,
042         * or {@code null} if it cannot be determined.
043         * @see Package#getImplementationVersion()
044         */
045        @Nullable
046        public static String getVersion() {
047                Package pkg = SpringVersion.class.getPackage();
048                return (pkg != null ? pkg.getImplementationVersion() : null);
049        }
050
051}