< prev index next >

jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java

Print this page




  59 import jdk.internal.misc.JavaLangModuleAccess;
  60 import jdk.internal.misc.SharedSecrets;
  61 import jdk.internal.module.ModuleHashes;
  62 import jdk.internal.module.ModuleInfoExtender;
  63 import jdk.internal.util.jar.JarIndex;
  64 
  65 import static jdk.internal.util.jar.JarIndex.INDEX_NAME;
  66 import static java.util.jar.JarFile.MANIFEST_NAME;
  67 import static java.util.stream.Collectors.joining;
  68 import static java.util.stream.Collectors.toSet;
  69 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
  70 
  71 /**
  72  * This class implements a simple utility for creating files in the JAR
  73  * (Java Archive) file format. The JAR format is based on the ZIP file
  74  * format, with optional meta-information stored in a MANIFEST entry.
  75  */
  76 public
  77 class Main {
  78     String program;
  79     PrintStream out, err;
  80     String fname, mname, ename;
  81     String zname = "";
  82     String rootjar = null;
  83 
  84     private static final int BASE_VERSION = 0;
  85 
  86     class Entry {
  87         final String basename;
  88         final String entryname;
  89         final File file;
  90         final boolean isDir;
  91 
  92         Entry(int version, File file) {
  93             this.file = file;
  94             String path = file.getPath();
  95             if (file.isDirectory()) {
  96                 isDir = true;
  97                 path = path.endsWith(File.separator) ? path :
  98                             path + File.separator;
  99             } else {


 172      * cflag: create
 173      * uflag: update
 174      * xflag: xtract
 175      * tflag: table
 176      * vflag: verbose
 177      * flag0: no zip compression (store only)
 178      * Mflag: DO NOT generate a manifest file (just ZIP)
 179      * iflag: generate jar index
 180      * nflag: Perform jar normalization at the end
 181      * pflag: preserve/don't strip leading slash and .. component from file name
 182      */
 183     boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag;
 184 
 185     /* To support additional GNU Style informational options */
 186     enum Info {
 187         HELP(GNUStyleOptions::printHelp),
 188         COMPAT_HELP(GNUStyleOptions::printCompatHelp),
 189         USAGE_SUMMARY(GNUStyleOptions::printUsageSummary),
 190         VERSION(GNUStyleOptions::printVersion);
 191 
 192         private Consumer<PrintStream> printFunction;
 193         Info(Consumer<PrintStream> f) { this.printFunction = f; }
 194         void print(PrintStream out) { printFunction.accept(out); }
 195     };
 196     Info info;
 197 
 198     /* Modular jar related options */
 199     boolean printModuleDescriptor;
 200     Version moduleVersion;
 201     Pattern modulesToHash;
 202     ModuleFinder moduleFinder = ModuleFinder.of();
 203 
 204     private static final String MODULE_INFO = "module-info.class";
 205 
 206     static final String MANIFEST_DIR = "META-INF/";
 207     static final String VERSIONS_DIR = MANIFEST_DIR + "versions/";
 208     static final String VERSION = "1.0";
 209 
 210     private static ResourceBundle rsrc;
 211 
 212     /**
 213      * If true, maintain compatibility with JDK releases prior to 6.0 by
 214      * timestamping extracted files with the time at which they are extracted.


 235             throw new Error("Error in message file");
 236         }
 237     }
 238 
 239     static String formatMsg(String key, String arg) {
 240         String msg = getMsg(key);
 241         String[] args = new String[1];
 242         args[0] = arg;
 243         return MessageFormat.format(msg, (Object[]) args);
 244     }
 245 
 246     static String formatMsg2(String key, String arg, String arg1) {
 247         String msg = getMsg(key);
 248         String[] args = new String[2];
 249         args[0] = arg;
 250         args[1] = arg1;
 251         return MessageFormat.format(msg, (Object[]) args);
 252     }
 253 
 254     public Main(PrintStream out, PrintStream err, String program) {






 255         this.out = out;
 256         this.err = err;
 257         this.program = program;
 258     }
 259 
 260     /**
 261      * Creates a new empty temporary file in the same directory as the
 262      * specified file.  A variant of File.createTempFile.
 263      */
 264     private static File createTempFileInSameDirectoryAs(File file)
 265         throws IOException {
 266         File dir = file.getParentFile();
 267         if (dir == null)
 268             dir = new File(".");
 269         return File.createTempFile("jartmp", null, dir);
 270     }
 271 
 272     private boolean ok;
 273 
 274     /**




  59 import jdk.internal.misc.JavaLangModuleAccess;
  60 import jdk.internal.misc.SharedSecrets;
  61 import jdk.internal.module.ModuleHashes;
  62 import jdk.internal.module.ModuleInfoExtender;
  63 import jdk.internal.util.jar.JarIndex;
  64 
  65 import static jdk.internal.util.jar.JarIndex.INDEX_NAME;
  66 import static java.util.jar.JarFile.MANIFEST_NAME;
  67 import static java.util.stream.Collectors.joining;
  68 import static java.util.stream.Collectors.toSet;
  69 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
  70 
  71 /**
  72  * This class implements a simple utility for creating files in the JAR
  73  * (Java Archive) file format. The JAR format is based on the ZIP file
  74  * format, with optional meta-information stored in a MANIFEST entry.
  75  */
  76 public
  77 class Main {
  78     String program;
  79     PrintWriter out, err;
  80     String fname, mname, ename;
  81     String zname = "";
  82     String rootjar = null;
  83 
  84     private static final int BASE_VERSION = 0;
  85 
  86     class Entry {
  87         final String basename;
  88         final String entryname;
  89         final File file;
  90         final boolean isDir;
  91 
  92         Entry(int version, File file) {
  93             this.file = file;
  94             String path = file.getPath();
  95             if (file.isDirectory()) {
  96                 isDir = true;
  97                 path = path.endsWith(File.separator) ? path :
  98                             path + File.separator;
  99             } else {


 172      * cflag: create
 173      * uflag: update
 174      * xflag: xtract
 175      * tflag: table
 176      * vflag: verbose
 177      * flag0: no zip compression (store only)
 178      * Mflag: DO NOT generate a manifest file (just ZIP)
 179      * iflag: generate jar index
 180      * nflag: Perform jar normalization at the end
 181      * pflag: preserve/don't strip leading slash and .. component from file name
 182      */
 183     boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag;
 184 
 185     /* To support additional GNU Style informational options */
 186     enum Info {
 187         HELP(GNUStyleOptions::printHelp),
 188         COMPAT_HELP(GNUStyleOptions::printCompatHelp),
 189         USAGE_SUMMARY(GNUStyleOptions::printUsageSummary),
 190         VERSION(GNUStyleOptions::printVersion);
 191 
 192         private Consumer<PrintWriter> printFunction;
 193         Info(Consumer<PrintWriter> f) { this.printFunction = f; }
 194         void print(PrintWriter out) { printFunction.accept(out); }
 195     };
 196     Info info;
 197 
 198     /* Modular jar related options */
 199     boolean printModuleDescriptor;
 200     Version moduleVersion;
 201     Pattern modulesToHash;
 202     ModuleFinder moduleFinder = ModuleFinder.of();
 203 
 204     private static final String MODULE_INFO = "module-info.class";
 205 
 206     static final String MANIFEST_DIR = "META-INF/";
 207     static final String VERSIONS_DIR = MANIFEST_DIR + "versions/";
 208     static final String VERSION = "1.0";
 209 
 210     private static ResourceBundle rsrc;
 211 
 212     /**
 213      * If true, maintain compatibility with JDK releases prior to 6.0 by
 214      * timestamping extracted files with the time at which they are extracted.


 235             throw new Error("Error in message file");
 236         }
 237     }
 238 
 239     static String formatMsg(String key, String arg) {
 240         String msg = getMsg(key);
 241         String[] args = new String[1];
 242         args[0] = arg;
 243         return MessageFormat.format(msg, (Object[]) args);
 244     }
 245 
 246     static String formatMsg2(String key, String arg, String arg1) {
 247         String msg = getMsg(key);
 248         String[] args = new String[2];
 249         args[0] = arg;
 250         args[1] = arg1;
 251         return MessageFormat.format(msg, (Object[]) args);
 252     }
 253 
 254     public Main(PrintStream out, PrintStream err, String program) {
 255         this.out = new PrintWriter(out, true);
 256         this.err = new PrintWriter(err, true);
 257         this.program = program;
 258     }
 259 
 260     public Main(PrintWriter out, PrintWriter err, String program) {
 261         this.out = out;
 262         this.err = err;
 263         this.program = program;
 264     }
 265 
 266     /**
 267      * Creates a new empty temporary file in the same directory as the
 268      * specified file.  A variant of File.createTempFile.
 269      */
 270     private static File createTempFileInSameDirectoryAs(File file)
 271         throws IOException {
 272         File dir = file.getParentFile();
 273         if (dir == null)
 274             dir = new File(".");
 275         return File.createTempFile("jartmp", null, dir);
 276     }
 277 
 278     private boolean ok;
 279 
 280     /**


< prev index next >