222 */
223 private static Module findModule(String location) {
224 String mn = null;
225 if (location.startsWith("jrt:/")) {
226 // named module in runtime image ("jrt:/".length() == 5)
227 mn = location.substring(5, location.length());
228 } else if (location.startsWith("file:/")) {
229 // named module in exploded image
230 Path path = Paths.get(URI.create(location));
231 Path modulesDir = Paths.get(JAVA_HOME, "modules");
232 if (path.startsWith(modulesDir)) {
233 mn = path.getFileName().toString();
234 }
235 }
236
237 if (mn != null) {
238 // named module from runtime image or exploded module
239 Optional<Module> om = Layer.boot().findModule(mn);
240 if (!om.isPresent())
241 throw new InternalError(mn + " not in boot layer");
242 return om.get();
243 }
244
245 return null;
246 }
247
248 /**
249 * Returns URL if the given location is a regular file path.
250 */
251 private static URL toFileURL(String location) {
252 return AccessController.doPrivileged(new PrivilegedAction<>() {
253 public URL run() {
254 Path path = Paths.get(location);
255 if (Files.isRegularFile(path)) {
256 try {
257 return path.toUri().toURL();
258 } catch (MalformedURLException e) {}
259 }
260 return null;
261 }
262 });
|
222 */
223 private static Module findModule(String location) {
224 String mn = null;
225 if (location.startsWith("jrt:/")) {
226 // named module in runtime image ("jrt:/".length() == 5)
227 mn = location.substring(5, location.length());
228 } else if (location.startsWith("file:/")) {
229 // named module in exploded image
230 Path path = Paths.get(URI.create(location));
231 Path modulesDir = Paths.get(JAVA_HOME, "modules");
232 if (path.startsWith(modulesDir)) {
233 mn = path.getFileName().toString();
234 }
235 }
236
237 if (mn != null) {
238 // named module from runtime image or exploded module
239 Optional<Module> om = Layer.boot().findModule(mn);
240 if (!om.isPresent())
241 throw new InternalError(mn + " not in boot layer");
242 return om.getWhenPresent();
243 }
244
245 return null;
246 }
247
248 /**
249 * Returns URL if the given location is a regular file path.
250 */
251 private static URL toFileURL(String location) {
252 return AccessController.doPrivileged(new PrivilegedAction<>() {
253 public URL run() {
254 Path path = Paths.get(location);
255 if (Files.isRegularFile(path)) {
256 try {
257 return path.toUri().toURL();
258 } catch (MalformedURLException e) {}
259 }
260 return null;
261 }
262 });
|