mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-07 14:40:22 +00:00
8159781: jlink --include-locales fails with java.util.regex.PatternSyntaxException
Reviewed-by: mchung, okutsu
This commit is contained in:
parent
34f5b60b4a
commit
5c227bfdae
@ -25,6 +25,7 @@
|
||||
package jdk.tools.jlink.internal.plugins;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.IllformedLocaleException;
|
||||
@ -81,15 +82,15 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
|
||||
"sun.util.resources.ext",
|
||||
"sun.util.resources.provider");
|
||||
private static final String METAINFONAME = "LocaleDataMetaInfo";
|
||||
private static final String META_FILES =
|
||||
"*module-info.class," +
|
||||
"*LocaleDataProvider.class," +
|
||||
"*" + METAINFONAME + ".class,";
|
||||
private static final String INCLUDE_LOCALE_FILES =
|
||||
"*sun/text/resources/ext/[^\\/]+_%%.class," +
|
||||
"*sun/util/resources/ext/[^\\/]+_%%.class," +
|
||||
"*sun/text/resources/cldr/ext/[^\\/]+_%%.class," +
|
||||
"*sun/util/resources/cldr/ext/[^\\/]+_%%.class,";
|
||||
private static final List<String> META_FILES = List.of(
|
||||
".+module-info.class",
|
||||
".+LocaleDataProvider.class",
|
||||
".+" + METAINFONAME + ".class");
|
||||
private static final List<String> INCLUDE_LOCALE_FILES = List.of(
|
||||
".+sun/text/resources/ext/[^_]+_",
|
||||
".+sun/util/resources/ext/[^_]+_",
|
||||
".+sun/text/resources/cldr/ext/[^_]+_",
|
||||
".+sun/util/resources/cldr/ext/[^_]+_");
|
||||
private Predicate<String> predicate;
|
||||
private String userParam;
|
||||
private List<Locale.LanguageRange> priorityList;
|
||||
@ -203,15 +204,17 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
|
||||
String.format(PluginsResourceBundle.getMessage(NAME + ".nomatchinglocales"), userParam));
|
||||
}
|
||||
|
||||
String value = META_FILES + filtered.stream()
|
||||
.map(s -> includeLocaleFilePatterns(s))
|
||||
.collect(Collectors.joining(","));
|
||||
List<String> value = Stream.concat(
|
||||
META_FILES.stream(),
|
||||
filtered.stream().flatMap(s -> includeLocaleFilePatterns(s).stream()))
|
||||
.map(s -> "regex:" + s)
|
||||
.collect(Collectors.toList());
|
||||
predicate = ResourceFilter.includeFilter(value);
|
||||
}
|
||||
|
||||
private String includeLocaleFilePatterns(String tag) {
|
||||
private List<String> includeLocaleFilePatterns(String tag) {
|
||||
List<String> files = new ArrayList<>();
|
||||
String pTag = tag.replaceAll("-", "_");
|
||||
String files = "";
|
||||
int lastDelimiter = tag.length();
|
||||
String isoSpecial = pTag.matches("^(he|yi|id).*") ?
|
||||
pTag.replaceFirst("he", "iw")
|
||||
@ -221,11 +224,11 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
|
||||
// Add tag patterns including parents
|
||||
while (true) {
|
||||
pTag = pTag.substring(0, lastDelimiter);
|
||||
files += INCLUDE_LOCALE_FILES.replaceAll("%%", pTag);
|
||||
files.addAll(includeLocaleFiles(pTag));
|
||||
|
||||
if (!isoSpecial.isEmpty()) {
|
||||
isoSpecial = isoSpecial.substring(0, lastDelimiter);
|
||||
files += INCLUDE_LOCALE_FILES.replaceAll("%%", isoSpecial);
|
||||
files.addAll(includeLocaleFiles(isoSpecial));
|
||||
}
|
||||
|
||||
lastDelimiter = pTag.lastIndexOf('_');
|
||||
@ -237,31 +240,37 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
|
||||
final String lang = pTag;
|
||||
|
||||
// Add possible special locales of the COMPAT provider
|
||||
files += Set.of(jaJPJPTag, noNONYTag, thTHTHTag).stream()
|
||||
Set.of(jaJPJPTag, noNONYTag, thTHTHTag).stream()
|
||||
.filter(stag -> lang.equals(stag.substring(0,2)))
|
||||
.map(t -> INCLUDE_LOCALE_FILES.replaceAll("%%", t.replaceAll("-", "_")))
|
||||
.collect(Collectors.joining(","));
|
||||
.map(t -> includeLocaleFiles(t.replaceAll("-", "_")))
|
||||
.forEach(files::addAll);
|
||||
|
||||
// Add possible UN.M49 files (unconditional for now) for each language
|
||||
files += INCLUDE_LOCALE_FILES.replaceAll("%%", lang + "_[0-9]{3}");
|
||||
files.addAll(includeLocaleFiles(lang + "_[0-9]{3}"));
|
||||
if (!isoSpecial.isEmpty()) {
|
||||
files += INCLUDE_LOCALE_FILES.replaceAll("%%", isoSpecial + "_[0-9]{3}");
|
||||
files.addAll(includeLocaleFiles(isoSpecial + "_[0-9]{3}"));
|
||||
}
|
||||
|
||||
// Add Thai BreakIterator related data files
|
||||
if (lang.equals("th")) {
|
||||
files += "*sun/text/resources/thai_dict," +
|
||||
"*sun/text/resources/[^\\/]+BreakIteratorData_th,";
|
||||
files.add(".+sun/text/resources/thai_dict");
|
||||
files.add(".+sun/text/resources/[^_]+BreakIteratorData_th");
|
||||
}
|
||||
|
||||
// Add Taiwan resource bundles for Hong Kong
|
||||
if (tag.startsWith("zh-HK")) {
|
||||
files += INCLUDE_LOCALE_FILES.replaceAll("%%", "zh_TW");
|
||||
files.addAll(includeLocaleFiles("zh_TW"));
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private List<String> includeLocaleFiles(String localeStr) {
|
||||
return INCLUDE_LOCALE_FILES.stream()
|
||||
.map(s -> s + localeStr + ".class")
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean stripUnsupportedLocales(byte[] bytes, ClassReader cr) {
|
||||
char[] buf = new char[cr.getMaxStringLength()];
|
||||
boolean[] modified = new boolean[1];
|
||||
|
||||
@ -387,8 +387,6 @@ com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java 8141370 linux-i5
|
||||
|
||||
# core_tools
|
||||
|
||||
tools/jlink/plugins/IncludeLocalesPluginTest.java 8159781 generic-all
|
||||
|
||||
tools/jlink/JLinkOptimTest.java 8159264 generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user