Skip to content

Commit

Permalink
8303476: Add the runtime version in the release file of a JDK image
Browse files Browse the repository at this point in the history
Backport-of: 32247c336a189a40f696626a2578c65535ef6376
  • Loading branch information
GoeLin committed May 10, 2023
1 parent 1f601e9 commit 4548929
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions make/ReleaseFile.gmk
Expand Up @@ -51,6 +51,7 @@ define create-info-file
$(if $(VENDOR_VERSION_STRING), \
$(call info-file-item, "IMPLEMENTOR_VERSION", "$(VENDOR_VERSION_STRING)"))
$(call info-file-item, "JAVA_VERSION_DATE", "$(VERSION_DATE)")
$(call info-file-item, "JAVA_RUNTIME_VERSION", "$(VERSION_STRING)")
$(call info-file-item, "OS_NAME", "$(RELEASE_FILE_OS_NAME)")
$(call info-file-item, "OS_ARCH", "$(RELEASE_FILE_OS_ARCH)")
$(call info-file-item, "LIBC", "$(RELEASE_FILE_LIBC)")
Expand Down
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,9 +23,9 @@

/*
* @test
* @bug 8193660
* @summary Check SOURCE line in "release" file for closedjdk
* @run main CheckSource
* @bug 8193660 8303476
* @summary Check SOURCE line and JAVA_RUNTIME_VERSION in "release" file
* @run main CheckReleaseFile
*/

import java.io.BufferedReader;
Expand All @@ -37,18 +36,21 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckSource {
public class CheckReleaseFile {

public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\+?";

CheckSource(String dataFile, boolean isOpenJDK) {
private final boolean isOpenJDK;
CheckReleaseFile(String dataFile, boolean isOpenJDK) {
this.isOpenJDK = isOpenJDK;
// Read data files
readFile(dataFile, isOpenJDK);
readFile(dataFile);
}

private void readFile(String fileName, boolean isOpenJDK) {
private void readFile(String fileName) {
String fishForSOURCE = null;
String implementor = null;
String runtimeVersion = null;

File file = new File(fileName);

Expand Down Expand Up @@ -78,6 +80,12 @@ private void readFile(String fileName, boolean isOpenJDK) {
implementor = readIn;
continue;
}

// grab JAVA_RUNTIME_VERSION line
if (readIn.startsWith("JAVA_RUNTIME_VERSION=")) {
runtimeVersion = readIn;
continue;
}
}
} catch (FileNotFoundException fileExcept) {
throw new RuntimeException("File " + fileName +
Expand All @@ -91,6 +99,23 @@ private void readFile(String fileName, boolean isOpenJDK) {
if (fishForSOURCE == null) {
throw new RuntimeException("SOURCE line was not found!");
}

// Check if implementor is Oracle
boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation");
checkSource(fishForSOURCE, isOracle);

if (runtimeVersion == null) {
throw new RuntimeException("JAVA_RUNTIME_VERSION line was not found!");
}
String expected = "JAVA_RUNTIME_VERSION=\"" + Runtime.version() + "\"";
if (!expected.equals(runtimeVersion)) {
throw new RuntimeException("Mismatched runtime version: " +
runtimeVersion + " expected: " + expected);
}
}

private void checkSource(String fishForSOURCE, boolean isOracle) {

System.out.println("The source string found: " + fishForSOURCE);

// Extract the value of SOURCE=
Expand All @@ -101,8 +126,6 @@ private void readFile(String fileName, boolean isOpenJDK) {
}
String valueString = valueMatcher.group(1);

// Check if implementor is Oracle
boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation");

String[] values = valueString.split(" ");

Expand Down Expand Up @@ -144,6 +167,6 @@ public static void main(String args[]) {
System.out.println("JDK Path : " + jdkPath);
System.out.println("Runtime Name : " + runtime);

new CheckSource(jdkPath + "/release", runtime.contains("OpenJDK"));
new CheckReleaseFile(jdkPath + "/release", runtime.contains("OpenJDK"));
}
}

1 comment on commit 4548929

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.