< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JarArchive.java

Print this page
rev 15409 : 8156499: Update jlink to support creating images with modules that are packaged as multi-release JARs
Reviewed-by:
Contributed-by: steve.drach@oracle.com

*** 28,39 **** import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.Objects; import java.util.stream.Stream; - import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import jdk.tools.jlink.internal.Archive.Entry.EntryType; /** * An Archive backed by a jar file. --- 28,40 ---- import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.Objects; + import java.util.jar.JarEntry; + import java.util.jar.JarFile; import java.util.stream.Stream; import java.util.zip.ZipFile; import jdk.tools.jlink.internal.Archive.Entry.EntryType; /** * An Archive backed by a jar file.
*** 41,57 **** public abstract class JarArchive implements Archive { /** * An entry located in a jar file. */ ! private class JarEntry extends Entry { private final long size; ! private final ZipEntry entry; ! private final ZipFile file; ! JarEntry(String path, String name, EntryType type, ZipFile file, ZipEntry entry) { super(JarArchive.this, path, name, type); this.entry = Objects.requireNonNull(entry); this.file = Objects.requireNonNull(file); size = entry.getSize(); } --- 42,58 ---- public abstract class JarArchive implements Archive { /** * An entry located in a jar file. */ ! private class JarFileEntry extends Entry { private final long size; ! private final JarEntry entry; ! private final JarFile file; ! JarFileEntry(String path, String name, EntryType type, JarFile file, JarEntry entry) { super(JarArchive.this, path, name, type); this.entry = Objects.requireNonNull(entry); this.file = Objects.requireNonNull(file); size = entry.getSize(); }
*** 72,83 **** private static final String MODULE_INFO = "module-info.class"; private final Path file; private final String moduleName; ! // currently processed ZipFile ! private ZipFile zipFile; protected JarArchive(String mn, Path file) { Objects.requireNonNull(mn); Objects.requireNonNull(file); this.moduleName = mn; --- 73,85 ---- private static final String MODULE_INFO = "module-info.class"; private final Path file; private final String moduleName; ! // currently processed JarFile ! private JarFile jarFile; ! private int prefixLength = 0; protected JarArchive(String mn, Path file) { Objects.requireNonNull(mn); Objects.requireNonNull(file); this.moduleName = mn;
*** 95,119 **** } @Override public Stream<Entry> entries() { try { ! if (zipFile == null) { open(); } } catch (IOException ioe) { throw new UncheckedIOException(ioe); } ! return zipFile.stream().map(this::toEntry).filter(n -> n != null); } abstract EntryType toEntryType(String entryName); abstract String getFileName(String entryName); ! private Entry toEntry(ZipEntry ze) { ! String name = ze.getName(); String fn = getFileName(name); if (ze.isDirectory() || fn.startsWith("_")) { return null; } --- 97,129 ---- } @Override public Stream<Entry> entries() { try { ! if (jarFile == null) { open(); } } catch (IOException ioe) { throw new UncheckedIOException(ioe); } ! Stream<JarEntry> jarEntries = jarFile.stream(); ! if (jarFile.isMultiRelease()) { ! int version = jarFile.getVersion().major(); ! String name = "META-INF/versions/" + version + "/"; ! prefixLength = name.length(); ! jarEntries = jarEntries ! .filter(je -> je.getName().startsWith(name)); ! } ! return jarEntries.map(this::toEntry).filter(n -> n != null); } abstract EntryType toEntryType(String entryName); abstract String getFileName(String entryName); ! private Entry toEntry(JarEntry ze) { ! String name = ze.getName().substring(prefixLength); String fn = getFileName(name); if (ze.isDirectory() || fn.startsWith("_")) { return null; }
*** 121,143 **** EntryType rt = toEntryType(name); if (fn.equals(MODULE_INFO)) { fn = moduleName + "/" + MODULE_INFO; } ! return new JarEntry(ze.getName(), fn, rt, zipFile, ze); } @Override public void close() throws IOException { ! if (zipFile != null) { ! zipFile.close(); } } @Override public void open() throws IOException { ! if (zipFile != null) { ! zipFile.close(); } ! zipFile = new ZipFile(file.toFile()); } } --- 131,153 ---- EntryType rt = toEntryType(name); if (fn.equals(MODULE_INFO)) { fn = moduleName + "/" + MODULE_INFO; } ! return new JarFileEntry(name, fn, rt, jarFile, ze); } @Override public void close() throws IOException { ! if (jarFile != null) { ! jarFile.close(); } } @Override public void open() throws IOException { ! if (jarFile != null) { ! jarFile.close(); } ! jarFile = new JarFile(file.toFile(), true, ZipFile.OPEN_READ, JarFile.runtimeVersion()); } }
< prev index next >