--- a/jdk/src/java.base/share/classes/java/lang/Runtime.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Runtime.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,9 +26,21 @@
package java.lang;
import java.io.*;
+import java.math.BigInteger;
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.RandomAccess;
import java.util.StringTokenizer;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
+import sun.security.action.GetPropertyAction;
/**
* Every Java application has a single instance of class
@@ -46,6 +58,8 @@
public class Runtime {
private static final Runtime currentRuntime = new Runtime();
+ private static Version version;
+
/**
* Returns the runtime object associated with the current Java application.
* Most of the methods of class {@code Runtime} are instance
@@ -917,4 +931,591 @@
return out;
}
+ /**
+ * Returns the version of the Java Runtime Environment as a {@link
+ * Runtime.Version}.
+ *
+ * @return the {@link Runtime.Version} of the Java Runtime Environment
+ *
+ * @since 9
+ */
+ public static Version version() {
+ if (version == null) {
+ version = Version.parse(
+ GetPropertyAction.privilegedGetProperty("java.runtime.version"));
+ }
+ return version;
+ }
+
+ /**
+ * A representation of a version string for an implemenation of the
+ * Java SE Platform. A version string contains a version number
+ * optionally followed by pre-release and build information.
+ *
+ * <h2><a name="verNum">Version numbers</a></h2>
+ *
+ * <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence
+ * of elements separated by period characters (U+002E). An element is
+ * either zero, or a unsigned integer numeral without leading zeros. The
+ * final element in a version number must not be zero. The format is:
+ * </p>
+ *
+ * <blockquote><pre>
+ * ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$
+ * </pre></blockquote>
+ *
+ * <p> The sequence may be of arbitrary length but the first three
+ * elements are assigned specific meanings, as follows:</p>
+ *
+ * <blockquote><pre>
+ * $MAJOR.$MINOR.$SECURITY
+ * </pre></blockquote>
+ *
+ * <ul>
+ *
+ * <li><p> <a name="major">{@code $MAJOR}</a> --- The major version
+ * number, incremented for a major release that contains significant new
+ * features as specified in a new edition of the Java SE Platform
+ * Specification, <em>e.g.</em>, <a
+ * href="https://jcp.org/en/jsr/detail?id=337">JSR 337</a> for
+ * Java SE 8. Features may be removed in a major release, given
+ * advance notice at least one major release ahead of time, and
+ * incompatible changes may be made when justified. The {@code $MAJOR}
+ * version number of JDK 8 is {@code 8}; the {@code $MAJOR} version
+ * number of JDK 9 is {@code 9}. When {@code $MAJOR} is incremented,
+ * all subsequent elements are removed. </p></li>
+ *
+ * <li><p> <a name="minor">{@code $MINOR}</a> --- The minor version
+ * number, incremented for a minor update release that may contain
+ * compatible bug fixes, revisions to standard APIs mandated by a
+ * <a href="https://jcp.org/en/procedures/jcp2#5.3">Maintenance Release</a>
+ * of the relevant Platform Specification, and implementation features
+ * outside the scope of that Specification such as new JDK-specific APIs,
+ * additional service providers, new garbage collectors, and ports to new
+ * hardware architectures. </p></li>
+ *
+ * <li><p> <a name="security">{@code $SECURITY}</a> --- The security
+ * level, incremented for a security update release that contains critical
+ * fixes including those necessary to improve security. {@code $SECURITY}
+ * is <strong>not</strong> reset when {@code $MINOR} is incremented. A
+ * higher value of {@code $SECURITY} for a given {@code $MAJOR} value,
+ * therefore, always indicates a more secure release, regardless of the
+ * value of {@code $MINOR}. </p></li>
+ *
+ * </ul>
+ *
+ * <p> The fourth and later elements of a version number are free for use
+ * by downstream consumers of this code base. Such a consumer may,
+ * <em>e.g.</em>, use the fourth element to identify patch releases which
+ * contain a small number of critical non-security fixes in addition to
+ * the security fixes in the corresponding security release. </p>
+ *
+ * <p> The version number does not include trailing zero elements;
+ * <em>i.e.</em>, {@code $SECURITY} is omitted if it has the value zero,
+ * and {@code $MINOR} is omitted if both {@code $MINOR} and {@code
+ * $SECURITY} have the value zero. </p>
+ *
+ * <p> The sequence of numerals in a version number is compared to another
+ * such sequence in numerical, pointwise fashion; <em>e.g.</em>, {@code
+ * 9.9.1} is less than {@code 9.10.3}. If one sequence is shorter than
+ * another then the missing elements of the shorter sequence are
+ * considered to be less than the corresponding elements of the longer
+ * sequence; <em>e.g.</em>, {@code 9.1.2} is less than {@code 9.1.2.1}.
+ * </p>
+ *
+ * <h2><a name="verStr">Version strings</a></h2>
+ *
+ * <p> A <em>version string</em>, {@code $VSTR}, consists of a version
+ * number {@code $VNUM}, as described above, optionally followed by
+ * pre-release and build information, in the format </p>
+ *
+ * <blockquote><pre>
+ * $VNUM(-$PRE)?(\+($BUILD)?(-$OPT)?)?
+ * </pre></blockquote>
+ *
+ * <p> where: </p>
+ *
+ * <ul>
+ *
+ * <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)}
+ * --- A pre-release identifier. Typically {@code ea}, for a
+ * potentially unstable early-access release under active development,
+ * or {@code internal}, for an internal developer build.
+ *
+ * <li><p> <a name="build">{@code $BUILD}</a>, matching {@code
+ * (0|[1-9][0-9]*)} --- The build number, incremented for each promoted
+ * build. {@code $BUILD} is reset to {@code 1} when any portion of {@code
+ * $VNUM} is incremented. </p>
+ *
+ * <li><p> <a name="opt">{@code $OPT}</a>, matching {@code
+ * ([-a-zA-Z0-9\.]+)} --- Additional build information, if desired. In
+ * the case of an {@code internal} build this will often contain the date
+ * and time of the build. </p>
+ *
+ * </ul>
+ *
+ * <p> A version number {@code 10-ea} matches {@code $VNUM = "10"} and
+ * {@code $PRE = "ea"}. The version number {@code 10+-ea} matches
+ * {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p>
+ *
+ * <p> When comparing two version strings, the value of {@code $OPT}, if
+ * present, may or may not be significant depending on the chosen
+ * comparison method. The comparison methods {@link #compareTo(Version)
+ * compareTo()} and {@link #compareToIgnoreOpt(Version)
+ * compareToIgnoreOpt()} should be used consistently with the
+ * corresponding methods {@link #equals(Object) equals()} and {@link
+ * #equalsIgnoreOpt(Object) equalsIgnoreOpt()}. </p>
+ *
+ * <p> A <em>short version string</em>, {@code $SVSTR}, often useful in
+ * less formal contexts, is a version number optionally followed by a
+ * pre-release identifier:
+ *
+ * <blockquote><pre>
+ * $VNUM(-$PRE)?
+ * </pre></blockquote>
+ *
+ * @since 9
+ */
+ public static class Version
+ implements Comparable<Version>
+ {
+ private final List<Integer> version;
+ private final Optional<String> pre;
+ private final Optional<Integer> build;
+ private final Optional<String> optional;
+
+
+ // $VNUM(-$PRE)?(\+($BUILD)?(\-$OPT)?)?
+ // RE limits the format of version strings
+ // ([1-9][0-9]*(?:(?:\.0)*\.[1-9][0-9]*)*)(?:-([a-zA-Z0-9]+))?(?:(\+)(0|[1-9][0-9]*)?)?(?:-([-a-zA-Z0-9.]+))?
+
+ private static final String VNUM
+ = "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)";
+ private static final String VNUM_GROUP = "VNUM";
+
+ private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?";
+ private static final String PRE_GROUP = "PRE";
+
+ private static final String BUILD
+ = "(?:(?<PLUS>\\+)(?<BUILD>0|[1-9][0-9]*)?)?";
+ private static final String PLUS_GROUP = "PLUS";
+ private static final String BUILD_GROUP = "BUILD";
+
+ private static final String OPT = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?";
+ private static final String OPT_GROUP = "OPT";
+
+ private static final String VSTR_FORMAT
+ = "^" + VNUM + PRE + BUILD + OPT + "$";
+ private static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT);
+
+ /**
+ * Constructs a valid <a href="verStr">version string</a> containing
+ * a <a href="#verNum">version number</a> followed by pre-release and
+ * build information.
+ *
+ * @param s
+ * A string to be interpreted as a version
+ *
+ * @throws IllegalArgumentException
+ * If the given string cannot be interpreted as a valid
+ * version
+ *
+ * @throws NullPointerException
+ * If {@code s} is {@code null}
+ *
+ * @throws NumberFormatException
+ * If an element of the version number or the build number
+ * cannot be represented as an {@link Integer}
+ */
+ private Version(String s) {
+ if (s == null)
+ throw new NullPointerException();
+
+ Matcher m = VSTR_PATTERN.matcher(s);
+ if (!m.matches())
+ throw new IllegalArgumentException("Invalid version string: '"
+ + s + "'");
+
+ // $VNUM is a dot-separated list of integers of arbitrary length
+ List<Integer> list = new ArrayList<>();
+ for (String i : m.group(VNUM_GROUP).split("\\."))
+ list.add(Integer.parseInt(i));
+ version = Collections.unmodifiableList(list);
+
+ pre = Optional.ofNullable(m.group(PRE_GROUP));
+
+ String b = m.group(BUILD_GROUP);
+ // $BUILD is an integer
+ build = (b == null)
+ ? Optional.<Integer>empty()
+ : Optional.ofNullable(Integer.parseInt(b));
+
+ optional = Optional.ofNullable(m.group(OPT_GROUP));
+
+ // empty '+'
+ if ((m.group(PLUS_GROUP) != null) && !build.isPresent()) {
+ if (optional.isPresent()) {
+ if (pre.isPresent())
+ throw new IllegalArgumentException("'+' found with"
+ + " pre-release and optional components:'" + s
+ + "'");
+ } else {
+ throw new IllegalArgumentException("'+' found with neither"
+ + " build or optional components: '" + s + "'");
+ }
+ }
+ }
+
+ /**
+ * Parses the given string as a valid
+ * <a href="#verStr">version string</a> containing a
+ * <a href="#verNum">version number</a> followed by pre-release and
+ * build information.
+ *
+ * @param s
+ * A string to interpret as a version
+ *
+ * @throws IllegalArgumentException
+ * If the given string cannot be interpreted as a valid
+ * version
+ *
+ * @throws NullPointerException
+ * If the given string is {@code null}
+ *
+ * @throws NumberFormatException
+ * If an element of the version number or the build number
+ * cannot be represented as an {@link Integer}
+ *
+ * @return The Version of the given string
+ */
+ public static Version parse(String s) {
+ return new Version(s);
+ }
+
+ /**
+ * Returns the <a href="#major">major</a> version number.
+ *
+ * @return The major version number
+ */
+ public int major() {
+ return version.get(0);
+ }
+
+ /**
+ * Returns the <a href="#minor">minor</a> version number or zero if it
+ * was not set.
+ *
+ * @return The minor version number or zero if it was not set
+ */
+ public int minor() {
+ return (version.size() > 1 ? version.get(1) : 0);
+ }
+
+ /**
+ * Returns the <a href="#security">security</a> version number or zero
+ * if it was not set.
+ *
+ * @return The security version number or zero if it was not set
+ */
+ public int security() {
+ return (version.size() > 2 ? version.get(2) : 0);
+ }
+
+ /**
+ * Returns an unmodifiable {@link java.util.List List} of the
+ * integer numerals contained in the <a href="#verNum">version
+ * number</a>. The {@code List} always contains at least one
+ * element corresponding to the <a href="#major">major version
+ * number</a>.
+ *
+ * @return An unmodifiable list of the integer numerals
+ * contained in the version number
+ */
+ public List<Integer> version() {
+ return version;
+ }
+
+ /**
+ * Returns the optional <a href="#pre">pre-release</a> information.
+ *
+ * @return The optional pre-release information as a String
+ */
+ public Optional<String> pre() {
+ return pre;
+ }
+
+ /**
+ * Returns the <a href="#build">build number</a>.
+ *
+ * @return The optional build number.
+ */
+ public Optional<Integer> build() {
+ return build;
+ }
+
+ /**
+ * Returns <a href="#opt">optional</a> additional identifying build
+ * information.
+ *
+ * @return Additional build information as a String
+ */
+ public Optional<String> optional() {
+ return optional;
+ }
+
+ /**
+ * Compares this version to another.
+ *
+ * <p> Each of the components in the <a href="#verStr">version</a> is
+ * compared in the follow order of precedence: version numbers,
+ * pre-release identifiers, build numbers, optional build information.
+ * </p>
+ *
+ * <p> Comparison begins by examining the sequence of version numbers.
+ * If one sequence is shorter than another, then the missing elements
+ * of the shorter sequence are considered to be less than the
+ * corresponding elements of the longer sequence. </p>
+ *
+ * <p> A version with a pre-release identifier is always considered to
+ * be less than a version without one. Pre-release identifiers are
+ * compared numerically when they consist only of digits, and
+ * lexicographically otherwise. Numeric identifiers are considered to
+ * be less than non-numeric identifiers. </p>
+ *
+ * <p> A version without a build number is always less than one with a
+ * build number; otherwise build numbers are compared numerically. </p>
+ *
+ * <p> The optional build information is compared lexicographically.
+ * During this comparison, a version with optional build information is
+ * considered to be greater than a version without one. </p>
+ *
+ * <p> A version is not comparable to any other type of object.
+ *
+ * @param ob
+ * The object to be compared
+ *
+ * @return A negative integer, zero, or a positive integer if this
+ * {@code Version} is less than, equal to, or greater than the
+ * given {@code Version}
+ *
+ * @throws NullPointerException
+ * If the given object is {@code null}
+ */
+ @Override
+ public int compareTo(Version ob) {
+ return compare(ob, false);
+ }
+
+ /**
+ * Compares this version to another disregarding optional build
+ * information.
+ *
+ * <p> Two versions are compared by examining the version string as
+ * described in {@link #compareTo(Version)} with the exception that the
+ * optional build information is always ignored. </p>
+ *
+ * <p> A version is not comparable to any other type of object.
+ *
+ * @param ob
+ * The object to be compared
+ *
+ * @return A negative integer, zero, or a positive integer if this
+ * {@code Version} is less than, equal to, or greater than the
+ * given {@code Version}
+ *
+ * @throws NullPointerException
+ * If the given object is {@code null}
+ */
+ public int compareToIgnoreOpt(Version ob) {
+ return compare(ob, true);
+ }
+
+ private int compare(Version ob, boolean ignoreOpt) {
+ if (ob == null)
+ throw new NullPointerException("Invalid argument");
+
+ int ret = compareVersion(ob);
+ if (ret != 0)
+ return ret;
+
+ ret = comparePre(ob);
+ if (ret != 0)
+ return ret;
+
+ ret = compareBuild(ob);
+ if (ret != 0)
+ return ret;
+
+ if (!ignoreOpt)
+ return compareOpt(ob);
+
+ return 0;
+ }
+
+ private int compareVersion(Version ob) {
+ int size = version.size();
+ int oSize = ob.version().size();
+ int min = Math.min(size, oSize);
+ for (int i = 0; i < min; i++) {
+ Integer val = version.get(i);
+ Integer oVal = ob.version().get(i);
+ if (val != oVal)
+ return val - oVal;
+ }
+ if (size != oSize)
+ return size - oSize;
+ return 0;
+ }
+
+ private int comparePre(Version ob) {
+ Optional<String> oPre = ob.pre();
+ if (!pre.isPresent()) {
+ if (oPre.isPresent())
+ return 1;
+ } else {
+ if (!oPre.isPresent())
+ return -1;
+ String val = pre.get();
+ String oVal = oPre.get();
+ if (val.matches("\\d+")) {
+ return (oVal.matches("\\d+")
+ ? (new BigInteger(val)).compareTo(new BigInteger(oVal))
+ : -1);
+ } else {
+ return (oVal.matches("\\d+")
+ ? 1
+ : val.compareTo(oVal));
+ }
+ }
+ return 0;
+ }
+
+ private int compareBuild(Version ob) {
+ Optional<Integer> oBuild = ob.build();
+ if (oBuild.isPresent()) {
+ return (build.isPresent()
+ ? build.get().compareTo(oBuild.get())
+ : 1);
+ } else if (build.isPresent()) {
+ return -1;
+ }
+ return 0;
+ }
+
+ private int compareOpt(Version ob) {
+ Optional<String> oOpt = ob.optional();
+ if (!optional.isPresent()) {
+ if (oOpt.isPresent())
+ return -1;
+ } else {
+ if (!oOpt.isPresent())
+ return 1;
+ return optional.get().compareTo(oOpt.get());
+ }
+ return 0;
+ }
+
+ /**
+ * Returns a string representation of this version.
+ *
+ * @return The version string
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb
+ = new StringBuilder(version.stream()
+ .map(Object::toString)
+ .collect(Collectors.joining(".")));
+
+ pre.ifPresent(v -> sb.append("-").append(v));
+
+ if (build.isPresent()) {
+ sb.append("+").append(build.get());
+ if (optional.isPresent())
+ sb.append("-").append(optional.get());
+ } else {
+ if (optional.isPresent()) {
+ sb.append(pre.isPresent() ? "-" : "+-");
+ sb.append(optional.get());
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Determines whether this {@code Version} is equal to another object.
+ *
+ * <p> Two {@code Version}s are equal if and only if they represent the
+ * same version string.
+ *
+ * <p> This method satisfies the general contract of the {@link
+ * Object#equals(Object) Object.equals} method. </p>
+ *
+ * @param ob
+ * The object to which this {@code Version} is to be compared
+ *
+ * @return {@code true} if, and only if, the given object is a {@code
+ * Version} that is identical to this {@code Version}
+ *
+ */
+ @Override
+ public boolean equals(Object ob) {
+ boolean ret = equalsIgnoreOpt(ob);
+ if (!ret)
+ return false;
+
+ Version that = (Version)ob;
+ return (this.optional().equals(that.optional()));
+ }
+
+ /**
+ * Determines whether this {@code Version} is equal to another
+ * disregarding optional build information.
+ *
+ * <p> Two {@code Version}s are equal if and only if they represent the
+ * same version string disregarding the optional build information.
+ *
+ * @param ob
+ * The object to which this {@code Version} is to be compared
+ *
+ * @return {@code true} if, and only if, the given object is a {@code
+ * Version} that is identical to this {@code Version}
+ * ignoring the optinal build information
+ *
+ */
+ public boolean equalsIgnoreOpt(Object ob) {
+ if (this == ob)
+ return true;
+ if (!(ob instanceof Version))
+ return false;
+
+ Version that = (Version)ob;
+ return (this.version().equals(that.version())
+ && this.pre().equals(that.pre())
+ && this.build().equals(that.build()));
+ }
+
+ /**
+ * Returns the hash code of this version.
+ *
+ * <p> This method satisfies the general contract of the {@link
+ * Object#hashCode Object.hashCode} method.
+ *
+ * @return The hashcode of this version
+ */
+ @Override
+ public int hashCode() {
+ int h = 1;
+ int p = 17;
+
+ h = p * h + version.hashCode();
+ h = p * h + pre.hashCode();
+ h = p * h + build.hashCode();
+ h = p * h + optional.hashCode();
+
+ return h;
+ }
+ }
+
}
--- a/jdk/src/java.base/share/classes/java/lang/System.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/System.java Thu May 19 20:14:17 2016 +0000
@@ -576,7 +576,8 @@
* <tr><th>Key</th>
* <th>Description of Associated Value</th></tr>
* <tr><td><code>java.version</code></td>
- * <td>Java Runtime Environment version</td></tr>
+ * <td>Java Runtime Environment version which may be interpreted
+ * as a {@link Runtime.Version}</td></tr>
* <tr><td><code>java.vendor</code></td>
* <td>Java Runtime Environment vendor</td></tr>
* <tr><td><code>java.vendor.url</code></td>
@@ -584,19 +585,22 @@
* <tr><td><code>java.home</code></td>
* <td>Java installation directory</td></tr>
* <tr><td><code>java.vm.specification.version</code></td>
- * <td>Java Virtual Machine specification version</td></tr>
+ * <td>Java Virtual Machine specification version which may be
+ * interpreted as a {@link Runtime.Version}</td></tr>
* <tr><td><code>java.vm.specification.vendor</code></td>
* <td>Java Virtual Machine specification vendor</td></tr>
* <tr><td><code>java.vm.specification.name</code></td>
* <td>Java Virtual Machine specification name</td></tr>
* <tr><td><code>java.vm.version</code></td>
- * <td>Java Virtual Machine implementation version</td></tr>
+ * <td>Java Virtual Machine implementation version which may be
+ * interpreted as a {@link Runtime.Version}</td></tr>
* <tr><td><code>java.vm.vendor</code></td>
* <td>Java Virtual Machine implementation vendor</td></tr>
* <tr><td><code>java.vm.name</code></td>
* <td>Java Virtual Machine implementation name</td></tr>
* <tr><td><code>java.specification.version</code></td>
- * <td>Java Runtime Environment specification version</td></tr>
+ * <td>Java Runtime Environment specification version which may be
+ * interpreted as a {@link Runtime.Version}</td></tr>
* <tr><td><code>java.specification.vendor</code></td>
* <td>Java Runtime Environment specification vendor</td></tr>
* <tr><td><code>java.specification.name</code></td>
--- a/jdk/src/java.base/share/classes/java/util/jar/JarFile.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/util/jar/JarFile.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -153,7 +153,7 @@
SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
BASE_VERSION = 8; // one less than lowest version for versioned entries
- int runtimeVersion = jdk.Version.current().major();
+ int runtimeVersion = Runtime.version().major();
String jarVersion =
GetPropertyAction.privilegedGetProperty("jdk.util.jar.version");
if (jarVersion != null) {
@@ -357,7 +357,7 @@
}
private boolean runtimeVersionExists() {
- int version = jdk.Version.current().major();
+ int version = Runtime.version().major();
try {
Release.valueOf(version);
return true;
--- a/jdk/src/java.base/share/classes/jdk/Version.java Thu May 19 19:46:20 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,603 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk;
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import sun.security.action.GetPropertyAction;
-
-/**
- * A representation of the JDK version-string which contains a version
- * number optionally followed by pre-release and build information.
- *
- * <h2><a name="verNum">Version numbers</a></h2>
- *
- * A <em>version number</em>, {@code $VNUM}, is a non-empty sequence of
- * non-negative integer numerals, without leading or trailing zeroes,
- * separated by period characters (U+002E); i.e., it matches the regular
- * expression {@code ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$}. The sequence may
- * be of arbitrary length but the first three elements are assigned specific
- * meanings, as follows:
- *
- * <blockquote><pre>
- * $MAJOR.$MINOR.$SECURITY
- * </pre></blockquote>
- *
- * <ul>
- *
- * <li><p> <a name="major">{@code $MAJOR}</a> --- The major version number,
- * incremented for a major release that contains significant new features as
- * specified in a new edition of the Java SE Platform Specification,
- * <em>e.g.</em>, <a href="https://jcp.org/en/jsr/detail?id=337">JSR 337</a>
- * for Java SE 8. Features may be removed in a major release, given
- * advance notice at least one major release ahead of time, and incompatible
- * changes may be made when justified. The {@code $MAJOR} version number of
- * JDK 8 was {@code 8}; the {@code $MAJOR} version number of JDK 9
- * is {@code 9}. </p></li>
- *
- * <li><p> <a name="minor">{@code $MINOR}</a> --- The minor version number,
- * incremented for a minor update release that may contain compatible bug
- * fixes, revisions to standard APIs mandated by a <a
- * href="https://jcp.org/en/procedures/jcp2#5.3">Maintenance Release</a> of
- * the relevant Platform Specification, and implementation features outside
- * the scope of that Specification such as new JDK-specific APIs, additional
- * service providers, new garbage collectors, and ports to new hardware
- * architectures. {@code $MINOR} is reset to zero when {@code $MAJOR} is
- * incremented. </p></li>
- *
- * <li><p> <a name="security">{@code $SECURITY}</a> --- The security level,
- * incremented for a security-update release that contains critical fixes
- * including those necessary to improve security. {@code $SECURITY} is reset
- * to zero <strong>only</strong> when {@code $MAJOR} is incremented. A higher
- * value of {@code $SECURITY} for a given {@code $MAJOR} value, therefore,
- * always indicates a more secure release, regardless of the value of {@code
- * $MINOR}. </p></li>
- *
- * </ul>
- *
- * <p> The fourth and later elements of a version number are free for use by
- * downstream consumers of the JDK code base. Such a consumer may,
- * <em>e.g.</em>, use the fourth element to identify patch releases which
- * contain a small number of critical non-security fixes in addition to the
- * security fixes in the corresponding security release. </p>
- *
- * <p> The version number does not include trailing zero elements;
- * <em>i.e.</em>, {@code $SECURITY} is omitted if it has the value zero, and
- * {@code $MINOR} is omitted if both {@code $MINOR} and {@code $SECURITY} have
- * the value zero. </p>
- *
- * <p> The sequence of numerals in a version number is compared to another
- * such sequence in numerical, pointwise fashion; <em>e.g.</em>, {@code 9.9.1}
- * is less than {@code 9.10.0}. If one sequence is shorter than another then
- * the missing elements of the shorter sequence are considered to be zero;
- * <em>e.g.</em>, {@code 9.1.2} is equal to {@code 9.1.2.0} but less than
- * {@code 9.1.2.1}. </p>
- *
- * <h2><a name="verStr">Version strings</a></h2>
- *
- * <p> A <em>version string</em> {@code $VSTR} consists of a version number
- * {@code $VNUM}, as described above, optionally followed by pre-release and
- * build information, in the format </p>
- *
- * <blockquote><pre>
- * $VNUM(-$PRE)?(\+($BUILD)?(-$OPT)?)?
- * </pre></blockquote>
- *
- * <p> where: </p>
- *
- * <ul>
- *
- * <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)} ---
- * A pre-release identifier. Typically {@code ea}, for an early-access
- * release that's under active development and potentially unstable, or {@code
- * internal}, for an internal developer build.
- *
- * <li><p> <a name="build">{@code $BUILD}</a>, matching {@code
- * (0|[1-9][0-9]*)} --- The build number, incremented for each promoted build.
- * {@code $BUILD} is reset to {@code 1} when any portion of {@code $VNUM} is
- * incremented. </p>
- *
- * <li><p> <a name="opt">{@code $OPT}</a>, matching {@code ([-a-zA-Z0-9\.]+)}
- * --- Additional build information, if desired. In the case of an {@code
- * internal} build this will often contain the date and time of the
- * build. </p>
- *
- * </ul>
- *
- * <p> When comparing two version strings the value of {@code $OPT}, if
- * present, may or may not be significant depending on the chosen comparison
- * method. The comparison methods {@link #compareTo(Version) compareTo()} and
- * {@link #compareToIgnoreOpt(Version) compareToIgnoreOpt{}} should be used
- * consistently with the corresponding methods {@link #equals(Object) equals()}
- * and {@link #equalsIgnoreOpt(Object) equalsIgnoreOpt()}. </p>
- *
- * <p> A <em>short version string</em> ({@code $SVSTR}), often useful in less
- * formal contexts, is simply {@code $VNUM} optionally ended with {@code
- * -$PRE}. </p>
- *
- * @since 9
- */
-public final class Version
- implements Comparable<Version>
-{
- private final List<Integer> version;
- private final Optional<String> pre;
- private final Optional<Integer> build;
- private final Optional<String> optional;
-
- private static Version current;
-
- // $VNUM(-$PRE)?(\+($BUILD)?(\-$OPT)?)?
- // RE limits the format of version strings
- // ([1-9][0-9]*(?:(?:\.0)*\.[1-9][0-9]*)*)(?:-([a-zA-Z0-9]+))?(?:(\+)(0|[1-9][0-9]*)?)?(?:-([-a-zA-Z0-9.]+))?
-
- private static final String VNUM
- = "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)";
- private static final String VNUM_GROUP = "VNUM";
-
- private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?";
- private static final String PRE_GROUP = "PRE";
-
- private static final String BUILD
- = "(?:(?<PLUS>\\+)(?<BUILD>0|[1-9][0-9]*)?)?";
- private static final String PLUS_GROUP = "PLUS";
- private static final String BUILD_GROUP = "BUILD";
-
- private static final String OPT = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?";
- private static final String OPT_GROUP = "OPT";
-
- private static final String VSTR_FORMAT
- = "^" + VNUM + PRE + BUILD + OPT + "$";
- private static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT);
-
- /**
- * Constructs a valid JDK <a href="verStr">version string</a> containing a
- * <a href="#verNum">version number</a> followed by pre-release and build
- * information.
- *
- * @param s
- * A string to be interpreted as a version
- *
- * @throws IllegalArgumentException
- * If the given string cannot be interpreted a valid version
- *
- * @throws NullPointerException
- * If {@code s} is {@code null}
- *
- * @throws NumberFormatException
- * If an element of the version number or the build number cannot
- * be represented as an {@link Integer}
- */
- private Version(String s) {
- if (s == null)
- throw new NullPointerException();
-
- Matcher m = VSTR_PATTERN.matcher(s);
- if (!m.matches())
- throw new IllegalArgumentException("Invalid version string: '"
- + s + "'");
-
- // $VNUM is a dot-separated list of integers of arbitrary length
- List<Integer> list = new ArrayList<>();
- for (String i : m.group(VNUM_GROUP).split("\\."))
- list.add(Integer.parseInt(i));
- version = Collections.unmodifiableList(list);
-
- pre = Optional.ofNullable(m.group(PRE_GROUP));
-
- String b = m.group(BUILD_GROUP);
- // $BUILD is an integer
- build = (b == null)
- ? Optional.<Integer>empty()
- : Optional.ofNullable(Integer.parseInt(b));
-
- optional = Optional.ofNullable(m.group(OPT_GROUP));
-
- // empty '+'
- if ((m.group(PLUS_GROUP) != null) && !build.isPresent()) {
- if (optional.isPresent()) {
- if (pre.isPresent())
- throw new IllegalArgumentException("'+' found with"
- + " pre-release and optional components:'" + s + "'");
- } else {
- throw new IllegalArgumentException("'+' found with neither"
- + " build or optional components: '" + s + "'");
- }
- }
- }
-
- /**
- * Parses the given string as a valid JDK <a
- * href="#verStr">version string</a> containing a <a
- * href="#verNum">version number</a> followed by pre-release and
- * build information.
- *
- * @param s
- * A string to interpret as a version
- *
- * @throws IllegalArgumentException
- * If the given string cannot be interpreted a valid version
- *
- * @throws NullPointerException
- * If the given string is {@code null}
- *
- * @throws NumberFormatException
- * If an element of the version number or the build number cannot
- * be represented as an {@link Integer}
- *
- * @return This version
- */
- public static Version parse(String s) {
- return new Version(s);
- }
-
- /**
- * Returns {@code System.getProperty("java.version")} as a Version.
- *
- * @throws SecurityException
- * If a security manager exists and its {@link
- * SecurityManager#checkPropertyAccess(String)
- * checkPropertyAccess} method does not allow access to the
- * system property "java.version"
- *
- * @return {@code System.getProperty("java.version")} as a Version
- */
- public static Version current() {
- if (current == null) {
- current = parse(
- GetPropertyAction.privilegedGetProperty("java.version"));
- }
- return current;
- }
-
- /**
- * Returns the <a href="#major">major</a> version number.
- *
- * @return The major version number
- */
- public int major() {
- return version.get(0);
- }
-
- /**
- * Returns the <a href="#minor">minor</a> version number or zero if it was
- * not set.
- *
- * @return The minor version number or zero if it was not set
- */
- public int minor() {
- return (version.size() > 1 ? version.get(1) : 0);
- }
-
- /**
- * Returns the <a href="#security">security</a> version number or zero if
- * it was not set.
- *
- * @return The security version number or zero if it was not set
- */
- public int security() {
- return (version.size() > 2 ? version.get(2) : 0);
- }
-
- /**
- * Returns an unmodifiable {@link java.util.List List} of the
- * integer numerals contained in the <a href="#verNum">version
- * number</a>. The {@code List} always contains at least one
- * element corresponding to the <a href="#major">major version
- * number</a>.
- *
- * @return An unmodifiable list of the integer numerals
- * contained in the version number
- */
- public List<Integer> version() {
- return version;
- }
-
- /**
- * Returns the optional <a href="#pre">pre-release</a> information.
- *
- * @return The optional pre-release information as a String
- */
- public Optional<String> pre() {
- return pre;
- }
-
- /**
- * Returns the <a href="#build">build number</a>.
- *
- * @return The optional build number.
- */
- public Optional<Integer> build() {
- return build;
- }
-
- /**
- * Returns <a href="#opt">optional</a> additional identifying build
- * information.
- *
- * @return Additional build information as a String
- */
- public Optional<String> optional() {
- return optional;
- }
-
- /**
- * Compares this version to another.
- *
- * <p> Each of the components in the <a href="#verStr">version</a> is
- * compared in the follow order of precedence: version numbers,
- * pre-release identifiers, build numbers, optional build information. </p>
- *
- * <p> Comparison begins by examining the sequence of version numbers. If
- * one sequence is shorter than another, then the missing elements of the
- * shorter sequence are considered to be zero. </p>
- *
- * <p> A version with a pre-release identifier is always considered to be
- * less than a version without one. Pre-release identifiers are compared
- * numerically when they consist only of digits, and lexicographically
- * otherwise. Numeric identifiers are considered to be less than
- * non-numeric identifiers. </p>
- *
- * <p> A version without a build number is always less than one with a
- * build number; otherwise build numbers are compared numerically. </p>
- *
- * <p> The optional build information is compared lexicographically.
- * During this comparison, a version with optional build information is
- * considered to be greater than a version without one. </p>
- *
- * <p> A version is not comparable to any other type of object.
- *
- * @param ob
- * The object to be compared
- *
- * @return A negative integer, zero, or a positive integer if this
- * {@code Version} is less than, equal to, or greater than the
- * given {@code Version}
- *
- * @throws NullPointerException
- * If the given object is {@code null}
- */
- @Override
- public int compareTo(Version ob) {
- return compare(ob, false);
- }
-
- /**
- * Compares this version to another disregarding optional build
- * information.
- *
- * <p> Two versions are compared by examining the version string as
- * described in {@link #compareTo(Version)} with the exception that the
- * optional build information is always ignored. </p>
- *
- * <p> A version is not comparable to any other type of object.
- *
- * @param ob
- * The object to be compared
- *
- * @return A negative integer, zero, or a positive integer if this
- * {@code Version} is less than, equal to, or greater than the
- * given {@code Version}
- *
- * @throws NullPointerException
- * If the given object is {@code null}
- */
- public int compareToIgnoreOpt(Version ob) {
- return compare(ob, true);
- }
-
- private int compare(Version ob, boolean ignoreOpt) {
- if (ob == null)
- throw new NullPointerException("Invalid argument");
-
- int ret = compareVersion(ob);
- if (ret != 0)
- return ret;
-
- ret = comparePre(ob);
- if (ret != 0)
- return ret;
-
- ret = compareBuild(ob);
- if (ret != 0)
- return ret;
-
- if (!ignoreOpt)
- return compareOpt(ob);
-
- return 0;
- }
-
- private int compareVersion(Version ob) {
- int size = version.size();
- int oSize = ob.version().size();
- int min = Math.min(size, oSize);
- for (int i = 0; i < min; i++) {
- Integer val = version.get(i);
- Integer oVal = ob.version().get(i);
- if (val != oVal)
- return val - oVal;
- }
- if (size != oSize)
- return size - oSize;
- return 0;
- }
-
- private int comparePre(Version ob) {
- Optional<String> oPre = ob.pre();
- if (!pre.isPresent()) {
- if (oPre.isPresent())
- return 1;
- } else {
- if (!oPre.isPresent())
- return -1;
- String val = pre.get();
- String oVal = oPre.get();
- if (val.matches("\\d+")) {
- return (oVal.matches("\\d+")
- ? (new BigInteger(val)).compareTo(new BigInteger(oVal))
- : -1);
- } else {
- return (oVal.matches("\\d+")
- ? 1
- : val.compareTo(oVal));
- }
- }
- return 0;
- }
-
- private int compareBuild(Version ob) {
- Optional<Integer> oBuild = ob.build();
- if (oBuild.isPresent()) {
- return (build.isPresent()
- ? build.get().compareTo(oBuild.get())
- : 1);
- } else if (build.isPresent()) {
- return -1;
- }
- return 0;
- }
-
- private int compareOpt(Version ob) {
- Optional<String> oOpt = ob.optional();
- if (!optional.isPresent()) {
- if (oOpt.isPresent())
- return -1;
- } else {
- if (!oOpt.isPresent())
- return 1;
- return optional.get().compareTo(oOpt.get());
- }
- return 0;
- }
-
- /**
- * Returns a string representation of this version.
- *
- * @return The version string
- */
- @Override
- public String toString() {
- StringBuilder sb
- = new StringBuilder(version.stream()
- .map(Object::toString)
- .collect(Collectors.joining(".")));
- pre.ifPresent(v -> sb.append("-").append(v));
-
- if (build.isPresent()) {
- sb.append("+").append(build.get());
- if (optional.isPresent())
- sb.append("-").append(optional.get());
- } else {
- if (optional.isPresent()) {
- sb.append(pre.isPresent() ? "-" : "+-");
- sb.append(optional.get());
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Determines whether this {@code Version} is equal to another object.
- *
- * <p> Two {@code Version}s are equal if and only if they represent the
- * same version string.
- *
- * <p> This method satisfies the general contract of the {@link
- * Object#equals(Object) Object.equals} method. </p>
- *
- * @param ob
- * The object to which this {@code Version} is to be compared
- *
- * @return {@code true} if, and only if, the given object is a {@code
- * Version} that is identical to this {@code Version}
- *
- */
- @Override
- public boolean equals(Object ob) {
- boolean ret = equalsIgnoreOpt(ob);
- if (!ret)
- return false;
-
- Version that = (Version)ob;
- return (this.optional().equals(that.optional()));
- }
-
- /**
- * Determines whether this {@code Version} is equal to another
- * disregarding optional build information.
- *
- * <p> Two {@code Version}s are equal if and only if they represent the
- * same version string disregarding the optional build information.
- *
- * @param ob
- * The object to which this {@code Version} is to be compared
- *
- * @return {@code true} if, and only if, the given object is a {@code
- * Version} that is identical to this {@code Version}
- * ignoring the optinal build information
- *
- */
- public boolean equalsIgnoreOpt(Object ob) {
- if (this == ob)
- return true;
- if (!(ob instanceof Version))
- return false;
-
- Version that = (Version)ob;
- return (this.version().equals(that.version())
- && this.pre().equals(that.pre())
- && this.build().equals(that.build()));
- }
-
- /**
- * Returns the hash code of this version.
- *
- * <p> This method satisfies the general contract of the {@link
- * Object#hashCode Object.hashCode} method.
- *
- * @return The hashcode of this version
- */
- @Override
- public int hashCode() {
- int h = 1;
- int p = 17;
-
- h = p * h + version.hashCode();
- h = p * h + pre.hashCode();
- h = p * h + build.hashCode();
- h = p * h + optional.hashCode();
-
- return h;
- }
-}
--- a/jdk/src/java.base/share/classes/module-info.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/java.base/share/classes/module-info.java Thu May 19 20:14:17 2016 +0000
@@ -81,9 +81,6 @@
exports javax.security.auth.x500;
exports javax.security.cert;
- // see JDK-8144062
- exports jdk;
-
// the service types defined by the APIs in this module
--- a/jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/AboutDialog.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/AboutDialog.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -181,7 +181,7 @@
}
private static String getOnlineDocUrl() {
- String version = Integer.toString(jdk.Version.current().major());
+ String version = Integer.toString(Runtime.version().major());
return Resources.format(Messages.HELP_ABOUT_DIALOG_USER_GUIDE_LINK_URL,
version);
}
--- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.Runtime.Version;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
@@ -36,7 +37,6 @@
import java.util.function.Function;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
-import jdk.Version;
/**
* Adds aliasing to ZipFileSystem to support multi-release jar files. An alias map
@@ -69,7 +69,7 @@
if (o instanceof String) {
String s = (String)o;
if (s.equals("runtime")) {
- version = jdk.Version.current().major();
+ version = Runtime.version().major();
} else {
version = Integer.parseInt(s);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/Runtime/Version/Basic.java Thu May 19 20:14:17 2016 +0000
@@ -0,0 +1,401 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Unit test for java.lang.Runtime.Version.
+ * @bug 8072379 8144062
+ */
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.Runtime.Version;
+import java.math.BigInteger;
+import java.util.stream.Collectors;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static java.lang.System.out;
+
+public class Basic {
+ private static final Class<? extends Throwable> IAE
+ = IllegalArgumentException.class;
+ private static final Class<? extends Throwable> NPE
+ = NullPointerException.class;
+ private static final Class<? extends Throwable> NFE
+ = NumberFormatException.class;
+ private static final Class<?> VERSION = Version.class;
+
+ private static final BigInteger TOO_BIG
+ = (BigInteger.valueOf(Integer.MAX_VALUE)).add(BigInteger.ONE);
+ private static final String TOO_BIG_STR = TOO_BIG.toString();
+
+ public static void main(String ... args) {
+
+ //// Tests for parse(), major(), minor(), security(), pre(),
+ //// build(), opt(), version(), toString()
+ // v M m sec pre bld opt
+
+ // $VNUM
+ test("9", 9, 0, 0, "", 0, "");
+ test("9.1", 9, 1, 0, "", 0, "");
+ test("9.0.1", 9, 0, 1, "", 0, "");
+ test("404.1.2", 404, 1, 2, "", 0, "");
+ test("9.1.2.3", 9, 1, 2, "", 0, "");
+ test("1000.0.0.0.0.0.99999999", 1000, 0, 0, "", 0, "");
+
+ tryCatch(null, NPE);
+ tryCatch("", IAE);
+ tryCatch("foo", IAE);
+ tryCatch("7a", IAE);
+ tryCatch("0", IAE);
+ tryCatch("09", IAE);
+ tryCatch("9.0", IAE);
+ tryCatch("9.0.", IAE);
+ tryCatch("1.9,1", IAE);
+ tryCatch(TOO_BIG_STR, NFE);
+
+ // $PRE
+ test("9-ea", 9, 0, 0, "ea", 0, "");
+ test("9-internal", 9, 0, 0, "internal", 0, "");
+ test("9-0", 9, 0, 0, "0", 0, "");
+ test("9.2.7-8", 9, 2, 7, "8", 0, "");
+ test("1-ALL", 1, 0, 0, "ALL", 0, "");
+ test("2.3.4.5-1a", 2, 3, 4, "1a", 0, "");
+ test("1-" + TOO_BIG_STR, 1, 0, 0, TOO_BIG_STR, 0, "");
+
+ tryCatch("9:-ea", IAE);
+ tryCatch("3.14159-", IAE);
+ tryCatch("3.14159-%", IAE);
+
+ // $BUILD
+ test("9+0", 9, 0, 0, "", 0, "");
+ test("3.14+9999900", 3, 14, 0, "", 9999900, "");
+ test("9-pre+105", 9, 0, 0, "pre", 105, "");
+ test("6.0.42-8beta+4", 6, 0, 42, "8beta", 4, "");
+
+ tryCatch("9+", IAE);
+ tryCatch("7+a", IAE);
+ tryCatch("9+00", IAE);
+ tryCatch("4.2+01", IAE);
+ tryCatch("4.2+1a", IAE);
+ tryCatch("1+" + TOO_BIG_STR, NFE);
+
+ // $OPT
+ test("9+-foo", 9, 0, 0, "", 0, "foo");
+ test("9-pre-opt", 9, 0, 0, "pre", 0, "opt");
+ test("42+---bar", 42, 0, 0, "", 0, "--bar");
+ test("2.91+-8061493-", 2, 91, 0, "", 0, "8061493-");
+ test("24+-foo.bar", 24, 0, 0, "", 0, "foo.bar");
+ test("9-ribbit+17-...", 9, 0, 0, "ribbit", 17, "...");
+ test("7+1-" + TOO_BIG_STR, 7,0, 0, "", 1, TOO_BIG_STR);
+
+ tryCatch("9-pre+-opt", IAE);
+ tryCatch("1.4142+-", IAE);
+ tryCatch("2.9979+-%", IAE);
+
+ //// Test for Runtime.version()
+ testVersion();
+
+ //// Test for equals{IgnoreOpt}?(), hashCode(), compareTo{IgnoreOpt}?()
+ // compare: after "<" == -1, equal == 0, before ">" == 1
+ // v0 v1 eq eqNO cmp cmpNO
+ testEHC("9", "9", true, true, 0, 0);
+
+ testEHC("8", "9", false, false, -1, -1);
+ testEHC("9", "10", false, false, -1, -1);
+ testEHC("9", "8", false, false, 1, 1);
+
+ // $OPT comparison
+ testEHC("9", "9+-oink", false, true, -1, 0);
+ testEHC("9+-ribbit", "9+-moo", false, true, 1, 0);
+ testEHC("9-quack+3-ribbit",
+ "9-quack+3-moo", false, true, 1, 0);
+ testEHC("9.1+7", "9.1+7-moo-baa-la", false, true, -1, 0);
+
+ // numeric vs. non-numeric $PRE
+ testEHC("9.1.1.2-2a", "9.1.1.2-12", false, false, 1, 1);
+ testEHC("9.1.1.2-12", "9.1.1.2-4", false, false, 1, 1);
+
+ testEHC("27.16", "27.16+120", false, false, 1, 1);
+ testEHC("10", "10-ea", false, false, 1, 1);
+ testEHC("10.1+1", "10.1-ea+1", false, false, 1, 1);
+ testEHC("10.0.1+22", "10.0.1+21", false, false, 1, 1);
+
+ // numeric vs. non-numeric $PRE
+ testEHC("9.1.1.2-12", "9.1.1.2-a2", false, false, -1, -1);
+ testEHC("9.1.1.2-1", "9.1.1.2-4", false, false, -1, -1);
+
+ testEHC("9-internal", "9", false, false, -1, -1);
+ testEHC("9-ea+120", "9+120", false, false, -1, -1);
+ testEHC("9-ea+120", "9+120", false, false, -1, -1);
+ testEHC("9+101", "9", false, false, -1, -1);
+ testEHC("9+101", "9+102", false, false, -1, -1);
+ testEHC("1.9-ea", "9-ea", false, false, -1, -1);
+
+ if (fail != 0)
+ throw new RuntimeException((fail + pass) + " tests: "
+ + fail + " failure(s), first", first);
+ else
+ out.println("all " + (fail + pass) + " tests passed");
+
+ }
+
+ private static void test(String s, Integer major, Integer minor,
+ Integer sec, String pre, Integer build,
+ String opt)
+ {
+ Version v = testParse(s);
+
+ testStr(v.toString(), s);
+
+ testInt(v.major(), major);
+ testInt(v.minor(), minor);
+ testInt(v.security(), sec);
+ testStr((v.pre().isPresent() ? v.pre().get() : ""), pre);
+ testInt((v.build().isPresent() ? v.build().get() : 0), build);
+ testStr((v.optional().isPresent() ? v.optional().get() : ""), opt);
+
+ testVersion(v.version(), s);
+ }
+
+ private static Version testParse(String s) {
+ Version v = Version.parse(s);
+ pass();
+ return v;
+ }
+
+ private static void testInt(int got, int exp) {
+ if (got != exp) {
+ fail("testInt()", Integer.toString(exp), Integer.toString(got));
+ } else {
+ pass();
+ }
+ }
+
+ private static void testStr(String got, String exp) {
+ if (!got.equals(exp)) {
+ fail("testStr()", exp, got);
+ } else {
+ pass();
+ }
+ }
+
+ private static void tryCatch(String s, Class<? extends Throwable> ex) {
+ Throwable t = null;
+ try {
+ Version.parse(s);
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass())) {
+ t = x;
+ } else
+ x.printStackTrace();
+ }
+ if ((t == null) && (ex != null))
+ fail(s, ex);
+ else
+ pass();
+ }
+
+ private static void testVersion() {
+ Version current = Runtime.version();
+ String javaVer = System.getProperty("java.runtime.version");
+
+ // java.runtime.version == $VNUM(\-$PRE)?(\+$BUILD)?(-$OPT)?
+ String [] jv = javaVer.split("\\+");
+ String [] ver = jv[0].split("-");
+ List<Integer> javaVerVNum
+ = Arrays.stream(ver[0].split("\\."))
+ .map(v -> Integer.parseInt(v))
+ .collect(Collectors.toList());
+ if (!javaVerVNum.equals(current.version())) {
+ fail("Runtime.version()", javaVerVNum.toString(),
+ current.version().toString());
+ } else {
+ pass();
+ }
+
+ Optional<String> javaVerPre
+ = (ver.length == 2)
+ ? Optional.ofNullable(ver[1])
+ : Optional.empty();
+ if (!javaVerPre.equals(current.pre())) {
+ fail("testCurrent() pre()", javaVerPre.toString(),
+ current.pre().toString());
+ } else {
+ pass();
+ }
+
+ testEHC(current.toString(), javaVer, true, true, 0, 0);
+ }
+
+ private static void testVersion(List<Integer> vnum, String s) {
+ List<Integer> svnum = new ArrayList<Integer>();
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) {
+ Character c = s.charAt(i);
+ if (Character.isDigit(c)) {
+ sb.append(c);
+ } else {
+ svnum.add(Integer.parseInt(sb.toString()));
+ sb = new StringBuilder();
+ if (c == '+' || c == '-') {
+ break;
+ }
+ }
+ }
+ if (sb.length() > 0) {
+ svnum.add(Integer.parseInt(sb.toString()));
+ }
+
+ if (!svnum.equals(vnum)) {
+ fail("testVersion() equals()", svnum.toString(), vnum.toString());
+ } else {
+ pass();
+ }
+ }
+
+ private static void testEHC(String s0, String s1, boolean eq, boolean eqNO,
+ int cmp, int cmpNO)
+ {
+ Version v0 = Version.parse(s0);
+ Version v1 = Version.parse(s1);
+
+ testEquals(v0, v1, eq);
+ testEqualsNO(v0, v1, eqNO);
+
+ testHashCode(v0, v1, eq);
+
+ testCompare(v0, v1, cmp);
+ testCompareNO(v0, v1, cmpNO);
+ }
+
+ private static void testEqualsNO(Version v0, Version v1, boolean eq) {
+ if ((eq && !v0.equalsIgnoreOpt(v1))
+ || (!eq && v0.equalsIgnoreOpt(v1))) {
+ fail("equalsIgnoreOpt() " + Boolean.toString(eq),
+ v0.toString(), v1.toString());
+ } else {
+ pass();
+ }
+ }
+
+ private static void testEquals(Version v0, Version v1, boolean eq) {
+ if ((eq && !v0.equals(v1)) || (!eq && v0.equals(v1))) {
+ fail("equals() " + Boolean.toString(eq),
+ v0.toString(), v1.toString());
+ } else {
+ pass();
+ }
+ }
+
+ private static void testHashCode(Version v0, Version v1, boolean eq) {
+ int h0 = v0.hashCode();
+ int h1 = v1.hashCode();
+ if (eq) {
+ testInt(h0, h1);
+ } else if (h0 == h1) {
+ fail(String.format("hashCode() %s", h0),
+ Integer.toString(h0),
+ Integer.toString(h1));
+ } else { // !eq && (h0 != h1)
+ pass();
+ }
+ }
+
+ private static void testCompareNO(Version v0, Version v1, int compare)
+ {
+ try {
+ Method m = VERSION.getMethod("compareToIgnoreOpt", VERSION);
+ int cmp = (int) m.invoke(v0, v1);
+ checkCompare(v0, v1, compare, cmp);
+ } catch (IllegalAccessException | InvocationTargetException |
+ NoSuchMethodException ex) {
+ fail(String.format("compareToIgnoreOpt() invocation: %s",
+ ex.getClass()),
+ null);
+ }
+ }
+
+ private static void testCompare(Version v0, Version v1, int compare) {
+ try {
+ Method m = VERSION.getMethod("compareTo", VERSION);
+ int cmp = (int) m.invoke(v0, v1);
+ checkCompare(v0, v1, compare, cmp);
+ } catch (IllegalAccessException | InvocationTargetException |
+ NoSuchMethodException ex) {
+ fail(String.format("compareTo() invocation: %s", ex.getClass()),
+ null);
+ }
+ }
+
+ private static void checkCompare(Version v0, Version v1,
+ int compare, int cmp)
+ {
+ if (((cmp == 0) && (compare == 0))
+ || (compare == (cmp / Math.abs(cmp == 0 ? 1 : cmp)))) {
+ pass();
+ } else {
+ fail(String.format("compare() (cmp = %s) (compare = %s)",
+ cmp, compare),
+ v0.toString(), v1.toString());
+ }
+ }
+
+ private static int fail = 0;
+ private static int pass = 0;
+
+ private static Throwable first;
+
+ static void pass() {
+ pass++;
+ }
+
+ static void fail(String fs, Class ex) {
+ String s = "'" + fs + "'";
+ if (ex != null)
+ s += ": " + ex.getName() + " not thrown";
+ if (first == null)
+ setFirst(s);
+ System.err.println("FAILED: " + s);
+ fail++;
+ }
+
+ static void fail(String t, String exp, String got) {
+ String s = t + ": Expected '" + exp + "', got '" + got + "'";
+ if (first == null)
+ setFirst(s);
+ System.err.println("FAILED: " + s);
+ fail++;
+ }
+
+ private static void setFirst(String s) {
+ try {
+ throw new RuntimeException(s);
+ } catch (RuntimeException x) {
+ first = x;
+ }
+ }
+}
--- a/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8132734
+ * @bug 8132734 8144062
* @summary Test the extended API and the aliasing additions in JarFile that
* support multi-release jar files
* @library /lib/testlibrary/java/util/jar
@@ -39,7 +39,6 @@
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import jdk.Version;
import static java.util.jar.JarFile.Release;
@@ -51,7 +50,7 @@
public class MultiReleaseJarAPI {
- static final int MAJOR_VERSION = Version.current().major();
+ static final int MAJOR_VERSION = Runtime.version().major();
String userdir = System.getProperty("user.dir",".");
CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars();
--- a/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarIterators.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarIterators.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8132734
+ * @bug 8132734 8144062
* @summary Test the extended API and the aliasing additions in JarFile that
* support multi-release jar files
* @library /lib/testlibrary/java/util/jar
@@ -42,7 +42,6 @@
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;
-import jdk.Version;
import static java.util.jar.JarFile.Release;
@@ -54,7 +53,7 @@
public class MultiReleaseJarIterators {
- static final int MAJOR_VERSION = Version.current().major();
+ static final int MAJOR_VERSION = Runtime.version().major();
String userdir = System.getProperty("user.dir", ".");
File unversioned = new File(userdir, "unversioned.jar");
--- a/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarProperties.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarProperties.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8132734
+ * @bug 8132734 8144062
* @summary Test the System properties for JarFile that support multi-release jar files
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars
@@ -54,7 +54,6 @@
import java.nio.file.Files;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import jdk.Version;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -63,7 +62,7 @@
public class MultiReleaseJarProperties {
- static final int MAJOR_VERSION = Version.current().major();
+ static final int MAJOR_VERSION = Runtime.version().major();
final static int ROOTVERSION = 8; // magic number from knowledge of internals
final static String userdir = System.getProperty("user.dir", ".");
--- a/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarSecurity.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarSecurity.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8132734
+ * @bug 8132734 8144062
* @summary Test potential security related issues
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars
@@ -40,7 +40,6 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipFile;
-import jdk.Version;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -49,7 +48,7 @@
public class MultiReleaseJarSecurity {
- static final int MAJOR_VERSION = Version.current().major();
+ static final int MAJOR_VERSION = Runtime.version().major();
String userdir = System.getProperty("user.dir",".");
File multirelease = new File(userdir, "multi-release.jar");
--- a/jdk/test/jdk/Version/Basic.java Thu May 19 19:46:20 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,400 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @summary Unit test for jdk.Version.
- * @bug 8072379
- */
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.math.BigInteger;
-import java.util.stream.Collectors;
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-import jdk.Version;
-import static java.lang.System.out;
-
-public class Basic {
- private static final Class<? extends Throwable> IAE
- = IllegalArgumentException.class;
- private static final Class<? extends Throwable> NPE
- = NullPointerException.class;
- private static final Class<? extends Throwable> NFE
- = NumberFormatException.class;
- private static final Class<?> VERSION = Version.class;
-
- private static final BigInteger TOO_BIG
- = (BigInteger.valueOf(Integer.MAX_VALUE)).add(BigInteger.ONE);
- private static final String TOO_BIG_STR = TOO_BIG.toString();
-
- public static void main(String ... args) {
-
- //// Tests for parse(), major(), minor(), security(), pre(),
- //// build(), opt(), version(), toString()
- // v M m sec pre bld opt
-
- // $VNUM
- test("9", 9, 0, 0, "", 0, "");
- test("9.1", 9, 1, 0, "", 0, "");
- test("9.0.1", 9, 0, 1, "", 0, "");
- test("404.1.2", 404, 1, 2, "", 0, "");
- test("9.1.2.3", 9, 1, 2, "", 0, "");
- test("1000.0.0.0.0.0.99999999", 1000, 0, 0, "", 0, "");
-
- tryCatch(null, NPE);
- tryCatch("", IAE);
- tryCatch("foo", IAE);
- tryCatch("7a", IAE);
- tryCatch("0", IAE);
- tryCatch("09", IAE);
- tryCatch("9.0", IAE);
- tryCatch("9.0.", IAE);
- tryCatch("1.9,1", IAE);
- tryCatch(TOO_BIG_STR, NFE);
-
- // $PRE
- test("9-ea", 9, 0, 0, "ea", 0, "");
- test("9-internal", 9, 0, 0, "internal", 0, "");
- test("9-0", 9, 0, 0, "0", 0, "");
- test("9.2.7-8", 9, 2, 7, "8", 0, "");
- test("1-ALL", 1, 0, 0, "ALL", 0, "");
- test("2.3.4.5-1a", 2, 3, 4, "1a", 0, "");
- test("1-" + TOO_BIG_STR, 1, 0, 0, TOO_BIG_STR, 0, "");
-
- tryCatch("9:-ea", IAE);
- tryCatch("3.14159-", IAE);
- tryCatch("3.14159-%", IAE);
-
- // $BUILD
- test("9+0", 9, 0, 0, "", 0, "");
- test("3.14+9999900", 3, 14, 0, "", 9999900, "");
- test("9-pre+105", 9, 0, 0, "pre", 105, "");
- test("6.0.42-8beta+4", 6, 0, 42, "8beta", 4, "");
-
- tryCatch("9+", IAE);
- tryCatch("7+a", IAE);
- tryCatch("9+00", IAE);
- tryCatch("4.2+01", IAE);
- tryCatch("4.2+1a", IAE);
- tryCatch("1+" + TOO_BIG_STR, NFE);
-
- // $OPT
- test("9+-foo", 9, 0, 0, "", 0, "foo");
- test("9-pre-opt", 9, 0, 0, "pre", 0, "opt");
- test("42+---bar", 42, 0, 0, "", 0, "--bar");
- test("2.91+-8061493-", 2, 91, 0, "", 0, "8061493-");
- test("24+-foo.bar", 24, 0, 0, "", 0, "foo.bar");
- test("9-ribbit+17-...", 9, 0, 0, "ribbit", 17, "...");
- test("7+1-" + TOO_BIG_STR, 7,0, 0, "", 1, TOO_BIG_STR);
-
- tryCatch("9-pre+-opt", IAE);
- tryCatch("1.4142+-", IAE);
- tryCatch("2.9979+-%", IAE);
-
- //// Test for current()
- testCurrent();
-
- //// Test for equals{IgnoreOpt}?(), hashCode(), compareTo{IgnoreOpt}?()
- // compare: after "<" == -1, equal == 0, before ">" == 1
- // v0 v1 eq eqNO cmp cmpNO
- testEHC("9", "9", true, true, 0, 0);
-
- testEHC("8", "9", false, false, -1, -1);
- testEHC("9", "10", false, false, -1, -1);
- testEHC("9", "8", false, false, 1, 1);
-
- // $OPT comparison
- testEHC("9", "9+-oink", false, true, -1, 0);
- testEHC("9+-ribbit", "9+-moo", false, true, 1, 0);
- testEHC("9-quack+3-ribbit",
- "9-quack+3-moo", false, true, 1, 0);
- testEHC("9.1+7", "9.1+7-moo-baa-la", false, true, -1, 0);
-
- // numeric vs. non-numeric $PRE
- testEHC("9.1.1.2-2a", "9.1.1.2-12", false, false, 1, 1);
- testEHC("9.1.1.2-12", "9.1.1.2-4", false, false, 1, 1);
-
- testEHC("27.16", "27.16+120", false, false, 1, 1);
- testEHC("10", "10-ea", false, false, 1, 1);
- testEHC("10.1+1", "10.1-ea+1", false, false, 1, 1);
- testEHC("10.0.1+22", "10.0.1+21", false, false, 1, 1);
-
- // numeric vs. non-numeric $PRE
- testEHC("9.1.1.2-12", "9.1.1.2-a2", false, false, -1, -1);
- testEHC("9.1.1.2-1", "9.1.1.2-4", false, false, -1, -1);
-
- testEHC("9-internal", "9", false, false, -1, -1);
- testEHC("9-ea+120", "9+120", false, false, -1, -1);
- testEHC("9-ea+120", "9+120", false, false, -1, -1);
- testEHC("9+101", "9", false, false, -1, -1);
- testEHC("9+101", "9+102", false, false, -1, -1);
- testEHC("1.9-ea", "9-ea", false, false, -1, -1);
-
- if (fail != 0)
- throw new RuntimeException((fail + pass) + " tests: "
- + fail + " failure(s), first", first);
- else
- out.println("all " + (fail + pass) + " tests passed");
-
- }
-
- private static void test(String s, Integer major, Integer minor,
- Integer sec, String pre, Integer build,
- String opt)
- {
- Version v = testParse(s);
-
- testStr(v.toString(), s);
-
- testInt(v.major(), major);
- testInt(v.minor(), minor);
- testInt(v.security(), sec);
- testStr((v.pre().isPresent() ? v.pre().get() : ""), pre);
- testInt((v.build().isPresent() ? v.build().get() : 0), build);
- testStr((v.optional().isPresent() ? v.optional().get() : ""), opt);
-
- testVersion(v.version(), s);
- }
-
- private static Version testParse(String s) {
- Version v = Version.parse(s);
- pass();
- return v;
- }
-
- private static void testInt(int got, int exp) {
- if (got != exp) {
- fail("testInt()", Integer.toString(exp), Integer.toString(got));
- } else {
- pass();
- }
- }
-
- private static void testStr(String got, String exp) {
- if (!got.equals(exp)) {
- fail("testStr()", exp, got);
- } else {
- pass();
- }
- }
-
- private static void tryCatch(String s, Class<? extends Throwable> ex) {
- Throwable t = null;
- try {
- Version.parse(s);
- } catch (Throwable x) {
- if (ex.isAssignableFrom(x.getClass())) {
- t = x;
- } else
- x.printStackTrace();
- }
- if ((t == null) && (ex != null))
- fail(s, ex);
- else
- pass();
- }
-
- private static void testCurrent() {
- Version current = Version.current();
- String javaVer = System.getProperty("java.version");
-
- // java.version == $VNUM(\-$PRE)
- String [] ver = javaVer.split("-");
- List<Integer> javaVerVNum
- = Arrays.stream(ver[0].split("\\."))
- .map(v -> Integer.parseInt(v))
- .collect(Collectors.toList());
- if (!javaVerVNum.equals(current.version())) {
- fail("testCurrent() version()", javaVerVNum.toString(),
- current.version().toString());
- } else {
- pass();
- }
-
- Optional<String> javaVerPre
- = (ver.length == 2)
- ? Optional.ofNullable(ver[1])
- : Optional.empty();
- if (!javaVerPre.equals(current.pre())) {
- fail("testCurrent() pre()", javaVerPre.toString(),
- current.pre().toString());
- } else {
- pass();
- }
-
- testEHC(current.toString(), javaVer, true, true, 0, 0);
- }
-
- private static void testVersion(List<Integer> vnum, String s) {
- List<Integer> svnum = new ArrayList<Integer>();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < s.length(); i++) {
- Character c = s.charAt(i);
- if (Character.isDigit(c)) {
- sb.append(c);
- } else {
- svnum.add(Integer.parseInt(sb.toString()));
- sb = new StringBuilder();
- if (c == '+' || c == '-') {
- break;
- }
- }
- }
- if (sb.length() > 0) {
- svnum.add(Integer.parseInt(sb.toString()));
- }
-
- if (!svnum.equals(vnum)) {
- fail("testVersion() equals()", svnum.toString(), vnum.toString());
- } else {
- pass();
- }
- }
-
- private static void testEHC(String s0, String s1, boolean eq, boolean eqNO,
- int cmp, int cmpNO)
- {
- Version v0 = Version.parse(s0);
- Version v1 = Version.parse(s1);
-
- testEquals(v0, v1, eq);
- testEqualsNO(v0, v1, eqNO);
-
- testHashCode(v0, v1, eq);
-
- testCompare(v0, v1, cmp);
- testCompareNO(v0, v1, cmpNO);
- }
-
- private static void testEqualsNO(Version v0, Version v1, boolean eq) {
- if ((eq && !v0.equalsIgnoreOpt(v1))
- || (!eq && v0.equalsIgnoreOpt(v1))) {
- fail("equalsIgnoreOpt() " + Boolean.toString(eq),
- v0.toString(), v1.toString());
- } else {
- pass();
- }
- }
-
- private static void testEquals(Version v0, Version v1, boolean eq) {
- if ((eq && !v0.equals(v1)) || (!eq && v0.equals(v1))) {
- fail("equals() " + Boolean.toString(eq),
- v0.toString(), v1.toString());
- } else {
- pass();
- }
- }
-
- private static void testHashCode(Version v0, Version v1, boolean eq) {
- int h0 = v0.hashCode();
- int h1 = v1.hashCode();
- if (eq) {
- testInt(h0, h1);
- } else if (h0 == h1) {
- fail(String.format("hashCode() %s", h0),
- Integer.toString(h0),
- Integer.toString(h1));
- } else { // !eq && (h0 != h1)
- pass();
- }
- }
-
- private static void testCompareNO(Version v0, Version v1, int compare)
- {
- try {
- Method m = VERSION.getMethod("compareToIgnoreOpt", VERSION);
- int cmp = (int) m.invoke(v0, v1);
- checkCompare(v0, v1, compare, cmp);
- } catch (IllegalAccessException | InvocationTargetException |
- NoSuchMethodException ex) {
- fail(String.format("compareToIgnoreOpt() invocation: %s",
- ex.getClass()),
- null);
- }
- }
-
- private static void testCompare(Version v0, Version v1, int compare) {
- try {
- Method m = VERSION.getMethod("compareTo", VERSION);
- int cmp = (int) m.invoke(v0, v1);
- checkCompare(v0, v1, compare, cmp);
- } catch (IllegalAccessException | InvocationTargetException |
- NoSuchMethodException ex) {
- fail(String.format("compareTo() invocation: %s", ex.getClass()),
- null);
- }
- }
-
- private static void checkCompare(Version v0, Version v1,
- int compare, int cmp)
- {
- if (((cmp == 0) && (compare == 0))
- || (compare == (cmp / Math.abs(cmp == 0 ? 1 : cmp)))) {
- pass();
- } else {
- fail(String.format("compare() (cmp = %s) (compare = %s)",
- cmp, compare),
- v0.toString(), v1.toString());
- }
- }
-
- private static int fail = 0;
- private static int pass = 0;
-
- private static Throwable first;
-
- static void pass() {
- pass++;
- }
-
- static void fail(String fs, Class ex) {
- String s = "'" + fs + "'";
- if (ex != null)
- s += ": " + ex.getName() + " not thrown";
- if (first == null)
- setFirst(s);
- System.err.println("FAILED: " + s);
- fail++;
- }
-
- static void fail(String t, String exp, String got) {
- String s = t + ": Expected '" + exp + "', got '" + got + "'";
- if (first == null)
- setFirst(s);
- System.err.println("FAILED: " + s);
- fail++;
- }
-
- private static void setFirst(String s) {
- try {
- throw new RuntimeException(s);
- } catch (RuntimeException x) {
- first = x;
- }
- }
-}
--- a/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8144355
+ * @bug 8144355 8144062
* @summary Test aliasing additions to ZipFileSystem for multi-release jar files
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars
@@ -34,17 +34,17 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
+import java.lang.Runtime.Version;
import java.net.URI;
import java.nio.file.*;
import java.util.HashMap;
import java.util.Map;
-import jdk.Version;
import org.testng.Assert;
import org.testng.annotations.*;
public class MultiReleaseJarTest {
- final private int MAJOR_VERSION = Version.current().major();
+ final private int MAJOR_VERSION = Runtime.version().major();
final private String userdir = System.getProperty("user.dir",".");
final private Map<String,String> stringEnv = new HashMap<>();
--- a/jdk/test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java Thu May 19 19:46:20 2016 +0000
+++ b/jdk/test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java Thu May 19 20:14:17 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8132734
+ * @bug 8132734 8144062
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer
@@ -43,8 +43,6 @@
import java.nio.file.Paths;
import java.util.jar.JarFile;
-import jdk.Version;
-
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -94,7 +92,7 @@
public void testRuntimeVersioning(String style, String file) throws Exception {
String urlFile = "jar:file:" + file + "!/";
String baseUrlEntry = urlFile + "version/Version.java";
- String rtreturn = "return " + Version.current().major();
+ String rtreturn = "return " + Runtime.version().major();
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
// #runtime is "magic" for a multi-release jar, but not for unversioned jar
@@ -109,7 +107,7 @@
if (style.equals("unversioned")) return;
// direct access to versioned entry
- String versUrlEntry = urlFile + "META-INF/versions/" + Version.current().major()
+ String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major()
+ "/version/Version.java";
Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn));
// adding any fragment does not change things
@@ -187,7 +185,7 @@
MethodType mt = MethodType.methodType(int.class);
MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt);
Assert.assertEquals((int)mh.invoke(vcls.newInstance()),
- style.equals("unversioned") ? 8 : Version.current().major());
+ style.equals("unversioned") ? 8 : Runtime.version().major());
// now get a resource and verify that we don't have a fragment attached
URL vclsUrl = vcls.getResource("/version/Version.class");
@@ -206,7 +204,7 @@
if (style.equals("unversioned")) {
suffix = ".jar!/version/Version.class";
} else {
- suffix = ".jar!/META-INF/versions/" + Version.current().major()
+ suffix = ".jar!/META-INF/versions/" + Runtime.version().major()
+ "/version/Version.class";
}
Assert.assertTrue(rep.endsWith(suffix));