< prev index next >

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

Print this page

        

@@ -21,20 +21,25 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package java.lang.module;
+package jdk.internal.module;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UncheckedIOException;
+import java.lang.module.FindException;
+import java.lang.module.InvalidModuleDescriptorException;
+import java.lang.module.ModuleDescriptor;
 import java.lang.module.ModuleDescriptor.Requires;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
 import java.net.URI;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;

@@ -57,11 +62,10 @@
 import java.util.stream.Collectors;
 import java.util.zip.ZipFile;
 
 import jdk.internal.jmod.JmodFile;
 import jdk.internal.jmod.JmodFile.Section;
-import jdk.internal.module.Checks;
 import jdk.internal.perf.PerfCounter;
 import jdk.internal.util.jar.VersionedStream;
 
 
 /**

@@ -72,11 +76,11 @@
  * or link-time phases. In both cases it locates modular JAR and exploded
  * modules. When created for link-time then it additionally locates
  * modules in JMOD files.
  */
 
-class ModulePath implements ModuleFinder {
+public class ModulePath implements ModuleFinder {
     private static final String MODULE_INFO = "module-info.class";
 
     // the version to use for multi-release modular JARs
     private final Runtime.Version releaseVersion;
 

@@ -88,20 +92,20 @@
     private int next;
 
     // map of module name to module reference map for modules already located
     private final Map<String, ModuleReference> cachedModules = new HashMap<>();
 
-    ModulePath(Runtime.Version version, boolean isLinkPhase, Path... entries) {
+    public ModulePath(Runtime.Version version, boolean isLinkPhase, Path... entries) {
         this.releaseVersion = version;
         this.isLinkPhase = isLinkPhase;
         this.entries = entries.clone();
         for (Path entry : this.entries) {
             Objects.requireNonNull(entry);
         }
     }
 
-    ModulePath(Path... entries) {
+    public ModulePath(Path... entries) {
         this(JarFile.runtimeVersion(), false, entries);
     }
 
     @Override
     public Optional<ModuleReference> find(String name) {

@@ -341,15 +345,15 @@
      * @throws IOException
      * @throws InvalidModuleDescriptorException
      */
     private ModuleReference readJMod(Path file) throws IOException {
         try (JmodFile jf = new JmodFile(file)) {
-            ModuleDescriptor md;
+            ModuleInfo.Attributes attrs;
             try (InputStream in = jf.getInputStream(Section.CLASSES, MODULE_INFO)) {
-                md = ModuleDescriptor.read(in, () -> jmodPackages(jf));
+                attrs  = ModuleInfo.read(in, () -> jmodPackages(jf));
             }
-            return ModuleReferences.newJModModule(md, file);
+            return ModuleReferences.newJModModule(attrs, file);
         }
     }
 
 
     // -- JAR files --

@@ -555,29 +559,30 @@
         try (JarFile jf = new JarFile(file.toFile(),
                                       true,               // verify
                                       ZipFile.OPEN_READ,
                                       releaseVersion))
         {
-            ModuleDescriptor md;
+            ModuleInfo.Attributes attrs;
             JarEntry entry = jf.getJarEntry(MODULE_INFO);
             if (entry == null) {
 
                 // no module-info.class so treat it as automatic module
                 try {
-                    md = deriveModuleDescriptor(jf);
+                    ModuleDescriptor md = deriveModuleDescriptor(jf);
+                    attrs = new ModuleInfo.Attributes(md, null, null);
                 } catch (IllegalArgumentException iae) {
                     throw new FindException(
                         "Unable to derive module descriptor for: "
                         + jf.getName(), iae);
                 }
 
             } else {
-                md = ModuleDescriptor.read(jf.getInputStream(entry),
+                attrs = ModuleInfo.read(jf.getInputStream(entry),
                                            () -> jarPackages(jf));
             }
 
-            return ModuleReferences.newJarModule(md, file);
+            return ModuleReferences.newJarModule(attrs, file);
         }
     }
 
 
     // -- exploded directories --

@@ -602,19 +607,19 @@
      * @throws IOException
      * @throws InvalidModuleDescriptorException
      */
     private ModuleReference readExplodedModule(Path dir) throws IOException {
         Path mi = dir.resolve(MODULE_INFO);
-        ModuleDescriptor md;
+        ModuleInfo.Attributes attrs;
         try (InputStream in = Files.newInputStream(mi)) {
-            md = ModuleDescriptor.read(new BufferedInputStream(in),
+            attrs = ModuleInfo.read(new BufferedInputStream(in),
                                        () -> explodedPackages(dir));
         } catch (NoSuchFileException e) {
             // for now
             return null;
         }
-        return ModuleReferences.newExplodedModule(md, dir);
+        return ModuleReferences.newExplodedModule(attrs, dir);
     }
 
     /**
      * Maps the name of an entry in a JAR or ZIP file to a package name.
      *
< prev index next >