| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>JavaEnvironment.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: Jar Bundle</a> > <a href="../index.html" class="el_bundle">shiro-core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.util</a> > <span class="el_source">JavaEnvironment.java</span></div><h1>JavaEnvironment.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.util; |
| |
| /** |
| * Internal helper class used to find the Java/JDK version |
| * that Shiro is operating within, to allow for automatically |
| * adapting to the present platform's capabilities. |
| * |
| * <p>Note that Shiro does not support 1.2 or earlier JVMs - only 1.3 and later. |
| * |
| * <p><em>This class was borrowed and heavily based upon a nearly identical version found in |
| * the <a href="http://www.springframework.org/">Spring Framework</a>, with minor modifications. |
| * The original author names and copyright (Apache 2.0) has been left in place. A special |
| * thanks to Rod Johnson, Juergen Hoeller, and Rick Evans for making this available.</em> |
| * |
| * @since 0.2 |
| */ |
| <span class="nc" id="L35">public abstract class JavaEnvironment {</span> |
| |
| /** |
| * Constant identifying the 1.3.x JVM (JDK 1.3). |
| */ |
| public static final int JAVA_13 = 0; |
| |
| /** |
| * Constant identifying the 1.4.x JVM (J2SE 1.4). |
| */ |
| public static final int JAVA_14 = 1; |
| |
| /** |
| * Constant identifying the 1.5 JVM (Java 5). |
| */ |
| public static final int JAVA_15 = 2; |
| |
| /** |
| * Constant identifying the 1.6 JVM (Java 6). |
| */ |
| public static final int JAVA_16 = 3; |
| |
| /** |
| * Constant identifying the 1.7 JVM. |
| */ |
| public static final int JAVA_17 = 4; |
| |
| /** |
| * Constant identifying the 1.8 JVM. |
| */ |
| public static final int JAVA_18 = 5; |
| |
| /** The virtual machine version, i.e. <code>System.getProperty("java.version");</code>. */ |
| private static final String version; |
| |
| /** |
| * The virtual machine <em>major</em> version. For example, with a <code>version</code> of |
| * <code>1.5.6_10</code>, this would be <code>1.5</code> |
| */ |
| private static final int majorVersion; |
| |
| /** |
| * Static code initialization block that sets the |
| * <code>version</code> and <code>majorVersion</code> Class constants |
| * upon initialization. |
| */ |
| static { |
| <span class="nc" id="L82"> version = System.getProperty("java.version");</span> |
| // version String should look like "1.4.2_10" |
| |
| // NOTE: JDK 1.9 will be versioned differently '9' and/or 9.x.x |
| // https://blogs.oracle.com/java-platform-group/entry/a_new_jdk_9_version |
| |
| <span class="nc bnc" id="L88" title="All 2 branches missed."> if (version.contains("1.8.")) {</span> |
| <span class="nc" id="L89"> majorVersion = JAVA_18;</span> |
| <span class="nc bnc" id="L90" title="All 2 branches missed."> } else if (version.contains("1.7.")) {</span> |
| <span class="nc" id="L91"> majorVersion = JAVA_17;</span> |
| <span class="nc bnc" id="L92" title="All 2 branches missed."> } else if (version.contains("1.6.")) {</span> |
| <span class="nc" id="L93"> majorVersion = JAVA_16;</span> |
| <span class="nc bnc" id="L94" title="All 2 branches missed."> } else if (version.contains("1.5.")) {</span> |
| <span class="nc" id="L95"> majorVersion = JAVA_15;</span> |
| <span class="nc bnc" id="L96" title="All 2 branches missed."> } else if (version.contains("1.4.")) {</span> |
| <span class="nc" id="L97"> majorVersion = JAVA_14;</span> |
| } else { |
| // else leave 1.3 as default (it's either 1.3 or unknown) |
| <span class="nc" id="L100"> majorVersion = JAVA_13;</span> |
| } |
| <span class="nc" id="L102"> }</span> |
| |
| |
| /** |
| * Return the full Java version string, as returned by |
| * <code>System.getProperty("java.version")</code>. |
| * |
| * @return the full Java version string |
| * @see System#getProperty(String) |
| */ |
| public static String getVersion() { |
| <span class="nc" id="L113"> return version;</span> |
| } |
| |
| /** |
| * Get the major version code. This means we can do things like |
| * <code>if (getMajorVersion() < JAVA_14)</code>. |
| * |
| * @return a code comparable to the JAVA_XX codes in this class |
| * @see #JAVA_13 |
| * @see #JAVA_14 |
| * @see #JAVA_15 |
| * @see #JAVA_16 |
| * @see #JAVA_17 |
| * @see #JAVA_18 |
| */ |
| public static int getMajorVersion() { |
| <span class="nc" id="L129"> return majorVersion;</span> |
| } |
| |
| /** |
| * Convenience method to determine if the current JVM is at least Java 1.4. |
| * |
| * @return <code>true</code> if the current JVM is at least Java 1.4 |
| * @see #getMajorVersion() |
| * @see #JAVA_14 |
| * @see #JAVA_15 |
| * @see #JAVA_16 |
| * @see #JAVA_17 |
| * @see #JAVA_18 |
| */ |
| public static boolean isAtLeastVersion14() { |
| <span class="nc bnc" id="L144" title="All 2 branches missed."> return getMajorVersion() >= JAVA_14;</span> |
| } |
| |
| /** |
| * Convenience method to determine if the current JVM is at least |
| * Java 1.5 (Java 5). |
| * |
| * @return <code>true</code> if the current JVM is at least Java 1.5 |
| * @see #getMajorVersion() |
| * @see #JAVA_15 |
| * @see #JAVA_16 |
| * @see #JAVA_17 |
| * @see #JAVA_18 |
| */ |
| public static boolean isAtLeastVersion15() { |
| <span class="nc bnc" id="L159" title="All 2 branches missed."> return getMajorVersion() >= JAVA_15;</span> |
| } |
| |
| /** |
| * Convenience method to determine if the current JVM is at least |
| * Java 1.6 (Java 6). |
| * |
| * @return <code>true</code> if the current JVM is at least Java 1.6 |
| * @see #getMajorVersion() |
| * @see #JAVA_15 |
| * @see #JAVA_16 |
| * @see #JAVA_17 |
| * @see #JAVA_18 |
| * |
| * @since 1.2 |
| */ |
| public static boolean isAtLeastVersion16() { |
| <span class="nc bnc" id="L176" title="All 2 branches missed."> return getMajorVersion() >= JAVA_16;</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html> |