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