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
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 // without --include-locales option: should include all locales
74 {
75 "",
76 "jdk.localedata",
77 List.of(
78 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
79 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
80 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
81 "/jdk.localedata/sun/text/resources/ext/FormatData_zh.class",
82 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
83 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
84 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class",
85 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_zh.class"),
86 List.of(),
87 Arrays.stream(Locale.getAvailableLocales())
88 // "(root)" for Locale.ROOT rather than ""
89 .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
90 .collect(Collectors.toList()),
91 "",
92 },
370 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_in.class",
371 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_iw.class",
372 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ji.class"),
373 List.of(
374 "/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th",
375 "/jdk.localedata/sun/text/resources/ext/thai_dict",
376 "/jdk.localedata/sun/text/resources/ext/WordBreakIteratorData_th",
377 "/jdk.localedata/sun/text/resources/ext/BreakIteratorInfo_th.class",
378 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",
379 "/jdk.localedata/sun/text/resources/ext/FormatData_ja.class",
380 "/jdk.localedata/sun/text/resources/ext/FormatData_th.class",
381 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_en_001.class",
382 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_ja.class",
383 "/jdk.localedata/sun/text/resources/cldr/ext/FormatData_th.class"),
384 List.of(
385 "(root)", "en", "en_US", "en_US_POSIX", "in", "in_ID", "iw", "iw_IL",
386 "ji", "ji_001"),
387 "",
388 },
389
390 // Error case: No matching locales
391 {
392 "--include-locales=xyz",
393 "jdk.localedata",
394 null,
395 null,
396 null,
397 new PluginException(String.format(
398 PluginsResourceBundle.getMessage("include-locales.nomatchinglocales"), "xyz"))
399 .getMessage(),
400 },
401
402 // Error case: Invalid argument
403 {
404 "--include-locales=en,zh_HK",
405 "jdk.localedata",
406 null,
407 null,
408 null,
409 new PluginException(String.format(
|
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 },
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(
|