src/java.base/share/classes/jdk/internal/loader/BootLoader.java
changeset 49285 4d2e3f5abb48
parent 48995 58bec53828ba
child 49528 c1eb35eb5f38
equal deleted inserted replaced
49284:a51ca91c2cde 49285:4d2e3f5abb48
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    30 import java.net.MalformedURLException;
    30 import java.net.MalformedURLException;
    31 import java.net.URI;
    31 import java.net.URI;
    32 import java.net.URL;
    32 import java.net.URL;
    33 import java.nio.file.Files;
    33 import java.nio.file.Files;
    34 import java.nio.file.Path;
    34 import java.nio.file.Path;
    35 import java.nio.file.Paths;
       
    36 import java.security.AccessController;
    35 import java.security.AccessController;
    37 import java.security.PrivilegedAction;
    36 import java.security.PrivilegedAction;
    38 import java.util.Arrays;
    37 import java.util.Arrays;
    39 import java.util.Enumeration;
    38 import java.util.Enumeration;
    40 import java.util.Optional;
    39 import java.util.Optional;
   241             if (location.startsWith("jrt:/")) {
   240             if (location.startsWith("jrt:/")) {
   242                 // named module in runtime image ("jrt:/".length() == 5)
   241                 // named module in runtime image ("jrt:/".length() == 5)
   243                 mn = location.substring(5, location.length());
   242                 mn = location.substring(5, location.length());
   244             } else if (location.startsWith("file:/")) {
   243             } else if (location.startsWith("file:/")) {
   245                 // named module in exploded image
   244                 // named module in exploded image
   246                 Path path = Paths.get(URI.create(location));
   245                 Path path = Path.of(URI.create(location));
   247                 Path modulesDir = Paths.get(JAVA_HOME, "modules");
   246                 Path modulesDir = Path.of(JAVA_HOME, "modules");
   248                 if (path.startsWith(modulesDir)) {
   247                 if (path.startsWith(modulesDir)) {
   249                     mn = path.getFileName().toString();
   248                     mn = path.getFileName().toString();
   250                 }
   249                 }
   251             }
   250             }
   252 
   251 
   265          * Returns URL if the given location is a regular file path.
   264          * Returns URL if the given location is a regular file path.
   266          */
   265          */
   267         private static URL toFileURL(String location) {
   266         private static URL toFileURL(String location) {
   268             return AccessController.doPrivileged(new PrivilegedAction<>() {
   267             return AccessController.doPrivileged(new PrivilegedAction<>() {
   269                 public URL run() {
   268                 public URL run() {
   270                     Path path = Paths.get(location);
   269                     Path path = Path.of(location);
   271                     if (Files.isRegularFile(path)) {
   270                     if (Files.isRegularFile(path)) {
   272                         try {
   271                         try {
   273                             return path.toUri().toURL();
   272                             return path.toUri().toURL();
   274                         } catch (MalformedURLException e) {}
   273                         } catch (MalformedURLException e) {}
   275                     }
   274                     }
   283          * containing a manifest.
   282          * containing a manifest.
   284          */
   283          */
   285         private static Manifest getManifest(String location) {
   284         private static Manifest getManifest(String location) {
   286             return AccessController.doPrivileged(new PrivilegedAction<>() {
   285             return AccessController.doPrivileged(new PrivilegedAction<>() {
   287                 public Manifest run() {
   286                 public Manifest run() {
   288                     Path jar = Paths.get(location);
   287                     Path jar = Path.of(location);
   289                     try (InputStream in = Files.newInputStream(jar);
   288                     try (InputStream in = Files.newInputStream(jar);
   290                          JarInputStream jis = new JarInputStream(in, false)) {
   289                          JarInputStream jis = new JarInputStream(in, false)) {
   291                         return jis.getManifest();
   290                         return jis.getManifest();
   292                     } catch (IOException e) {
   291                     } catch (IOException e) {
   293                         return null;
   292                         return null;