blob: a3bf947c1c3960ac7b4bba45db46c98afe80608a [file] [log] [blame]
<?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 :: Core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.util</a> &gt; <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
* &quot;License&quot;); 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
* &quot;AS IS&quot; 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.
*
* &lt;p&gt;Note that Shiro does not support 1.2 or earlier JVMs - only 1.3 and later.
*
* &lt;p&gt;&lt;em&gt;This class was borrowed and heavily based upon a nearly identical version found in
* the &lt;a href=&quot;http://www.springframework.org/&quot;&gt;Spring Framework&lt;/a&gt;, 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.&lt;/em&gt;
*
* @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. &lt;code&gt;System.getProperty(&quot;java.version&quot;);&lt;/code&gt;. */
private static final String version;
/**
* The virtual machine &lt;em&gt;major&lt;/em&gt; version. For example, with a &lt;code&gt;version&lt;/code&gt; of
* &lt;code&gt;1.5.6_10&lt;/code&gt;, this would be &lt;code&gt;1.5&lt;/code&gt;
*/
private static final int majorVersion;
/**
* Static code initialization block that sets the
* &lt;code&gt;version&lt;/code&gt; and &lt;code&gt;majorVersion&lt;/code&gt; Class constants
* upon initialization.
*/
static {
<span class="nc" id="L82"> version = System.getProperty(&quot;java.version&quot;);</span>
// version String should look like &quot;1.4.2_10&quot;
// 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(&quot;1.8.&quot;)) {</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(&quot;1.7.&quot;)) {</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(&quot;1.6.&quot;)) {</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(&quot;1.5.&quot;)) {</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(&quot;1.4.&quot;)) {</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
* &lt;code&gt;System.getProperty(&quot;java.version&quot;)&lt;/code&gt;.
*
* @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
* &lt;code&gt;if (getMajorVersion() &lt; JAVA_14)&lt;/code&gt;.
*
* @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 &lt;code&gt;true&lt;/code&gt; 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() &gt;= JAVA_14;</span>
}
/**
* Convenience method to determine if the current JVM is at least
* Java 1.5 (Java 5).
*
* @return &lt;code&gt;true&lt;/code&gt; 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() &gt;= JAVA_15;</span>
}
/**
* Convenience method to determine if the current JVM is at least
* Java 1.6 (Java 6).
*
* @return &lt;code&gt;true&lt;/code&gt; 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() &gt;= JAVA_16;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html>