< prev index next >

src/java.base/share/classes/jdk/internal/module/ModuleReferences.java

Print this page

        

@@ -23,11 +23,10 @@
  * questions.
  */
 
 package jdk.internal.module;
 
-import java.io.File;
 import java.io.IOError;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UncheckedIOException;
 import java.lang.module.ModuleReader;

@@ -48,11 +47,10 @@
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.zip.ZipFile;
 
 import jdk.internal.jmod.JmodFile;
-import jdk.internal.loader.ResourceHelper;
 import jdk.internal.misc.SharedSecrets;
 import jdk.internal.module.ModuleHashes.HashSupplier;
 import jdk.internal.util.jar.VersionedStream;
 import sun.net.www.ParseUtil;
 

@@ -76,10 +74,11 @@
                                              HashSupplier hasher) {
         ModuleReference mref = new ModuleReferenceImpl(attrs.descriptor(),
                                                        uri,
                                                        supplier,
                                                        null,
+                                                       attrs.target(),
                                                        attrs.recordedHashes(),
                                                        hasher,
                                                        attrs.moduleResolution());
         if (patcher != null)
             mref = patcher.patchIfNeeded(mref);

@@ -240,20 +239,21 @@
             this.jf = newJarFile(path);
             this.uri = uri;
         }
 
         private JarEntry getEntry(String name) {
-            JarEntry entry = jf.getJarEntry(Objects.requireNonNull(name));
-            return (entry == null || entry.isDirectory()) ? null : entry;
+            return jf.getJarEntry(Objects.requireNonNull(name));
         }
 
         @Override
         Optional<URI> implFind(String name) throws IOException {
             JarEntry je = getEntry(name);
             if (je != null) {
                 if (jf.isMultiRelease())
                     name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je);
+                if (je.isDirectory() && !name.endsWith("/"))
+                    name += "/";
                 String encodedPath = ParseUtil.encodePath(name, false);
                 String uris = "jar:" + uri + "!/" + encodedPath;
                 return Optional.of(URI.create(uris));
             } else {
                 return Optional.empty();

@@ -272,11 +272,10 @@
 
         @Override
         Stream<String> implList() throws IOException {
             // take snapshot to avoid async close
             List<String> names = VersionedStream.stream(jf)
-                    .filter(e -> !e.isDirectory())
                     .map(JarEntry::getName)
                     .collect(Collectors.toList());
             return names.stream();
         }
 

@@ -314,10 +313,12 @@
 
         @Override
         Optional<URI> implFind(String name) {
             JmodFile.Entry je = getEntry(name);
             if (je != null) {
+                if (je.isDirectory() && !name.endsWith("/"))
+                    name += "/";
                 String encodedPath = ParseUtil.encodePath(name, false);
                 String uris = "jmod:" + uri + "!/" + encodedPath;
                 return Optional.of(URI.create(uris));
             } else {
                 return Optional.empty();

@@ -374,30 +375,14 @@
          */
         private void ensureOpen() throws IOException {
             if (closed) throw new IOException("ModuleReader is closed");
         }
 
-        /**
-         * Returns a Path to access the given resource. Returns null if the
-         * resource name does not convert to a file path that locates a regular
-         * file in the module.
-         */
-        private Path toFilePath(String name) {
-            Path path = ResourceHelper.toFilePath(name);
-            if (path != null) {
-                Path file = dir.resolve(path);
-                if (Files.isRegularFile(file)) {
-                    return file;
-                }
-            }
-            return null;
-        }
-
         @Override
         public Optional<URI> find(String name) throws IOException {
             ensureOpen();
-            Path path = toFilePath(name);
+            Path path = Resources.toFilePath(dir, name);
             if (path != null) {
                 try {
                     return Optional.of(path.toUri());
                 } catch (IOError e) {
                     throw (IOException) e.getCause();

@@ -408,38 +393,35 @@
         }
 
         @Override
         public Optional<InputStream> open(String name) throws IOException {
             ensureOpen();
-            Path path = toFilePath(name);
+            Path path = Resources.toFilePath(dir, name);
             if (path != null) {
                 return Optional.of(Files.newInputStream(path));
             } else {
                 return Optional.empty();
             }
         }
 
         @Override
         public Optional<ByteBuffer> read(String name) throws IOException {
             ensureOpen();
-            Path path = toFilePath(name);
+            Path path = Resources.toFilePath(dir, name);
             if (path != null) {
                 return Optional.of(ByteBuffer.wrap(Files.readAllBytes(path)));
             } else {
                 return Optional.empty();
             }
         }
 
         @Override
         public Stream<String> list() throws IOException {
             ensureOpen();
-            // sym links not followed
-            return Files.find(dir, Integer.MAX_VALUE,
-                              (path, attrs) -> attrs.isRegularFile())
-                    .map(f -> dir.relativize(f)
-                                 .toString()
-                                 .replace(File.separatorChar, '/'));
+            return Files.walk(dir, Integer.MAX_VALUE)
+                        .map(f -> Resources.toResourceName(dir, f))
+                        .filter(s -> s.length() > 0);
         }
 
         @Override
         public void close() {
             closed = true;
< prev index next >