< prev index next >

src/java.base/share/classes/jdk/internal/loader/BootLoader.java

Print this page




 207          * Otherwise this method returns null.
 208          */
 209         private static Module findModule(String location) {
 210             String moduleName = null;
 211             if (location.startsWith("jrt:/")) {
 212                 // named module in runtime image ("jrt:/".length() == 5)
 213                 moduleName = location.substring(5, location.length());
 214             } else {
 215                 // named module in exploded image
 216                 Path path = Paths.get(location);
 217                 Path modulesDir = Paths.get(JAVA_HOME, "modules");
 218                 if (path.startsWith(modulesDir)) {
 219                     moduleName = path.getFileName().toString();
 220                 }
 221             }
 222 
 223             if (moduleName != null) {
 224                 // named module from runtime image or exploded module
 225                 Optional<Module> om = BOOT_LAYER.findModule(moduleName);
 226                 if (!om.isPresent())
 227                     throw new InternalError();
 228                 return om.get();
 229             }
 230 
 231             return null;
 232         }
 233 
 234         /**
 235          * Returns URL if the given location is a regular file path.
 236          */
 237         private static URL toFileURL(String location) {
 238             return AccessController.doPrivileged(new PrivilegedAction<>() {
 239                 public URL run() {
 240                     Path path = Paths.get(location);
 241                     if (Files.isRegularFile(path)) {
 242                         try {
 243                             return path.toUri().toURL();
 244                         } catch (MalformedURLException e) {}
 245                     }
 246                     return null;
 247                 }




 207          * Otherwise this method returns null.
 208          */
 209         private static Module findModule(String location) {
 210             String moduleName = null;
 211             if (location.startsWith("jrt:/")) {
 212                 // named module in runtime image ("jrt:/".length() == 5)
 213                 moduleName = location.substring(5, location.length());
 214             } else {
 215                 // named module in exploded image
 216                 Path path = Paths.get(location);
 217                 Path modulesDir = Paths.get(JAVA_HOME, "modules");
 218                 if (path.startsWith(modulesDir)) {
 219                     moduleName = path.getFileName().toString();
 220                 }
 221             }
 222 
 223             if (moduleName != null) {
 224                 // named module from runtime image or exploded module
 225                 Optional<Module> om = BOOT_LAYER.findModule(moduleName);
 226                 if (!om.isPresent())
 227                     throw new InternalError("Module not present:" + moduleName);
 228                 return om.get();
 229             }
 230 
 231             return null;
 232         }
 233 
 234         /**
 235          * Returns URL if the given location is a regular file path.
 236          */
 237         private static URL toFileURL(String location) {
 238             return AccessController.doPrivileged(new PrivilegedAction<>() {
 239                 public URL run() {
 240                     Path path = Paths.get(location);
 241                     if (Files.isRegularFile(path)) {
 242                         try {
 243                             return path.toUri().toURL();
 244                         } catch (MalformedURLException e) {}
 245                     }
 246                     return null;
 247                 }


< prev index next >