Path: blob/master/test/jdk/build/releaseFile/CheckSource.java
41145 views
1/*2* Copyright (c) 2018, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test26* @bug 819366027* @summary Check SOURCE line in "release" file for closedjdk28* @run main CheckSource29*/3031import java.io.BufferedReader;32import java.io.File;33import java.io.FileReader;34import java.io.FileNotFoundException;35import java.io.IOException;36import java.util.regex.Matcher;37import java.util.regex.Pattern;3839public class CheckSource {4041public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\+?";4243CheckSource(String dataFile, boolean isOpenJDK) {44// Read data files45readFile(dataFile, isOpenJDK);46}4748private void readFile(String fileName, boolean isOpenJDK) {49String fishForSOURCE = null;50String implementor = null;5152File file = new File(fileName);5354// open the stream to read in for Entries55try (BufferedReader buffRead =56new BufferedReader(new FileReader(fileName))) {5758// this is the string read59String readIn;6061// let's read some strings!62while ((readIn = buffRead.readLine()) != null) {63readIn = readIn.trim();6465// throw out blank lines66if (readIn.length() == 0)67continue;6869// grab SOURCE line70if (readIn.startsWith("SOURCE=")) {71fishForSOURCE = readIn;72continue;73}7475// grab IMPLEMENTOR line76if (readIn.startsWith("IMPLEMENTOR=")) {77implementor = readIn;78continue;79}80}81} catch (FileNotFoundException fileExcept) {82throw new RuntimeException("File " + fileName +83" not found reading data!", fileExcept);84} catch (IOException ioExcept) {85throw new RuntimeException("Unexpected problem reading data!",86ioExcept);87}8889// was SOURCE even found?90if (fishForSOURCE == null) {91throw new RuntimeException("SOURCE line was not found!");92}93System.out.println("The source string found: " + fishForSOURCE);9495// Extract the value of SOURCE=96Pattern valuePattern = Pattern.compile("SOURCE=\"(.*)\"");97Matcher valueMatcher = valuePattern.matcher(fishForSOURCE);98if (!valueMatcher.matches()) {99throw new RuntimeException("SOURCE string has bad format, should be SOURCE=\"<value>\"");100}101String valueString = valueMatcher.group(1);102103// Check if implementor is Oracle104boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation");105106String[] values = valueString.split(" ");107108// First value MUST start with ".:" regardless of Oracle or OpenJDK109String rootRegexp = "\\." + SRC_HASH_REGEXP;110if (!values[0].matches(rootRegexp)) {111throw new RuntimeException("The test failed, first element did not match regexp: " + rootRegexp);112}113114// If it's an Oracle build, it can be either OpenJDK or OracleJDK. Other115// builds may have any number of additional elements in any format.116if (isOracle) {117if (isOpenJDK) {118if (values.length != 1) {119throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +120" Should be 1 for Oracle built OpenJDK.");121}122} else {123if (values.length != 2) {124throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +125" Should be 2 for OracleJDK.");126}127// Second value MUST start with "open:" for OracleJDK128String openRegexp = "open" + SRC_HASH_REGEXP;129if (!values[1].matches(openRegexp)) {130throw new RuntimeException("The test failed, second element did not match regexp: " + openRegexp);131}132}133}134135// Everything was fine136System.out.println("The test passed!");137}138139public static void main(String args[]) {140String jdkPath = System.getProperty("test.jdk");141String runtime = System.getProperty("java.runtime.name");142143System.out.println("JDK Path : " + jdkPath);144System.out.println("Runtime Name : " + runtime);145146new CheckSource(jdkPath + "/release", runtime.contains("OpenJDK"));147}148}149150151