1 /*
   2  * Copyright (c) 2016, 2017, 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.nio.file.Path;
  25 import java.util.Arrays;
  26 import java.util.ArrayList;
  27 import java.util.List;
  28 import java.util.Locale;
  29 import java.util.stream.Collectors;
  30 
  31 import jdk.tools.jlink.plugin.Plugin;
  32 import jdk.tools.jlink.plugin.PluginException;
  33 import jdk.tools.jlink.internal.PluginRepository;
  34 import jdk.tools.jlink.internal.TaskHelper;
  35 import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
  36 import tests.Helper;
  37 import tests.JImageGenerator;
  38 import tests.JImageValidator;
  39 import tests.Result;
  40 
  41 /*
  42  * @test
  43  * @bug 8152143 8152704 8155649 8165804 8185841 8176841 8190918
  44  * @summary IncludeLocalesPlugin tests
  45  * @author Naoto Sato
  46  * @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
  47  * @library ../../lib
  48  * @modules java.base/jdk.internal.jimage
  49  *          jdk.jdeps/com.sun.tools.classfile
  50  *          jdk.jlink/jdk.tools.jlink.internal
  51  *          jdk.jlink/jdk.tools.jlink.internal.plugins
  52  *          jdk.jlink/jdk.tools.jlink.plugin
  53  *          jdk.jlink/jdk.tools.jmod
  54  *          jdk.jlink/jdk.tools.jimage
  55  *          jdk.compiler
  56  * @build tests.*
  57  * @build tools.jlink.plugins.GetAvailableLocales
  58  * @run main/othervm/timeout=300 -Xmx1g IncludeLocalesPluginTest
  59  */
  60 public class IncludeLocalesPluginTest {
  61 
  62     private final static String moduleName = "IncludeLocalesTest";
  63     private static Helper helper;
  64     private final static int INCLUDE_LOCALES_OPTION = 0;
  65     private final static int ADDMODS_OPTION         = 1;
  66     private final static int EXPECTED_LOCATIONS     = 2;
  67     private final static int UNEXPECTED_PATHS       = 3;
  68     private final static int AVAILABLE_LOCALES      = 4;
  69     private final static int ERROR_MESSAGE          = 5;
  70 
  71     private static int errors;
  72 
  73     private final static Object[][] testData = {
  74         // Test data should include:
  75         //  - --include-locales command line option
  76         //  - --add-modules command line option values
  77         //  - List of required resources in the result image
  78         //  - List of resources that should not exist in the result image
  79         //  - List of available locales in the result image
  80         //  - Error message
  81 
  82         // without --include-locales option: should include all locales
  83         {
  84             "",
  85             "jdk.localedata",
  86             List.of(
  87                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
  88                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
  89                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
  90                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
  91                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
  92                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
  93                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
  94                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
  95             List.of(),
  96             Arrays.stream(Locale.getAvailableLocales())
  97                   // "(root)" for Locale.ROOT rather than ""
  98                   .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
  99                   .collect(Collectors.toList()),
 100             "",
 101         },
 102 
 103         // Asterisk works exactly the same as above
 104         {
 105             "--include-locales=*",
 106             "jdk.localedata",
 107             List.of(
 108                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 109                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 110                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 111                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 112                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 113                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 114                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
 115                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 116             List.of(),
 117             Arrays.stream(Locale.getAvailableLocales())
 118                   // "(root)" for Locale.ROOT rather than ""
 119                   .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
 120                   .collect(Collectors.toList()),
 121             "",
 122         },
 123 
 124         // World English/Spanish in Latin America
 125         {
 126             "--include-locales=en-001,es-419",
 127             "jdk.localedata",
 128             List.of(
 129                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_AU.class",
 130                 "/jdk.localedata/sun/text/resources/ext/FormatData_es.class",
 131                 "/jdk.localedata/sun/text/resources/ext/FormatData_es_AR.class",
 132                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 133                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_150.class",
 134                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_AT.class",
 135                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_es.class",
 136                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_es_419.class",
 137                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_es_AR.class"),
 138             List.of(
 139                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 140                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 141                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 142                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 143                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 144                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 145                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 146                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 147             List.of(
 148                 "(root)", "en", "en_US", "en_US_POSIX", "en_001", "en_150", "en_AG", "en_AI",
 149                 "en_AT", "en_AU", "en_BB", "en_BE", "en_BM", "en_BS", "en_BW", "en_BZ",
 150                 "en_CA", "en_CC", "en_CH", "en_CK", "en_CM", "en_CX", "en_CY", "en_DE",
 151                 "en_DG", "en_DK", "en_DM", "en_ER", "en_FI", "en_FJ", "en_FK", "en_FM",
 152                 "en_GB", "en_GD", "en_GG", "en_GH", "en_GI", "en_GM", "en_GY", "en_HK",
 153                 "en_IE", "en_IL", "en_IM", "en_IN", "en_IO", "en_JE", "en_JM", "en_KE",
 154                 "en_KI", "en_KN", "en_KY", "en_LC", "en_LR", "en_LS", "en_MG", "en_MO",
 155                 "en_MS", "en_MT", "en_MU", "en_MW", "en_MY", "en_NA", "en_NF", "en_NG",
 156                 "en_NL", "en_NR", "en_NU", "en_NZ", "en_PG", "en_PH", "en_PK", "en_PN",
 157                 "en_PW", "en_RW", "en_SB", "en_SC", "en_SD", "en_SE", "en_SG", "en_SH",
 158                 "en_SI", "en_SL", "en_SS", "en_SX", "en_SZ", "en_TC", "en_TK", "en_TO",
 159                 "en_TT", "en_TV", "en_TZ", "en_UG", "en_VC", "en_VG", "en_VU", "en_WS",
 160                 "en_ZA", "en_ZM", "en_ZW", "es", "es_419", "es_AR", "es_BO", "es_BR",
 161                 "es_CL", "es_CO", "es_CR", "es_CU", "es_DO", "es_EC", "es_GT", "es_HN",
 162                 "es_MX", "es_NI", "es_PA", "es_PE", "es_PR", "es_PY", "es_SV", "es_US",
 163                 "es_UY", "es_VE"),
 164             "",
 165         },
 166 
 167         // All English and Japanese locales
 168         {
 169             "--include-locales=en,ja",
 170             "jdk.localedata",
 171             List.of(
 172                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 173                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 174                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 175                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class"),
 176             List.of(
 177                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 178                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 179                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 180                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 181                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 182                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 183                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
 184                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 185             List.of(
 186                 "(root)", "en", "en_001", "en_150", "en_AG", "en_AI", "en_AS", "en_AT",
 187                 "en_AU", "en_BB", "en_BE", "en_BI", "en_BM", "en_BS", "en_BW", "en_BZ",
 188                 "en_CA", "en_CC", "en_CH", "en_CK", "en_CM", "en_CX", "en_CY", "en_DE",
 189                 "en_DG", "en_DK", "en_DM", "en_ER", "en_FI", "en_FJ", "en_FK", "en_FM",
 190                 "en_GB", "en_GD", "en_GG", "en_GH", "en_GI", "en_GM", "en_GU", "en_GY",
 191                 "en_HK", "en_IE", "en_IL", "en_IM", "en_IN", "en_IO", "en_JE", "en_JM",
 192                 "en_KE", "en_KI", "en_KN", "en_KY", "en_LC", "en_LR", "en_LS", "en_MG",
 193                 "en_MH", "en_MO", "en_MP", "en_MS", "en_MT", "en_MU", "en_MW", "en_MY",
 194                 "en_NA", "en_NF", "en_NG", "en_NL", "en_NR", "en_NU", "en_NZ", "en_PG",
 195                 "en_PH", "en_PK", "en_PN", "en_PR", "en_PW", "en_RW", "en_SB", "en_SC",
 196                 "en_SD", "en_SE", "en_SG", "en_SH", "en_SI", "en_SL", "en_SS", "en_SX",
 197                 "en_SZ", "en_TC", "en_TK", "en_TO", "en_TT", "en_TV", "en_TZ", "en_UG",
 198                 "en_UM", "en_US", "en_US_POSIX", "en_VC", "en_VG", "en_VI", "en_VU",
 199                 "en_WS", "en_ZA", "en_ZM", "en_ZW", "ja", "ja_JP",
 200                 "ja_JP_JP_#u-ca-japanese"),
 201             "",
 202         },
 203 
 204         // All locales in Austria
 205         {
 206             "--include-locales=*-AT",
 207             "jdk.localedata",
 208             List.of(
 209                 "/jdk.localedata/sun/text/resources/ext/FormatData_de.class",
 210                 "/jdk.localedata/sun/text/resources/ext/FormatData_de_AT.class",
 211                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_de.class",
 212                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_de_AT.class",
 213                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 214                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_150.class",
 215                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_AT.class"),
 216             List.of(
 217                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 218                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 219                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 220                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 221                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 222                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 223                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 224                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 225                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 226             List.of(
 227                 "(root)", "en", "en_US", "en_US_POSIX", "en_001", "en_150", "en_AT",
 228                 "de", "de_AT"),
 229             "",
 230         },
 231 
 232         // All locales in India
 233         {
 234             "--include-locales=*-IN",
 235             "jdk.localedata",
 236             List.of(
 237                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_IN.class",
 238                 "/jdk.localedata/sun/text/resources/ext/FormatData_hi_IN.class",
 239                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 240                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_IN.class"),
 241             List.of(
 242                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 243                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 244                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 245                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 246                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorResources_th.class",
 247                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 248                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 249                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 250                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 251                 "/jdk.localedata/sun/util/resources/cldr/ext/CalendarData_as_IN.class",
 252                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 253                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
 254                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 255             List.of(
 256                 "(root)", "as_IN", "as", "bn_IN", "bn", "bo_IN", "bo", "brx_IN", "brx",
 257                 "en", "en_001", "en_IN", "en_US", "en_US_POSIX", "gu_IN", "gu", "hi_IN",
 258                 "hi", "kn_IN", "kn", "kok_IN", "kok", "ks_IN", "ks", "ml_IN", "ml",
 259                 "mr_IN", "mr", "ne_IN", "ne", "or_IN", "or", "pa_IN", "pa", "pa_IN_#Guru",
 260                 "pa__#Guru", "ta_IN", "ta", "te_IN", "te", "ur_IN", "ur"),
 261             "",
 262         },
 263 
 264         // Thai
 265         {
 266             "--include-locales=th",
 267             "jdk.localedata",
 268             List.of(
 269                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 270                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 271                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 272                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 273                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorResources_th.class",
 274                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class"),
 275             List.of(
 276                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 277                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 278                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 279                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 280                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 281                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 282             List.of(
 283                 "(root)", "en", "en_US", "en_US_POSIX", "th", "th_TH",
 284                 "th_TH_TH_#u-nu-thai"),
 285             "",
 286         },
 287 
 288         // Hong Kong
 289         {
 290             "--include-locales=zh-HK",
 291             "jdk.localedata",
 292             List.of(
 293                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 294                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_HK.class",
 295                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_TW.class",
 296                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 297             List.of(
 298                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 299                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 300                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 301                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 302                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 303                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 304                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 305                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_CN.class",
 306                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 307                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 308                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 309             List.of(
 310                 "(root)", "en", "en_US", "en_US_POSIX", "zh", "zh__#Hans", "zh__#Hant",
 311                 "zh_HK", "zh_HK_#Hans", "zh_HK_#Hant"),
 312             "",
 313         },
 314 
 315         // Simplified Chinese
 316         {
 317             "--include-locales=zh-Hans",
 318             "jdk.localedata",
 319             List.of(
 320                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 321                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_CN.class",
 322                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_SG.class",
 323                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 324             List.of(
 325                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 326                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 327                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 328                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 329                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 330                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 331                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 332                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 333                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 334                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 335             List.of(
 336                 "(root)", "en", "en_US", "en_US_POSIX", "zh", "zh__#Hans", "zh_CN",
 337                 "zh_CN_#Hans", "zh_HK_#Hans", "zh_MO_#Hans", "zh_SG", "zh_SG_#Hans"),
 338             "",
 339         },
 340 
 341         // Norwegian
 342         {
 343             "--include-locales=nb,nn,no",
 344             "jdk.localedata",
 345             List.of(
 346                 "/jdk.localedata/sun/text/resources/ext/FormatData_no.class",
 347                 "/jdk.localedata/sun/text/resources/ext/FormatData_no_NO.class",
 348                 "/jdk.localedata/sun/text/resources/ext/FormatData_no_NO_NY.class",
 349                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_nb.class",
 350                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_nn.class"),
 351             List.of(
 352                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 353                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 354                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 355                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 356                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 357                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 358                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 359                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 360                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 361                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 362             List.of(
 363                 "(root)", "en", "en_US", "en_US_POSIX", "nb", "nb_NO", "nb_SJ", "nn",
 364                 "nn_NO", "no", "no_NO", "no_NO_NY"),
 365             "",
 366         },
 367 
 368         // Hebrew/Indonesian/Yiddish
 369         {
 370             "--include-locales=he,id,yi",
 371             "jdk.localedata",
 372             List.of(
 373                 "/jdk.localedata/sun/text/resources/ext/FormatData_in.class",
 374                 "/jdk.localedata/sun/text/resources/ext/FormatData_in_ID.class",
 375                 "/jdk.localedata/sun/text/resources/ext/FormatData_iw.class",
 376                 "/jdk.localedata/sun/text/resources/ext/FormatData_iw_IL.class",
 377                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_in.class",
 378                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_iw.class",
 379                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ji.class"),
 380             List.of(
 381                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 382                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 383                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 384                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 385                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 386                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 387                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 388                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 389                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 390                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 391             List.of(
 392                 "(root)", "en", "en_US", "en_US_POSIX", "in", "in_ID", "iw", "iw_IL",
 393                 "ji", "ji_001"),
 394             "",
 395         },
 396 
 397         // Langtag including extensions. Should be ignored.
 398         {
 399             "--include-locales=en,ja-u-nu-thai",
 400             "jdk.localedata",
 401             List.of(
 402                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 403                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class"),
 404             List.of(
 405                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 406                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class"),
 407             List.of(
 408                 "(root)", "en", "en_001", "en_150", "en_AG", "en_AI", "en_AS", "en_AT",
 409                 "en_AU", "en_BB", "en_BE", "en_BI", "en_BM", "en_BS", "en_BW", "en_BZ",
 410                 "en_CA", "en_CC", "en_CH", "en_CK", "en_CM", "en_CX", "en_CY", "en_DE",
 411                 "en_DG", "en_DK", "en_DM", "en_ER", "en_FI", "en_FJ", "en_FK", "en_FM",
 412                 "en_GB", "en_GD", "en_GG", "en_GH", "en_GI", "en_GM", "en_GU", "en_GY",
 413                 "en_HK", "en_IE", "en_IL", "en_IM", "en_IN", "en_IO", "en_JE", "en_JM",
 414                 "en_KE", "en_KI", "en_KN", "en_KY", "en_LC", "en_LR", "en_LS", "en_MG",
 415                 "en_MH", "en_MO", "en_MP", "en_MS", "en_MT", "en_MU", "en_MW", "en_MY",
 416                 "en_NA", "en_NF", "en_NG", "en_NL", "en_NR", "en_NU", "en_NZ", "en_PG",
 417                 "en_PH", "en_PK", "en_PN", "en_PR", "en_PW", "en_RW", "en_SB", "en_SC",
 418                 "en_SD", "en_SE", "en_SG", "en_SH", "en_SI", "en_SL", "en_SS", "en_SX",
 419                 "en_SZ", "en_TC", "en_TK", "en_TO", "en_TT", "en_TV", "en_TZ", "en_UG",
 420                 "en_UM", "en_US", "en_US_POSIX", "en_VC", "en_VG", "en_VI", "en_VU",
 421                 "en_WS", "en_ZA", "en_ZM", "en_ZW"),
 422             "",
 423         },
 424 
 425         // Error case: No matching locales
 426         {
 427             "--include-locales=xyz",
 428             "jdk.localedata",
 429             null,
 430             null,
 431             null,
 432             new PluginException(String.format(
 433                 PluginsResourceBundle.getMessage("include-locales.nomatchinglocales"), "xyz"))
 434                 .getMessage(),
 435         },
 436 
 437         // Error case: Invalid argument
 438         {
 439             "--include-locales=en,zh_HK",
 440             "jdk.localedata",
 441             null,
 442             null,
 443             null,
 444             new PluginException(String.format(
 445                 PluginsResourceBundle.getMessage("include-locales.invalidtag"), "zh_hk"))
 446                 .getMessage(),
 447         },
 448 
 449         // Error case: jdk.localedata is not added
 450         {
 451             "--include-locales=en-US",
 452             "java.base",
 453             null,
 454             null,
 455             null,
 456             new PluginException(
 457                 PluginsResourceBundle.getMessage("include-locales.localedatanotfound"))
 458                 .getMessage(),
 459         },
 460     };
 461 
 462     public static void main(String[] args) throws Exception {
 463         helper = Helper.newHelper();
 464         if (helper == null) {
 465             System.err.println("Test not run");
 466             return;
 467         }
 468         helper.generateDefaultModules();
 469 
 470         for (Object[] data : testData) {
 471             // create image for each test data
 472             Result result;
 473             if (data[INCLUDE_LOCALES_OPTION].toString().isEmpty()) {
 474                 System.out.println("Invoking jlink with no --include-locales option");
 475                 result = JImageGenerator.getJLinkTask()
 476                     .modulePath(helper.defaultModulePath())
 477                     .output(helper.createNewImageDir(moduleName))
 478                     .addMods((String) data[ADDMODS_OPTION])
 479                     .call();
 480             } else {
 481                 System.out.println("Invoking jlink with \"" + data[INCLUDE_LOCALES_OPTION] + "\"");
 482                 result = JImageGenerator.getJLinkTask()
 483                     .modulePath(helper.defaultModulePath())
 484                     .output(helper.createNewImageDir(moduleName))
 485                     .addMods((String) data[ADDMODS_OPTION])
 486                     .option((String) data[INCLUDE_LOCALES_OPTION])
 487                     .call();
 488             }
 489 
 490             String errorMsg = (String) data[ERROR_MESSAGE];
 491             if (errorMsg.isEmpty()) {
 492                 Path image = result.assertSuccess();
 493 
 494                 // test locale data entries
 495                 testLocaleDataEntries(image,
 496                     (List<String>) data[EXPECTED_LOCATIONS],
 497                     (List<String>) data[UNEXPECTED_PATHS]);
 498 
 499                 // test available locales
 500                 testAvailableLocales(image, (List<String>) data[AVAILABLE_LOCALES]);
 501             } else {
 502                 result.assertFailure(new TaskHelper(TaskHelper.JLINK_BUNDLE)
 503                     .getMessage("error.prefix") + " " +errorMsg);
 504                 System.out.println("\tExpected failure: " + result.getMessage());
 505             }
 506         }
 507 
 508         if (errors > 0) {
 509             throw new RuntimeException("Test failed");
 510         }
 511     }
 512 
 513     private static void testLocaleDataEntries(Path image, List<String> expectedLocations,
 514                         List<String> unexpectedPaths) throws Exception {
 515         System.out.println("testLocaleDataEntries:");
 516         try {
 517             JImageValidator.validate(
 518                 image.resolve("lib").resolve("modules"),
 519                 expectedLocations, unexpectedPaths);
 520         } catch (Exception e) {
 521             System.out.println("\tFailed with: " + e);
 522             e.printStackTrace();
 523             errors++;
 524         }
 525     }
 526 
 527     private static void testAvailableLocales(Path image, List<String> availableLocales) throws Exception {
 528         System.out.println("testAvailableLocales:");
 529         Path launcher = image.resolve("bin/java" +
 530             (System.getProperty("os.name").startsWith("Windows") ? ".exe" : ""));
 531         List<String> args = new ArrayList<>(availableLocales.size() + 2);
 532         args.add(launcher.toString());
 533         args.add("GetAvailableLocales");
 534         args.addAll(availableLocales);
 535         Process proc = new ProcessBuilder(args).inheritIO().start();
 536 
 537         int len = Math.min(10, args.size());
 538         String command = args.subList(0, len).stream().collect(Collectors.joining(" "))
 539                          + (len < availableLocales.size() ? " ..." : "");
 540 
 541         int status = proc.waitFor();
 542         if (status == 0) {
 543             System.out.println("\tDone\t" + command);
 544         } else {
 545             System.out.println("\tExit " + status + "\t" + command);
 546             errors++;
 547         }
 548         System.out.println();
 549     }
 550 }