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
  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/util/resources/cldr/ext/CalendarData_as_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                 "/jdk.localedata/sun/util/resources/cldr/ext/CalendarData_kok_IN.class",
 242                 "/jdk.localedata/sun/util/resources/cldr/ext/CalendarData_pa_IN.class"),
 243             List.of(
 244                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 245                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 246                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 247                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 248                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorResources_th.class",
 249                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 250                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 251                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 252                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 253                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 254                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
 255                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 256             List.of(
 257                 "(root)", "as_IN", "as", "bn_IN", "bn", "bo_IN", "bo", "brx_IN", "brx",
 258                 "en", "en_001", "en_IN", "en_US", "en_US_POSIX", "gu_IN", "gu", "hi_IN",
 259                 "hi", "kn_IN", "kn", "kok_IN", "kok", "ks_IN", "ks", "ml_IN", "ml",
 260                 "mr_IN", "mr", "ne_IN", "ne", "or_IN", "or", "pa_IN", "pa", "pa_IN_#Guru",
 261                 "pa__#Guru", "ta_IN", "ta", "te_IN", "te", "ur_IN", "ur"),
 262             "",
 263         },
 264 
 265         // Thai
 266         {
 267             "--include-locales=th",
 268             "jdk.localedata",
 269             List.of(
 270                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 271                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 272                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 273                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 274                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorResources_th.class",
 275                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class"),
 276             List.of(
 277                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 278                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 279                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 280                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 281                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 282                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 283             List.of(
 284                 "(root)", "en", "en_US", "en_US_POSIX", "th", "th_TH",
 285                 "th_TH_TH_#u-nu-thai"),
 286             "",
 287         },
 288 
 289         // Hong Kong
 290         {
 291             "--include-locales=zh-HK",
 292             "jdk.localedata",
 293             List.of(
 294                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 295                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_HK.class",
 296                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_TW.class",
 297                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 298             List.of(
 299                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 300                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 301                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 302                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 303                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 304                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 305                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 306                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_CN.class",
 307                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 308                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 309                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 310             List.of(
 311                 "(root)", "en", "en_US", "en_US_POSIX", "zh", "zh__#Hans", "zh__#Hant",
 312                 "zh_HK", "zh_HK_#Hans", "zh_HK_#Hant"),
 313             "",
 314         },
 315 
 316         // Simplified Chinese
 317         {
 318             "--include-locales=zh-Hans",
 319             "jdk.localedata",
 320             List.of(
 321                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
 322                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_CN.class",
 323                 "/jdk.localedata/sun/text/resources/ext/FormatData_zh_SG.class",
 324                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
 325             List.of(
 326                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 327                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 328                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 329                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 330                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 331                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 332                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 333                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 334                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 335                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 336             List.of(
 337                 "(root)", "en", "en_US", "en_US_POSIX", "zh", "zh__#Hans", "zh_CN",
 338                 "zh_HK", "zh_MO", "zh_CN_#Hans", "zh_HK_#Hans", "zh_MO_#Hans", "zh_SG", "zh_SG_#Hans"),
 339             "",
 340         },
 341 
 342         // Norwegian
 343         {
 344             "--include-locales=nb,nn,no",
 345             "jdk.localedata",
 346             List.of(
 347                 "/jdk.localedata/sun/text/resources/ext/FormatData_no.class",
 348                 "/jdk.localedata/sun/text/resources/ext/FormatData_no_NO.class",
 349                 "/jdk.localedata/sun/text/resources/ext/FormatData_no_NO_NY.class",
 350                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_nb.class",
 351                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_nn.class"),
 352             List.of(
 353                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 354                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 355                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 356                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 357                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 358                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 359                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 360                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 361                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 362                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 363             List.of(
 364                 "(root)", "en", "en_US", "en_US_POSIX", "nb", "nb_NO", "nb_SJ", "nn",
 365                 "nn_NO", "no", "no_NO", "no_NO_NY"),
 366             "",
 367         },
 368 
 369         // Hebrew/Indonesian/Yiddish
 370         {
 371             "--include-locales=he,id,yi",
 372             "jdk.localedata",
 373             List.of(
 374                 "/jdk.localedata/sun/text/resources/ext/FormatData_in.class",
 375                 "/jdk.localedata/sun/text/resources/ext/FormatData_in_ID.class",
 376                 "/jdk.localedata/sun/text/resources/ext/FormatData_iw.class",
 377                 "/jdk.localedata/sun/text/resources/ext/FormatData_iw_IL.class",
 378                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_in.class",
 379                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_iw.class",
 380                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ji.class"),
 381             List.of(
 382                 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
 383                 "/jdk.localedata/sun/text/resources/ext/thai_dict",
 384                 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
 385                 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
 386                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 387                 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
 388                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
 389                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
 390                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 391                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
 392             List.of(
 393                 "(root)", "en", "en_US", "en_US_POSIX", "in", "in_ID", "iw", "iw_IL",
 394                 "ji", "ji_001"),
 395             "",
 396         },
 397 
 398         // Langtag including extensions. Should be ignored.
 399         {
 400             "--include-locales=en,ja-u-nu-thai",
 401             "jdk.localedata",
 402             List.of(
 403                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
 404                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class"),
 405             List.of(
 406                 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
 407                 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class"),
 408             List.of(
 409                 "(root)", "en", "en_001", "en_150", "en_AG", "en_AI", "en_AS", "en_AT",
 410                 "en_AU", "en_BB", "en_BE", "en_BI", "en_BM", "en_BS", "en_BW", "en_BZ",
 411                 "en_CA", "en_CC", "en_CH", "en_CK", "en_CM", "en_CX", "en_CY", "en_DE",
 412                 "en_DG", "en_DK", "en_DM", "en_ER", "en_FI", "en_FJ", "en_FK", "en_FM",
 413                 "en_GB", "en_GD", "en_GG", "en_GH", "en_GI", "en_GM", "en_GU", "en_GY",
 414                 "en_HK", "en_IE", "en_IL", "en_IM", "en_IN", "en_IO", "en_JE", "en_JM",
 415                 "en_KE", "en_KI", "en_KN", "en_KY", "en_LC", "en_LR", "en_LS", "en_MG",
 416                 "en_MH", "en_MO", "en_MP", "en_MS", "en_MT", "en_MU", "en_MW", "en_MY",
 417                 "en_NA", "en_NF", "en_NG", "en_NL", "en_NR", "en_NU", "en_NZ", "en_PG",
 418                 "en_PH", "en_PK", "en_PN", "en_PR", "en_PW", "en_RW", "en_SB", "en_SC",
 419                 "en_SD", "en_SE", "en_SG", "en_SH", "en_SI", "en_SL", "en_SS", "en_SX",
 420                 "en_SZ", "en_TC", "en_TK", "en_TO", "en_TT", "en_TV", "en_TZ", "en_UG",
 421                 "en_UM", "en_US", "en_US_POSIX", "en_VC", "en_VG", "en_VI", "en_VU",
 422                 "en_WS", "en_ZA", "en_ZM", "en_ZW"),
 423             "",
 424         },
 425 
 426         // Error case: No matching locales
 427         {
 428             "--include-locales=xyz",
 429             "jdk.localedata",
 430             null,
 431             null,
 432             null,
 433             new PluginException(String.format(
 434                 PluginsResourceBundle.getMessage("include-locales.nomatchinglocales"), "xyz"))
 435                 .getMessage(),
 436         },
 437 
 438         // Error case: Invalid argument
 439         {
 440             "--include-locales=en,zh_HK",
 441             "jdk.localedata",
 442             null,
 443             null,
 444             null,
 445             new PluginException(String.format(
 446                 PluginsResourceBundle.getMessage("include-locales.invalidtag"), "zh_hk"))
 447                 .getMessage(),
 448         },
 449 
 450         // Error case: jdk.localedata is not added
 451         {
 452             "--include-locales=en-US",
 453             "java.base",
 454             null,
 455             null,
 456             null,
 457             new PluginException(
 458                 PluginsResourceBundle.getMessage("include-locales.localedatanotfound"))
 459                 .getMessage(),
 460         },
 461     };
 462 
 463     public static void main(String[] args) throws Exception {
 464         helper = Helper.newHelper();
 465         if (helper == null) {
 466             System.err.println("Test not run");
 467             return;
 468         }
 469         helper.generateDefaultModules();
 470 
 471         for (Object[] data : testData) {
 472             // create image for each test data
 473             Result result;
 474             if (data[INCLUDE_LOCALES_OPTION].toString().isEmpty()) {
 475                 System.out.println("Invoking jlink with no --include-locales option");
 476                 result = JImageGenerator.getJLinkTask()
 477                     .modulePath(helper.defaultModulePath())
 478                     .output(helper.createNewImageDir(moduleName))
 479                     .addMods((String) data[ADDMODS_OPTION])
 480                     .call();
 481             } else {
 482                 System.out.println("Invoking jlink with \"" + data[INCLUDE_LOCALES_OPTION] + "\"");
 483                 result = JImageGenerator.getJLinkTask()
 484                     .modulePath(helper.defaultModulePath())
 485                     .output(helper.createNewImageDir(moduleName))
 486                     .addMods((String) data[ADDMODS_OPTION])
 487                     .option((String) data[INCLUDE_LOCALES_OPTION])
 488                     .call();
 489             }
 490 
 491             String errorMsg = (String) data[ERROR_MESSAGE];
 492             if (errorMsg.isEmpty()) {
 493                 Path image = result.assertSuccess();
 494 
 495                 // test locale data entries
 496                 testLocaleDataEntries(image,
 497                     (List<String>) data[EXPECTED_LOCATIONS],
 498                     (List<String>) data[UNEXPECTED_PATHS]);
 499 
 500                 // test available locales
 501                 testAvailableLocales(image, (List<String>) data[AVAILABLE_LOCALES]);
 502             } else {
 503                 result.assertFailure(new TaskHelper(TaskHelper.JLINK_BUNDLE)
 504                     .getMessage("error.prefix") + " " +errorMsg);
 505                 System.out.println("\tExpected failure: " + result.getMessage());
 506             }
 507         }
 508 
 509         if (errors > 0) {
 510             throw new RuntimeException("Test failed");
 511         }
 512     }
 513 
 514     private static void testLocaleDataEntries(Path image, List<String> expectedLocations,
 515                         List<String> unexpectedPaths) throws Exception {
 516         System.out.println("testLocaleDataEntries:");
 517         try {
 518             JImageValidator.validate(
 519                 image.resolve("lib").resolve("modules"),
 520                 expectedLocations, unexpectedPaths);
 521         } catch (Exception e) {
 522             System.out.println("\tFailed with: " + e);
 523             e.printStackTrace();
 524             errors++;
 525         }
 526     }
 527 
 528     private static void testAvailableLocales(Path image, List<String> availableLocales) throws Exception {
 529         System.out.println("testAvailableLocales:");
 530         Path launcher = image.resolve("bin/java" +
 531             (System.getProperty("os.name").startsWith("Windows") ? ".exe" : ""));
 532         List<String> args = new ArrayList<>(availableLocales.size() + 2);
 533         args.add(launcher.toString());
 534         args.add("GetAvailableLocales");
 535         args.addAll(availableLocales);
 536         Process proc = new ProcessBuilder(args).inheritIO().start();
 537 
 538         int len = Math.min(10, args.size());
 539         String command = args.subList(0, len).stream().collect(Collectors.joining(" "))
 540                          + (len < availableLocales.size() ? " ..." : "");
 541 
 542         int status = proc.waitFor();
 543         if (status == 0) {
 544             System.out.println("\tDone\t" + command);
 545         } else {
 546             System.out.println("\tExit " + status + "\t" + command);
 547             errors++;
 548         }
 549         System.out.println();
 550     }
 551 }