1
-
2
1
/*
3
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
4
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
4
*
6
5
* This code is free software; you can redistribute it and/or modify it
24
23
25
24
/*
26
25
* @test
27
- * @bug 8193660
28
- * @summary Check SOURCE line in "release" file for closedjdk
29
- * @run main CheckSource
26
+ * @bug 8193660 8303476
27
+ * @summary Check SOURCE line and JAVA_RUNTIME_VERSION in "release" file
28
+ * @run main CheckReleaseFile
30
29
*/
31
30
32
31
import java .io .BufferedReader ;
37
36
import java .util .regex .Matcher ;
38
37
import java .util .regex .Pattern ;
39
38
40
- public class CheckSource {
39
+ public class CheckReleaseFile {
41
40
42
41
public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\ +?" ;
43
42
44
- CheckSource (String dataFile , boolean isOpenJDK ) {
43
+ private final boolean isOpenJDK ;
44
+ CheckReleaseFile (String dataFile , boolean isOpenJDK ) {
45
+ this .isOpenJDK = isOpenJDK ;
45
46
// Read data files
46
- readFile (dataFile , isOpenJDK );
47
+ readFile (dataFile );
47
48
}
48
49
49
- private void readFile (String fileName , boolean isOpenJDK ) {
50
+ private void readFile (String fileName ) {
50
51
String fishForSOURCE = null ;
51
52
String implementor = null ;
53
+ String runtimeVersion = null ;
52
54
53
55
File file = new File (fileName );
54
56
@@ -78,6 +80,12 @@ private void readFile(String fileName, boolean isOpenJDK) {
78
80
implementor = readIn ;
79
81
continue ;
80
82
}
83
+
84
+ // grab JAVA_RUNTIME_VERSION line
85
+ if (readIn .startsWith ("JAVA_RUNTIME_VERSION=" )) {
86
+ runtimeVersion = readIn ;
87
+ continue ;
88
+ }
81
89
}
82
90
} catch (FileNotFoundException fileExcept ) {
83
91
throw new RuntimeException ("File " + fileName +
@@ -91,6 +99,23 @@ private void readFile(String fileName, boolean isOpenJDK) {
91
99
if (fishForSOURCE == null ) {
92
100
throw new RuntimeException ("SOURCE line was not found!" );
93
101
}
102
+
103
+ // Check if implementor is Oracle
104
+ boolean isOracle = (implementor != null ) && implementor .contains ("Oracle Corporation" );
105
+ checkSource (fishForSOURCE , isOracle );
106
+
107
+ if (runtimeVersion == null ) {
108
+ throw new RuntimeException ("JAVA_RUNTIME_VERSION line was not found!" );
109
+ }
110
+ String expected = "JAVA_RUNTIME_VERSION=\" " + Runtime .version () + "\" " ;
111
+ if (!expected .equals (runtimeVersion )) {
112
+ throw new RuntimeException ("Mismatched runtime version: " +
113
+ runtimeVersion + " expected: " + expected );
114
+ }
115
+ }
116
+
117
+ private void checkSource (String fishForSOURCE , boolean isOracle ) {
118
+
94
119
System .out .println ("The source string found: " + fishForSOURCE );
95
120
96
121
// Extract the value of SOURCE=
@@ -101,8 +126,6 @@ private void readFile(String fileName, boolean isOpenJDK) {
101
126
}
102
127
String valueString = valueMatcher .group (1 );
103
128
104
- // Check if implementor is Oracle
105
- boolean isOracle = (implementor != null ) && implementor .contains ("Oracle Corporation" );
106
129
107
130
String [] values = valueString .split (" " );
108
131
@@ -144,6 +167,6 @@ public static void main(String args[]) {
144
167
System .out .println ("JDK Path : " + jdkPath );
145
168
System .out .println ("Runtime Name : " + runtime );
146
169
147
- new CheckSource (jdkPath + "/release" , runtime .contains ("OpenJDK" ));
170
+ new CheckReleaseFile (jdkPath + "/release" , runtime .contains ("OpenJDK" ));
148
171
}
149
172
}
0 commit comments