diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java index 5e8d85b1eff..6246e29afc2 100644 --- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java @@ -46,6 +46,7 @@ import jdk.tools.jlink.internal.Archive.Entry; import jdk.tools.jlink.internal.Archive.Entry.EntryType; import jdk.tools.jlink.internal.PoolImpl.CompressedModuleData; import jdk.tools.jlink.plugin.ExecutableImage; +import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.Pool; import jdk.tools.jlink.plugin.Pool.ModuleData; import jdk.tools.jlink.plugin.Pool.ModuleDataType; @@ -183,6 +184,8 @@ public final class ImageFileCreator { PoolImpl resultResources; try { resultResources = pluginSupport.visitResources(allContent); + } catch (PluginException pe) { + throw pe; } catch (Exception ex) { throw new IOException(ex); } diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java index 8a37d8c518e..b373f85b935 100644 --- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java @@ -92,6 +92,7 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr "*sun/text/resources/cldr/ext/[^\\/]+_%%.class," + "*sun/util/resources/cldr/ext/[^\\/]+_%%.class,"; private Predicate predicate; + private String userParam; private List priorityList; private List available; private List filtered; @@ -155,13 +156,17 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr @Override public void configure(Map config) { - try { - priorityList = Arrays.stream(config.get(NAME).split(",")) - .map(Locale.LanguageRange::new) - .collect(Collectors.toList()); - } catch (IllegalArgumentException iae) { - throw new PluginException(iae.getLocalizedMessage()); - } + userParam = config.get(NAME); + priorityList = Arrays.stream(userParam.split(",")) + .map(s -> { + try { + return new Locale.LanguageRange(s); + } catch (IllegalArgumentException iae) { + throw new PluginException(String.format( + PluginsResourceBundle.getMessage(NAME + ".invalidtag"), s)); + } + }) + .collect(Collectors.toList()); } @Override @@ -191,7 +196,8 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr filtered = filterLocales(available); if (filtered.isEmpty()) { - throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".nomatchinglocales")); + throw new PluginException( + String.format(PluginsResourceBundle.getMessage(NAME + ".nomatchinglocales"), userParam)); } try { diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties index 0fd33da26b0..38ffbe493f1 100644 --- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties @@ -20,7 +20,7 @@ Level 0: constant string sharing\n\ Level 1: ZIP\n\ Level 2: both.\n\ An optional filter can be specified to list the pattern of files to be filtered.\n\ -Use ^ for negation. eg: *Exception.class,*Error.class,^/java.base/java/lang/* +Use ^ for negation. e.g.: *Exception.class,*Error.class,^/java.base/java/lang/* compact-cp.argument= @@ -32,17 +32,17 @@ copy-files.argument== to copy to the image>. copy-files.description=\ If files to copy are not absolute path, JDK home dir is used.\n\ -eg: jrt-fs.jar,LICENSE,/home/me/myfile.txt=somewehere/conf.txt +e.g.: jrt-fs.jar,LICENSE,/home/me/myfile.txt=somewehere/conf.txt exclude-files.argument= exclude-files.description=\ -Specify files to exclude. eg: *.diz, /java.base/native/client/* +Specify files to exclude. e.g.: *.diz, /java.base/native/client/* exclude-resources.argument= exclude-resources.description=\ -Specify resources to exclude. eg: *.jcov, */META-INF/* +Specify resources to exclude. e.g.: *.jcov, */META-INF/* installed-modules.description=Fast loading of module descriptors (always enabled) @@ -51,7 +51,7 @@ onoff.argument= sort-resources.argument= sort-resources.description=\ -Sort resources. eg: */modules-info.class,/java-base/java/lang/* +Sort resources. e.g.: */modules-info.class,/java-base/java/lang/* strip-debug.description=\ Strip debug information from the output image @@ -73,13 +73,16 @@ include-locales.argument=\ include-locales.description=\ BCP 47 language tags separated by a comma, allowing locale matching\n\ -defined in RFC 4647. eg: en,ja,*-IN +defined in RFC 4647. e.g.: en,ja,*-IN include-locales.missingpackages=\ Missing locale data packages in jdk.localedata:\n\t include-locales.nomatchinglocales=\ -No matching locales found. Check the specified pattern. +No matching locales found for \"%s\". Check the specified pattern. + +include-locales.invalidtag=\ +Invalid language tag: %s main.status.ok=Functional. diff --git a/jdk/test/tools/jlink/JLink2Test.java b/jdk/test/tools/jlink/JLink2Test.java index 4e08a8146be..d68242590ce 100644 --- a/jdk/test/tools/jlink/JLink2Test.java +++ b/jdk/test/tools/jlink/JLink2Test.java @@ -101,7 +101,7 @@ public class JLink2Test { .addJmods(helper.getStdJmodsDir()) .addJmods(jar.getParent()) .addMods("bad") - .call().assertFailure("(\n|\r|.)*Error: jdk.tools.jlink.plugin.PluginException: module-info.class not found for bad module(\n|\r|.)*"); + .call().assertFailure("(\n|\r|.)*Error: module-info.class not found for bad module(\n|\r|.)*"); try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jar.toFile()))) { JarEntry entry = new JarEntry("classes"); out.putNextEntry(entry); @@ -118,7 +118,7 @@ public class JLink2Test { .addJmods(jar.getParent()) .addJars(helper.getStdJmodsDir()) .addMods("bad") - .call().assertFailure("(\n|\r|.)*Error: jdk.tools.jlink.plugin.PluginException: module-info.class not found for bad module(\n|\r|.)*"); + .call().assertFailure("(\n|\r|.)*Error: module-info.class not found for bad module(\n|\r|.)*"); } private static void testSameNames(Helper helper) throws Exception { diff --git a/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java b/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java index 26c217eb57a..e109e6c496f 100644 --- a/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java +++ b/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java @@ -298,17 +298,19 @@ public class IncludeLocalesPluginTest { null, null, null, - new PluginException( - PluginsResourceBundle.getMessage("include-locales.nomatchinglocales")) - .toString(), + new PluginException(String.format( + PluginsResourceBundle.getMessage("include-locales.nomatchinglocales"), "xyz")) + .getMessage(), }, // Error case: Invalid argument - {"--include-locales=zh_HK", + {"--include-locales=en,zh_HK", null, null, null, - "range=zh_hk", + new PluginException(String.format( + PluginsResourceBundle.getMessage("include-locales.invalidtag"), "zh_HK")) + .getMessage(), }, };