src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java

Print this page
rev 16200 : 8166568: jmod tool needs extract option
8169492: jdk.internal.jmod.JmodFile.JMOD_MAGIC_NUMBER is a mutable array
Reviewed-by:

*** 45,54 **** --- 45,55 ---- import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Version; import java.lang.module.ResolutionException; import java.lang.module.ResolvedModule; import java.net.URI; + import java.nio.file.CopyOption; import java.nio.file.FileSystems; import java.nio.file.FileVisitOption; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.InvalidPathException;
*** 151,160 **** --- 152,162 ---- EXIT_SYSERR = 3, // System error or resource exhaustion. EXIT_ABNORMAL = 4;// terminated abnormally enum Mode { CREATE, + EXTRACT, LIST, DESCRIBE, HASH };
*** 200,209 **** --- 202,214 ---- boolean ok; switch (options.mode) { case CREATE: ok = create(); break; + case EXTRACT: + ok = extract(); + break; case LIST: ok = list(); break; case DESCRIBE: ok = describe();
*** 246,255 **** --- 251,285 ---- if (zip != null) zip.close(); } } + private boolean extract() throws IOException { + try (JmodFile jf = new JmodFile(options.jmodFile)) { + jf.stream().forEach(e -> { + try { + ZipEntry entry = e.zipEntry(); + String name = entry.getName(); + int index = name.lastIndexOf("/"); + if (index != -1) { + Path p = Paths.get(name.substring(0, index)); + if (Files.notExists(p)) + Files.createDirectories(p); + } + + try (OutputStream os = Files.newOutputStream(Paths.get(name))) { + jf.getInputStream(e).transferTo(os); + } + } catch (IOException x) { + throw new UncheckedIOException(x); + } + }); + + return true; + } + } + private boolean hashModules() { return new Hasher(options.moduleFinder).run(); } private boolean describe() throws IOException {
*** 1156,1165 **** --- 1186,1196 ---- String content = super.format(all); StringBuilder builder = new StringBuilder(); builder.append(getMessage("main.opt.mode")).append("\n "); builder.append(getMessage("main.opt.mode.create")).append("\n "); + builder.append(getMessage("main.opt.mode.extract")).append("\n "); builder.append(getMessage("main.opt.mode.list")).append("\n "); builder.append(getMessage("main.opt.mode.describe")).append("\n "); builder.append(getMessage("main.opt.mode.hash")).append("\n\n"); String cmdfile = null;