< prev index next >

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

Print this page

        

*** 21,40 **** * 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; 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.ModuleDescriptor.Requires; import java.net.URI; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; --- 21,45 ---- * 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 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,67 **** 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; /** --- 62,71 ----
*** 72,82 **** * 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 { private static final String MODULE_INFO = "module-info.class"; // the version to use for multi-release modular JARs private final Runtime.Version releaseVersion; --- 76,86 ---- * 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. */ ! 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,107 **** 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) { this.releaseVersion = version; this.isLinkPhase = isLinkPhase; this.entries = entries.clone(); for (Path entry : this.entries) { Objects.requireNonNull(entry); } } ! ModulePath(Path... entries) { this(JarFile.runtimeVersion(), false, entries); } @Override public Optional<ModuleReference> find(String name) { --- 92,111 ---- private int next; // map of module name to module reference map for modules already located private final Map<String, ModuleReference> cachedModules = new HashMap<>(); ! 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); } } ! public ModulePath(Path... entries) { this(JarFile.runtimeVersion(), false, entries); } @Override public Optional<ModuleReference> find(String name) {
*** 341,355 **** * @throws IOException * @throws InvalidModuleDescriptorException */ private ModuleReference readJMod(Path file) throws IOException { try (JmodFile jf = new JmodFile(file)) { ! ModuleDescriptor md; try (InputStream in = jf.getInputStream(Section.CLASSES, MODULE_INFO)) { ! md = ModuleDescriptor.read(in, () -> jmodPackages(jf)); } ! return ModuleReferences.newJModModule(md, file); } } // -- JAR files -- --- 345,359 ---- * @throws IOException * @throws InvalidModuleDescriptorException */ private ModuleReference readJMod(Path file) throws IOException { try (JmodFile jf = new JmodFile(file)) { ! ModuleInfo.Attributes attrs; try (InputStream in = jf.getInputStream(Section.CLASSES, MODULE_INFO)) { ! attrs = ModuleInfo.read(in, () -> jmodPackages(jf)); } ! return ModuleReferences.newJModModule(attrs, file); } } // -- JAR files --
*** 555,583 **** try (JarFile jf = new JarFile(file.toFile(), true, // verify ZipFile.OPEN_READ, releaseVersion)) { ! ModuleDescriptor md; JarEntry entry = jf.getJarEntry(MODULE_INFO); if (entry == null) { // no module-info.class so treat it as automatic module try { ! md = deriveModuleDescriptor(jf); } catch (IllegalArgumentException iae) { throw new FindException( "Unable to derive module descriptor for: " + jf.getName(), iae); } } else { ! md = ModuleDescriptor.read(jf.getInputStream(entry), () -> jarPackages(jf)); } ! return ModuleReferences.newJarModule(md, file); } } // -- exploded directories -- --- 559,588 ---- try (JarFile jf = new JarFile(file.toFile(), true, // verify ZipFile.OPEN_READ, releaseVersion)) { ! ModuleInfo.Attributes attrs; JarEntry entry = jf.getJarEntry(MODULE_INFO); if (entry == null) { // no module-info.class so treat it as automatic module try { ! 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 { ! attrs = ModuleInfo.read(jf.getInputStream(entry), () -> jarPackages(jf)); } ! return ModuleReferences.newJarModule(attrs, file); } } // -- exploded directories --
*** 602,620 **** * @throws IOException * @throws InvalidModuleDescriptorException */ private ModuleReference readExplodedModule(Path dir) throws IOException { Path mi = dir.resolve(MODULE_INFO); ! ModuleDescriptor md; try (InputStream in = Files.newInputStream(mi)) { ! md = ModuleDescriptor.read(new BufferedInputStream(in), () -> explodedPackages(dir)); } catch (NoSuchFileException e) { // for now return null; } ! return ModuleReferences.newExplodedModule(md, dir); } /** * Maps the name of an entry in a JAR or ZIP file to a package name. * --- 607,625 ---- * @throws IOException * @throws InvalidModuleDescriptorException */ private ModuleReference readExplodedModule(Path dir) throws IOException { Path mi = dir.resolve(MODULE_INFO); ! ModuleInfo.Attributes attrs; try (InputStream in = Files.newInputStream(mi)) { ! attrs = ModuleInfo.read(new BufferedInputStream(in), () -> explodedPackages(dir)); } catch (NoSuchFileException e) { // for now return null; } ! return ModuleReferences.newExplodedModule(attrs, dir); } /** * Maps the name of an entry in a JAR or ZIP file to a package name. *
< prev index next >