src/share/classes/org/openjdk/jigsaw/cli/Packager.java
Print this page
@@ -25,11 +25,10 @@
package org.openjdk.jigsaw.cli;
import java.lang.module.*;
import java.io.*;
-import java.security.SignatureException;
import java.util.*;
import static java.lang.System.out;
import static java.lang.System.err;
@@ -59,14 +58,14 @@
--fast : use fastest, rather then best compression
*/
public class Packager {
- private static JigsawModuleSystem jms
+ private static final JigsawModuleSystem jms
= JigsawModuleSystem.instance();
- private static boolean jigsawDevMode
+ private static final boolean jigsawDevMode
= System.getenv("JIGSAW_DEV_MODE") != null;
/** Temp dir for modules to be pre-installed into */
private static File tmp_dst;
@@ -133,19 +132,52 @@
private static void createTempWorkDir()
throws Command.Exception
{
try {
- tmp_dst = File.createTempFile("jigsaw",null);
+ tmp_dst = File.createTempFile("jigsaw", null);
Files.delete(tmp_dst);
Files.mkdirs(tmp_dst, "jigsaw temp directory");
+ } catch (IOException x) {
+ throw new Command.Exception(x);
}
- catch (IOException x) {
+ }
+
+ class Contents extends Command<SimpleLibrary> {
+ protected void go(SimpleLibrary lib)
+ throws Command.Exception
+ {
+ String jmodName = takeArg();
+ finishArgs();
+ try (FileInputStream fis = new FileInputStream(jmodName);
+ DataInputStream dis = new DataInputStream(fis);
+ ModuleFile.Reader reader = new ModuleFile.Reader(dis)) {
+ List<String> contents = reader.getContents();
+ for (String fn : contents)
+ out.format(" %s%n", fn);
+ } catch (IOException x) {
throw new Command.Exception(x);
}
}
+ }
+ class Show extends Command<SimpleLibrary> {
+ protected void go(SimpleLibrary lib)
+ throws Command.Exception
+ {
+ String jmodName = takeArg();
+ finishArgs();
+ try (FileInputStream fis = new FileInputStream(jmodName);
+ DataInputStream dis = new DataInputStream(fis);
+ ModuleFile.Reader reader = new ModuleFile.Reader(dis)) {
+ ModuleInfo mi = jms.parseModuleInfo(reader.readStart());
+ Commands.formatModule(out, mi, verbose);
+ } catch (IOException x) {
+ throw new Command.Exception(x);
+ }
+ }
+ }
class Jmod extends Command<SimpleLibrary> {
private String getModuleVersion(String modulename)
throws Command.Exception
{
@@ -589,25 +621,34 @@
cleanup();
}
}
}
- private static Map<String,Class<? extends Command<SimpleLibrary>>> commands
+ private static final Map<String,Class<? extends Command<SimpleLibrary>>> commands
= new HashMap<>();
static {
+ commands.put("contents", Contents.class);
commands.put("deb", Deb.class);
commands.put("jmod", Jmod.class);
+ commands.put("show", Show.class);
}
private OptionParser parser;
private static OptionSpec<File> resourcePath; // ##
private void usage() {
out.format("%n");
- out.format("usage: jpkg [-v] [-L <library>] [-r <resource-dir>] [-i <include-dir>] [-m <module-dir>] [-d <output-dir>] [-c <command>] [-n <name>] [-e <e-mail@address>] [-s <short description>] [-l <long description>] [-x <extra metadata>] [deb|jmod] <module-name>%n");
+ out.format("usage: jpkg contents <module-file>%n");
+ out.format(" jpkg show [-v] <module-file>%n");
+ out.format(" jpkg [-v] [-L <library>] [-r <resource-dir>] ");
+ out.format( "[-i <include-dir>] [-m <module-dir>] ");
+ out.format( "[-d <output-dir>] [-c <command>] [-n <name>] ");
+ out.format( "[-e <e-mail@address>] [-s <short description>] ");
+ out.format( "[-l <long description>] [-x <extra metadata>] ");
+ out.format( "[deb|jmod] <module-name>%n");
out.format("%n");
try {
parser.printHelpOn(out);
} catch (IOException x) {
throw new AssertionError(x);
@@ -812,10 +853,14 @@
if (cmd == Deb.class)
(new Deb()).run(null, opts);
else if (cmd == Jmod.class)
(new Jmod()).run(null, opts);
+ else if (cmd == Contents.class)
+ (new Contents()).run(null, opts);
+ else if (cmd == Show.class)
+ (new Show()).run(null, opts);
}
/**
* Helper method to check if a path exists before using it further.
*
@@ -822,11 +867,11 @@
* @param path to check
* @param type of path being checked
*
* @throws Command.Exception if path doesn't exist
*/
- private static final void checkIfPathExists(File path, String type)
+ private static void checkIfPathExists(File path, String type)
throws Command.Exception {
if (!path.exists())
throw new Command.Exception("%s path doesn't exist: %s",
type, path);
@@ -838,11 +883,11 @@
* @param path to check
* @param type of path being checked
*
* @throws Command.Exception if path isn't readable
*/
- private static final void checkIfPathIsReadable(File path, String type)
+ private static void checkIfPathIsReadable(File path, String type)
throws Command.Exception {
if (!path.canRead())
throw new Command.Exception("%s path isn't readable: %s",
type, path);
@@ -854,11 +899,11 @@
* @param path to check
* @param type of path being checked
*
* @throws Command.Exception if path is not a directory
*/
- private static final void checkIfPathIsDirectory(File path, String type)
+ private static void checkIfPathIsDirectory(File path, String type)
throws Command.Exception {
if (!path.isDirectory())
throw new Command.Exception("%s path is not a directory: %s",
type, path);
@@ -870,11 +915,11 @@
* @param path to check
* @param type of path being checked
*
* @throws Command.Exception if path is not a directory
*/
- private static final void checkPathArgument(File path, String type)
+ private static void checkPathArgument(File path, String type)
throws Command.Exception {
checkIfPathExists(path, type);
checkIfPathIsReadable(path, type);
checkIfPathIsDirectory(path, type);