Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/build/translations/VerifyTranslations.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 it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 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 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.BufferedInputStream;
25
import java.io.FileInputStream;
26
import java.io.IOException;
27
import java.io.PrintWriter;
28
import java.io.StringWriter;
29
import java.util.Set;
30
import java.util.regex.Matcher;
31
import java.util.regex.Pattern;
32
import java.util.zip.ZipEntry;
33
import java.util.zip.ZipInputStream;
34
35
/**
36
* @test
37
* @requires release.implementor == "Oracle Corporation"
38
* @modules jdk.jlink/jdk.tools.jimage
39
* @summary Oracle builds of OpenJDK should only contain english, chinese and
40
* japanese translations
41
*/
42
public class VerifyTranslations {
43
44
/**
45
* The set of translations we want to see in an Oracle built image
46
*/
47
private static final Set<String> VALID_TRANSLATION_SUFFIXES = Set.of(
48
"_en", "_en_US", "_en_US_POSIX", "_ja", "_zh_CN"
49
);
50
51
/**
52
* This regexp will not match locales with 3 letter lang strings because
53
* doing so would trigger a ton of false positives all over the source
54
* tree. This is ok for now but is a potential future flaw in the test.
55
*/
56
private static final String BASE_LOCALE_REGEXP
57
= "(_[a-z]{2}(_[A-Z][a-z]{3})?(_([A-Z]{2})|([0-9]{3}))?(_[a-zA-Z]+)?)";
58
59
public static void main(String[] args) {
60
String jdkPath = System.getProperty("test.jdk");
61
String modulesFile = jdkPath + "/lib/modules";
62
63
// Run jimage tool to extract list of all classes and resources in the jdk
64
StringWriter output = new StringWriter();
65
jdk.tools.jimage.Main.run(new String[] { "list", modulesFile }, new PrintWriter(output));
66
67
Pattern classesLocalePattern = Pattern.compile(BASE_LOCALE_REGEXP + "\\.(class|properties)");
68
69
boolean failed = false;
70
String module = "";
71
for (String line : output.toString().split("\n")) {
72
if (line.startsWith("Module: ")) {
73
module = line.substring(8).trim();
74
}
75
// We do not filter resources in jdk.localedata
76
if (!module.equals("jdk.localedata")) {
77
Matcher matcher = classesLocalePattern.matcher(line);
78
if (matcher.find()) {
79
if (!VALID_TRANSLATION_SUFFIXES.contains(matcher.group(1))) {
80
System.out.println("Unsupported translation found in lib/modules: "
81
+ module + "/" + line.trim());
82
failed = true;
83
}
84
}
85
}
86
}
87
88
// Check all files in src.zip
89
Pattern sourceLocalePattern = Pattern.compile(BASE_LOCALE_REGEXP + "\\.java");
90
String srcZip = jdkPath + "/lib/src.zip";
91
try (ZipInputStream srcZipInput = new ZipInputStream(
92
new BufferedInputStream(new FileInputStream(srcZip)))) {
93
ZipEntry entry;
94
while ((entry = srcZipInput.getNextEntry()) != null) {
95
String name = entry.getName();
96
if (!name.startsWith("jdk.localedata")) {
97
Matcher matcher = sourceLocalePattern.matcher(name);
98
if (matcher.find()) {
99
if (!VALID_TRANSLATION_SUFFIXES.contains(matcher.group(1))) {
100
System.out.println("Unsupported translation found in lib/src.zip: " + name);
101
failed = true;
102
}
103
}
104
}
105
}
106
} catch (IOException e) {
107
throw new RuntimeException(e);
108
}
109
110
if (failed) {
111
throw new RuntimeException("lib/modules contains unsupported translations");
112
}
113
}
114
}
115
116