Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/compatibility/JdkInfo.java
38853 views
1
/*
2
* Copyright (c) 2017, 2019, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* It represents a JDK with some specific attributes.
26
* If two JdkInfo instances have the same version value, the instances are
27
* regarded as equivalent.
28
*/
29
public class JdkInfo {
30
31
public final String jdkPath;
32
33
public final String version;
34
public final String supportedProtocols;
35
public final String supportedCipherSuites;
36
public final boolean supportsSNI;
37
public final boolean supportsALPN;
38
39
public JdkInfo(String jdkPath) {
40
this.jdkPath = jdkPath;
41
42
String output = jdkAttributes(jdkPath);
43
if (output == null || output.trim().isEmpty()) {
44
throw new RuntimeException(
45
"Cannot determine the JDK attributes: " + jdkPath);
46
}
47
48
String[] attributes = Utils.split(output, Utils.PARAM_DELIMITER);
49
version = attributes[0].replaceAll(".*=", "");
50
supportedProtocols = attributes[1].replaceAll(".*=", "");
51
supportedCipherSuites = attributes[2].replaceAll(".*=", "");
52
supportsSNI = Boolean.valueOf(attributes[3].replaceAll(".*=", ""));
53
supportsALPN = Boolean.valueOf(attributes[4].replaceAll(".*=", ""));
54
}
55
56
// Determines the specific attributes for the specified JDK.
57
private static String jdkAttributes(String jdkPath) {
58
return ProcessUtils.java(jdkPath, null, JdkUtils.class).getOutput();
59
}
60
61
@Override
62
public int hashCode() {
63
return version == null ? 0 : version.hashCode();
64
}
65
66
@Override
67
public boolean equals(Object obj) {
68
if (this == obj) {
69
return true;
70
}
71
if (obj == null) {
72
return false;
73
}
74
if (getClass() != obj.getClass()) {
75
return false;
76
}
77
JdkInfo other = (JdkInfo) obj;
78
if (version == null) {
79
if (other.version != null) {
80
return false;
81
}
82
} else if (!version.equals(other.version)) {
83
return false;
84
}
85
return true;
86
}
87
88
public boolean supportsProtocol(Protocol protocol) {
89
return supportedProtocols.contains(protocol.name);
90
}
91
92
public boolean supportsCipherSuite(CipherSuite cipherSuite) {
93
return supportedCipherSuites.contains(cipherSuite.name());
94
}
95
}
96
97