Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/compatibility/JdkInfo.java
38853 views
/*1* Copyright (c) 2017, 2019, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* It represents a JDK with some specific attributes.25* If two JdkInfo instances have the same version value, the instances are26* regarded as equivalent.27*/28public class JdkInfo {2930public final String jdkPath;3132public final String version;33public final String supportedProtocols;34public final String supportedCipherSuites;35public final boolean supportsSNI;36public final boolean supportsALPN;3738public JdkInfo(String jdkPath) {39this.jdkPath = jdkPath;4041String output = jdkAttributes(jdkPath);42if (output == null || output.trim().isEmpty()) {43throw new RuntimeException(44"Cannot determine the JDK attributes: " + jdkPath);45}4647String[] attributes = Utils.split(output, Utils.PARAM_DELIMITER);48version = attributes[0].replaceAll(".*=", "");49supportedProtocols = attributes[1].replaceAll(".*=", "");50supportedCipherSuites = attributes[2].replaceAll(".*=", "");51supportsSNI = Boolean.valueOf(attributes[3].replaceAll(".*=", ""));52supportsALPN = Boolean.valueOf(attributes[4].replaceAll(".*=", ""));53}5455// Determines the specific attributes for the specified JDK.56private static String jdkAttributes(String jdkPath) {57return ProcessUtils.java(jdkPath, null, JdkUtils.class).getOutput();58}5960@Override61public int hashCode() {62return version == null ? 0 : version.hashCode();63}6465@Override66public boolean equals(Object obj) {67if (this == obj) {68return true;69}70if (obj == null) {71return false;72}73if (getClass() != obj.getClass()) {74return false;75}76JdkInfo other = (JdkInfo) obj;77if (version == null) {78if (other.version != null) {79return false;80}81} else if (!version.equals(other.version)) {82return false;83}84return true;85}8687public boolean supportsProtocol(Protocol protocol) {88return supportedProtocols.contains(protocol.name);89}9091public boolean supportsCipherSuite(CipherSuite cipherSuite) {92return supportedCipherSuites.contains(cipherSuite.name());93}94}959697