8321557: Move SOURCE line verification for OracleJDK out of OpenJDK

Reviewed-by: ihse
This commit is contained in:
Erik Joelsson 2023-12-12 21:31:41 +00:00
parent ac07355f55
commit 5463c9cd9a

View File

@ -29,34 +29,35 @@
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class CheckReleaseFile { public class CheckReleaseFile {
public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\+?"; public static final String SRC_HASH_REGEXP = ":git:[a-z0-9]*\\+?";
private final boolean isOpenJDK; public static void main(String args[]) throws IOException {
CheckReleaseFile(String dataFile, boolean isOpenJDK) { String jdkPath = System.getProperty("test.jdk");
this.isOpenJDK = isOpenJDK; String runtime = System.getProperty("java.runtime.name");
// Read data files
readFile(dataFile); System.out.println("JDK Path : " + jdkPath);
System.out.println("Runtime Name : " + runtime);
checkReleaseFile(Path.of(jdkPath));
} }
private void readFile(String fileName) { private static void checkReleaseFile(Path javaHome) throws IOException {
String fishForSOURCE = null; String source = null;
String implementor = null;
String runtimeVersion = null; String runtimeVersion = null;
File file = new File(fileName); Path releaseFile = javaHome.resolve("release");
// open the stream to read in for Entries // open the stream to read in for Entries
try (BufferedReader buffRead = try (BufferedReader buffRead = Files.newBufferedReader(releaseFile)) {
new BufferedReader(new FileReader(fileName))) {
// this is the string read // this is the string read
String readIn; String readIn;
@ -71,13 +72,7 @@ public class CheckReleaseFile {
// grab SOURCE line // grab SOURCE line
if (readIn.startsWith("SOURCE=")) { if (readIn.startsWith("SOURCE=")) {
fishForSOURCE = readIn; source = readIn;
continue;
}
// grab IMPLEMENTOR line
if (readIn.startsWith("IMPLEMENTOR=")) {
implementor = readIn;
continue; continue;
} }
@ -87,22 +82,13 @@ public class CheckReleaseFile {
continue; continue;
} }
} }
} catch (FileNotFoundException fileExcept) {
throw new RuntimeException("File " + fileName +
" not found reading data!", fileExcept);
} catch (IOException ioExcept) {
throw new RuntimeException("Unexpected problem reading data!",
ioExcept);
} }
// was SOURCE even found? // was SOURCE even found?
if (fishForSOURCE == null) { if (source == null) {
throw new RuntimeException("SOURCE line was not found!"); throw new RuntimeException("SOURCE line was not found!");
} }
checkSource(source);
// Check if implementor is Oracle
boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation");
checkSource(fishForSOURCE, isOracle);
if (runtimeVersion == null) { if (runtimeVersion == null) {
throw new RuntimeException("JAVA_RUNTIME_VERSION line was not found!"); throw new RuntimeException("JAVA_RUNTIME_VERSION line was not found!");
@ -114,13 +100,13 @@ public class CheckReleaseFile {
} }
} }
private void checkSource(String fishForSOURCE, boolean isOracle) { private static void checkSource(String source) {
System.out.println("The source string found: " + fishForSOURCE); System.out.println("The source string found: " + source);
// Extract the value of SOURCE= // Extract the value of SOURCE=
Pattern valuePattern = Pattern.compile("SOURCE=\"(.*)\""); Pattern valuePattern = Pattern.compile("SOURCE=\"(.*)\"");
Matcher valueMatcher = valuePattern.matcher(fishForSOURCE); Matcher valueMatcher = valuePattern.matcher(source);
if (!valueMatcher.matches()) { if (!valueMatcher.matches()) {
throw new RuntimeException("SOURCE string has bad format, should be SOURCE=\"<value>\""); throw new RuntimeException("SOURCE string has bad format, should be SOURCE=\"<value>\"");
} }
@ -137,36 +123,19 @@ public class CheckReleaseFile {
// If it's an Oracle build, it can be either OpenJDK or OracleJDK. Other // If it's an Oracle build, it can be either OpenJDK or OracleJDK. Other
// builds may have any number of additional elements in any format. // builds may have any number of additional elements in any format.
if (isOracle) { String runtime = System.getProperty("java.runtime.name");
if (isOpenJDK) { String vendor = System.getProperty("java.vendor");
if (values.length != 1) { if (runtime.contains("OpenJDK") && vendor.contains("Oracle Corporation")) {
throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." + System.out.println("Oracle built OpenJDK, verifying SOURCE format");
" Should be 1 for Oracle built OpenJDK."); if (values.length != 1) {
} throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +
} else { " Should be 1 for Oracle built OpenJDK.");
if (values.length != 2) {
throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +
" Should be 2 for OracleJDK.");
}
// Second value MUST start with "open:" for OracleJDK
String openRegexp = "open" + SRC_HASH_REGEXP;
if (!values[1].matches(openRegexp)) {
throw new RuntimeException("The test failed, second element did not match regexp: " + openRegexp);
}
} }
} else {
System.out.println("Not Oracle built OpenJDK, skipping further SOURCE verification");
} }
// Everything was fine // Everything was fine
System.out.println("The test passed!"); System.out.println("The test passed!");
} }
public static void main(String args[]) {
String jdkPath = System.getProperty("test.jdk");
String runtime = System.getProperty("java.runtime.name");
System.out.println("JDK Path : " + jdkPath);
System.out.println("Runtime Name : " + runtime);
new CheckReleaseFile(jdkPath + "/release", runtime.contains("OpenJDK"));
}
} }