Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/internal/Versions.java
41159 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.javadoc.internal;2627import java.util.ResourceBundle;28import java.util.stream.Collectors;2930import static java.util.ResourceBundle.getBundle;3132public final class Versions {3334private Versions() { throw new AssertionError(); }3536/**37* Returns the version of the {@code javadoc} tool and the Standard doclet.38*39* <p> This is typically the same as the version of the JDK platform being40* used to run the tool, but may be different when running the tool on an41* older version of the platform.42*43* @throws RuntimeException in an unlikely event of the version info44* not being available45*46* @apiNote This method does not return {@code null}, has the return type of47* {@code Optional<Runtime.Version>}, or throw a checked exception. Those48* would warp the API to cater for something that is probably a result of49* a build error anyway. Hence, {@code RuntimeException}.50*51* @return the version52*/53public static Runtime.Version javadocVersion() throws RuntimeException {54/*55* The "jdk.javadoc.internal.tool.resources.version" resource bundle is56* non-localized and represented by a class compiled from a source like this:57*58* $ cat build/.../support/gensrc/jdk.javadoc/jdk/javadoc/internal/tool/resources/version.java59* package jdk.javadoc.internal.tool.resources;60*61* public final class version extends java.util.ListResourceBundle {62* protected final Object[][] getContents() {63* return new Object[][] {64* { "full", "15-internal+0-2020-06-02-1426246.duke..." },65* { "jdk", "15" },66* { "release", "15-internal" },67* };68* }69* }70*71* The string keyed by "full" should be parseable by Runtime.Version.parse()72*/73ResourceBundle bundle = getBundle("jdk.javadoc.internal.tool.resources.version");74return Runtime.Version.parse(bundle.getString("full"));75}7677/**78* Returns a short string representation of the provided version.79*80* <p> The string contains the dotted representation of the version number,81* followed by the prerelease info, if any.82* For example, "15", "15.1", "15.0.1", "15-internal".83*84* @return a short string representation of the provided version85*86* @throws NullPointerException if {@code v == null}87*/88public static String shortVersionStringOf(Runtime.Version v) {89String svstr = v.version().stream()90.map(Object::toString)91.collect(Collectors.joining("."));92if (v.pre().isPresent()) {93svstr += "-" + v.pre().get();94}95return svstr;96}9798/**99* Returns a full string representation of the provided version.100*101* <p> Examples of strings returned from this method are "14+36-1461" and102* "15-internal+0-2020-06-02-1426246.duke...".103*104* @return a full string representation of the provided version105*106* @throws NullPointerException if {@code v == null}107*/108public static String fullVersionStringOf(Runtime.Version v) {109return v.toString();110}111}112113114