changeset 39139:8c8f2162a4bc

8159781: jlink --include-locales fails with java.util.regex.PatternSyntaxException Reviewed-by: mchung, okutsu
author naoto
date Wed, 22 Jun 2016 08:51:32 -0700
parents 1e1d98dbb44b
children 86f21a96d0ab
files jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java jdk/test/ProblemList.txt
diffstat 2 files changed, 33 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java	Wed Jun 22 09:21:06 2016 +0100
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java	Wed Jun 22 08:51:32 2016 -0700
@@ -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 @@
         "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 @@
                 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 @@
         // 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 @@
         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];
--- a/jdk/test/ProblemList.txt	Wed Jun 22 09:21:06 2016 +0100
+++ b/jdk/test/ProblemList.txt	Wed Jun 22 08:51:32 2016 -0700
@@ -387,8 +387,6 @@
 
 # core_tools
 
-tools/jlink/plugins/IncludeLocalesPluginTest.java               8159781 generic-all
-
 tools/jlink/JLinkOptimTest.java                                 8159264 generic-all
 
 ############################################################################