Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/internal/Versions.java
41159 views
1
/*
2
* Copyright (c) 2020, 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.javadoc.internal;
27
28
import java.util.ResourceBundle;
29
import java.util.stream.Collectors;
30
31
import static java.util.ResourceBundle.getBundle;
32
33
public final class Versions {
34
35
private Versions() { throw new AssertionError(); }
36
37
/**
38
* Returns the version of the {@code javadoc} tool and the Standard doclet.
39
*
40
* <p> This is typically the same as the version of the JDK platform being
41
* used to run the tool, but may be different when running the tool on an
42
* older version of the platform.
43
*
44
* @throws RuntimeException in an unlikely event of the version info
45
* not being available
46
*
47
* @apiNote This method does not return {@code null}, has the return type of
48
* {@code Optional<Runtime.Version>}, or throw a checked exception. Those
49
* would warp the API to cater for something that is probably a result of
50
* a build error anyway. Hence, {@code RuntimeException}.
51
*
52
* @return the version
53
*/
54
public static Runtime.Version javadocVersion() throws RuntimeException {
55
/*
56
* The "jdk.javadoc.internal.tool.resources.version" resource bundle is
57
* non-localized and represented by a class compiled from a source like this:
58
*
59
* $ cat build/.../support/gensrc/jdk.javadoc/jdk/javadoc/internal/tool/resources/version.java
60
* package jdk.javadoc.internal.tool.resources;
61
*
62
* public final class version extends java.util.ListResourceBundle {
63
* protected final Object[][] getContents() {
64
* return new Object[][] {
65
* { "full", "15-internal+0-2020-06-02-1426246.duke..." },
66
* { "jdk", "15" },
67
* { "release", "15-internal" },
68
* };
69
* }
70
* }
71
*
72
* The string keyed by "full" should be parseable by Runtime.Version.parse()
73
*/
74
ResourceBundle bundle = getBundle("jdk.javadoc.internal.tool.resources.version");
75
return Runtime.Version.parse(bundle.getString("full"));
76
}
77
78
/**
79
* Returns a short string representation of the provided version.
80
*
81
* <p> The string contains the dotted representation of the version number,
82
* followed by the prerelease info, if any.
83
* For example, "15", "15.1", "15.0.1", "15-internal".
84
*
85
* @return a short string representation of the provided version
86
*
87
* @throws NullPointerException if {@code v == null}
88
*/
89
public static String shortVersionStringOf(Runtime.Version v) {
90
String svstr = v.version().stream()
91
.map(Object::toString)
92
.collect(Collectors.joining("."));
93
if (v.pre().isPresent()) {
94
svstr += "-" + v.pre().get();
95
}
96
return svstr;
97
}
98
99
/**
100
* Returns a full string representation of the provided version.
101
*
102
* <p> Examples of strings returned from this method are "14+36-1461" and
103
* "15-internal+0-2020-06-02-1426246.duke...".
104
*
105
* @return a full string representation of the provided version
106
*
107
* @throws NullPointerException if {@code v == null}
108
*/
109
public static String fullVersionStringOf(Runtime.Version v) {
110
return v.toString();
111
}
112
}
113
114