|
42 | 42 |
|
43 | 43 | import java.util.Arrays;
|
44 | 44 | import java.util.Locale;
|
| 45 | +import java.util.Objects; |
| 46 | +import java.util.regex.Pattern; |
45 | 47 |
|
46 | 48 | import org.graalvm.nativeimage.ImageSingletons;
|
47 | 49 | import org.graalvm.nativeimage.Platform;
|
|
59 | 61 | public final class RuntimeResourceAccess {
|
60 | 62 |
|
61 | 63 | /**
|
62 |
| - * Make Java resources that are matched by a {@code pattern} available at run time. If the given |
63 |
| - * {@code pattern} starts with {@code <module-name>:} then the pattern that follows will only |
64 |
| - * match resources from Java module named {@code <module-name>}. |
| 64 | + * Make Java resource {@code resourcePath} from {@code module} available at run time. If the |
| 65 | + * given {@code module} is unnamed, the resource is looked up on the classpath instead. |
65 | 66 | *
|
66 | 67 | * @since 22.3
|
67 | 68 | */
|
68 |
| - public static void includeResources(String pattern) { |
69 |
| - ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), pattern); |
| 69 | + public static void addResource(Module module, String resourcePath) { |
| 70 | + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), |
| 71 | + withModuleName(module, Pattern.quote(resourcePath))); |
70 | 72 | }
|
71 | 73 |
|
72 | 74 | /**
|
73 |
| - * Ensure Java resources that are matched by a {@code pattern} will never be available at run |
74 |
| - * time. If the given {@code pattern} starts with {@code <module-name>:} then the pattern that |
75 |
| - * follows will only match resources from Java module named {@code <module-name>}. |
| 75 | + * Make Java ResourceBundle that is specified by a {@code baseBundleName} and {@code locales} |
| 76 | + * from module {@code module} available at run time. If the given {@code module} is unnamed, the |
| 77 | + * ResourceBundle is looked up on the classpath instead. |
76 | 78 | *
|
77 | 79 | * @since 22.3
|
78 | 80 | */
|
79 |
| - public static void excludeResources(String pattern) { |
80 |
| - ImageSingletons.lookup(RuntimeResourceSupport.class).ignoreResources(ConfigurationCondition.alwaysTrue(), pattern); |
| 81 | + public static void addResourceBundle(Module module, String baseBundleName, Locale[] locales) { |
| 82 | + Objects.requireNonNull(locales); |
| 83 | + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), |
| 84 | + withModuleName(module, baseBundleName), Arrays.asList(locales)); |
81 | 85 | }
|
82 | 86 |
|
83 | 87 | /**
|
84 |
| - * Make Java ResourceBundles that are specified by a {@code baseBundleName} and {@code locales} |
85 |
| - * available at run time. If the given {@code baseBundleName} starts with {@code <module-name>:} |
86 |
| - * then only the ResourceBundles from Java module named {@code <module-name>} will be added |
87 |
| - * (i.e. ResourceBundles with the same name from other modules will not be added). |
| 88 | + * Make Java ResourceBundle that is specified by a {@code bundleName} from module {@code module} |
| 89 | + * available at run time. If the given {@code module} is unnamed, the ResourceBundle is looked |
| 90 | + * up on the classpath instead. |
88 | 91 | *
|
89 | 92 | * @since 22.3
|
90 | 93 | */
|
91 |
| - public static void addResourceBundles(String baseBundleName, Locale[] locales) { |
92 |
| - ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), baseBundleName, Arrays.asList(locales)); |
| 94 | + public static void addResourceBundle(Module module, String bundleName) { |
| 95 | + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), |
| 96 | + withModuleName(module, bundleName)); |
93 | 97 | }
|
94 | 98 |
|
95 |
| - /** |
96 |
| - * Make Java ResourceBundles that are specified by a {@code bundleName} available at run time. |
97 |
| - * If the given {@code bundleName} starts with {@code <module-name>:} then only the |
98 |
| - * ResourceBundles from Java module named {@code <module-name>} will be added (i.e. |
99 |
| - * ResourceBundles with the same name from other modules will not be added). |
100 |
| - * |
101 |
| - * @since 22.3 |
102 |
| - */ |
103 |
| - public static void addResourceBundles(String bundleName) { |
104 |
| - ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), bundleName); |
| 99 | + private static String withModuleName(Module module, String str) { |
| 100 | + Objects.requireNonNull(module); |
| 101 | + Objects.requireNonNull(str); |
| 102 | + return (module.isNamed() ? module.getName() : "ALL-UNNAMED") + ":" + str; |
105 | 103 | }
|
106 | 104 |
|
107 | 105 | private RuntimeResourceAccess() {
|
|
0 commit comments