Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/build/releaseFile/CheckSource.java
41145 views
1
2
/*
3
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/*
26
* @test
27
* @bug 8193660
28
* @summary Check SOURCE line in "release" file for closedjdk
29
* @run main CheckSource
30
*/
31
32
import java.io.BufferedReader;
33
import java.io.File;
34
import java.io.FileReader;
35
import java.io.FileNotFoundException;
36
import java.io.IOException;
37
import java.util.regex.Matcher;
38
import java.util.regex.Pattern;
39
40
public class CheckSource {
41
42
public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\+?";
43
44
CheckSource(String dataFile, boolean isOpenJDK) {
45
// Read data files
46
readFile(dataFile, isOpenJDK);
47
}
48
49
private void readFile(String fileName, boolean isOpenJDK) {
50
String fishForSOURCE = null;
51
String implementor = null;
52
53
File file = new File(fileName);
54
55
// open the stream to read in for Entries
56
try (BufferedReader buffRead =
57
new BufferedReader(new FileReader(fileName))) {
58
59
// this is the string read
60
String readIn;
61
62
// let's read some strings!
63
while ((readIn = buffRead.readLine()) != null) {
64
readIn = readIn.trim();
65
66
// throw out blank lines
67
if (readIn.length() == 0)
68
continue;
69
70
// grab SOURCE line
71
if (readIn.startsWith("SOURCE=")) {
72
fishForSOURCE = readIn;
73
continue;
74
}
75
76
// grab IMPLEMENTOR line
77
if (readIn.startsWith("IMPLEMENTOR=")) {
78
implementor = readIn;
79
continue;
80
}
81
}
82
} catch (FileNotFoundException fileExcept) {
83
throw new RuntimeException("File " + fileName +
84
" not found reading data!", fileExcept);
85
} catch (IOException ioExcept) {
86
throw new RuntimeException("Unexpected problem reading data!",
87
ioExcept);
88
}
89
90
// was SOURCE even found?
91
if (fishForSOURCE == null) {
92
throw new RuntimeException("SOURCE line was not found!");
93
}
94
System.out.println("The source string found: " + fishForSOURCE);
95
96
// Extract the value of SOURCE=
97
Pattern valuePattern = Pattern.compile("SOURCE=\"(.*)\"");
98
Matcher valueMatcher = valuePattern.matcher(fishForSOURCE);
99
if (!valueMatcher.matches()) {
100
throw new RuntimeException("SOURCE string has bad format, should be SOURCE=\"<value>\"");
101
}
102
String valueString = valueMatcher.group(1);
103
104
// Check if implementor is Oracle
105
boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation");
106
107
String[] values = valueString.split(" ");
108
109
// First value MUST start with ".:" regardless of Oracle or OpenJDK
110
String rootRegexp = "\\." + SRC_HASH_REGEXP;
111
if (!values[0].matches(rootRegexp)) {
112
throw new RuntimeException("The test failed, first element did not match regexp: " + rootRegexp);
113
}
114
115
// If it's an Oracle build, it can be either OpenJDK or OracleJDK. Other
116
// builds may have any number of additional elements in any format.
117
if (isOracle) {
118
if (isOpenJDK) {
119
if (values.length != 1) {
120
throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +
121
" Should be 1 for Oracle built OpenJDK.");
122
}
123
} else {
124
if (values.length != 2) {
125
throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." +
126
" Should be 2 for OracleJDK.");
127
}
128
// Second value MUST start with "open:" for OracleJDK
129
String openRegexp = "open" + SRC_HASH_REGEXP;
130
if (!values[1].matches(openRegexp)) {
131
throw new RuntimeException("The test failed, second element did not match regexp: " + openRegexp);
132
}
133
}
134
}
135
136
// Everything was fine
137
System.out.println("The test passed!");
138
}
139
140
public static void main(String args[]) {
141
String jdkPath = System.getProperty("test.jdk");
142
String runtime = System.getProperty("java.runtime.name");
143
144
System.out.println("JDK Path : " + jdkPath);
145
System.out.println("Runtime Name : " + runtime);
146
147
new CheckSource(jdkPath + "/release", runtime.contains("OpenJDK"));
148
}
149
}
150
151