1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk; 27 28 import java.util.regex.Matcher; 29 import java.util.regex.Pattern; 30 import java.util.ArrayList; 31 import java.util.List; 32 import java.util.Optional; 33 34 /** 35 * A representation of the Oracle JDK version-string which interprets the 36 * fourth element of the version number as a patch release. 37 * 38 * <h2><a name="verNum">Version numbers</a></h2> 39 * 40 * The Oracle implementation of the version number contains a fourth 41 * element to identify the patch release as follows: 42 * 43 * <blockquote><pre> 44 * $MAJOR.$MINOR.$SECURITY.$PATCH 45 * </pre></blockquote> 46 * 47 * <ul> 48 * 49 * <li><p> <a href="Version.html#major">{@code $MAJOR}</a>, 50 * <a href="Version.html#minor">{@code $MINOR}</a>, and 51 * <a href="Version.html#security">{@code $SECURITY}</a> are as defined in 52 * {@link Version}. </p></li> 53 * 54 * <li><p> <a name="patch">{@code $PATCH}</a> --- The patch level, incremented 55 * for a release containing security and high-priority customer fixes which 56 * have been tested together. {@code $PATCH} is reset to zero when {@code 57 * $SECURITY}, {@code $MINOR}, or {@code $MAJOR} are incremented. {@code 58 * $PATCH} is included in the short version string if it is not zero. </p> 59 * </li> 60 * 61 * </ul> 62 * 63 * <h2><a name="verStr">Version strings</a></h2> 64 * 65 * <p> The <em>version string</em> is as defined in {@link Version} with the 66 * following addenda: 67 * 68 * <ul> 69 * 70 * <li><p> <a href="Version.html#pre">{@code $PRE}</a> is {@code ea} for all 71 * known non-GAC (General Availability Candidate) releases and defaults to 72 * {@code internal} for developer builds. </p></li> 73 * 74 * <li><p> <a href="Version.html#build">{@code $BUILD}</a> is 75 * <em>required</em> for promoted builds and is <em>optional</em> for 76 * developer builds. </p></li> 77 * 78 * <li><p> <a href="Version.html#opt">{@code $OPT}</a> may contain bug IDs to 79 * identify custom releases or information identifying development 80 * builds. </p></li> 81 * 82 * </ul> 83 * 84 * @since 9 85 */ 86 public class OracleVersion extends Version 87 { 88 /** 89 * Constructs a valid Oracle JDK <a href="#verStr">version string</a> 90 * containing a <a href="#verNum">version number</a> which may include a 91 * <a href="#patch">patch number</a> followed by pre-release and build 92 * information. 93 * 94 * @param s 95 * A string to be interpreted as a version 96 * 97 * @throws IllegalArgumentException 98 * If the given string cannot be interpreted a valid version 99 * 100 * @throws NullPointerException 101 * If the given string is {@code null} 102 * 103 * @throws NumberFormatException 104 * If an element of the version number or the build number cannot 105 * be represented as an {@link Integer} 106 */ 107 OracleVersion(String s) { 108 super(s); 109 } 110 111 /** 112 * Parses the given string as a valid Oracle JDK <a 113 * href="#verStr">version string</a> containing a <a href="#verNum">version 114 * number</a> which may include a <a href="#patch">patch number</a> 115 * followed by pre-release and build information. 116 * 117 * @param s 118 * A string to interpret as an version 119 * 120 * @throws IllegalArgumentException 121 * If the given string cannot be interpreted a valid version 122 * 123 * @throws NullPointerException 124 * If the given string is {@code null} 125 * 126 * @throws NumberFormatException 127 * If an element of the version number or the build number cannot 128 * be represented as an {@link Integer} 129 * 130 * @return This version 131 */ 132 public static OracleVersion parse(String s) { 133 return new OracleVersion(s); 134 } 135 136 /** 137 * Returns the <a href="#patch">patch</a> version number or zero if 138 * it was not set. 139 * 140 * @return The patch version number or zero if it was not set 141 */ 142 public int patch() { 143 return (version().size() > 3 ? version().get(3) : 0); 144 } 145 }