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