1 11 package org.eclipse.update.internal.jarprocessor; 12 13 import java.io.File ; 14 15 public class Main { 16 17 public static class Options { 18 public String outputDir = "."; public String signCommand = null; 20 public boolean pack = false; 21 public boolean repack = false; 22 public boolean unpack = false; 23 public boolean verbose = false; 24 public boolean processAll = false; 25 public File input = null; 26 } 27 28 private static void printUsage() { 29 System.out.println("[-option ...]... input"); System.out.println("The following options are supported:"); System.out.println("-processAll process all jars, regardless of whether they were previously normalized"); System.out.println(" By default only normalized jars will be processed."); System.out.println("-repack normalize jars "); System.out.println("-sign <command> sign jars using <command>"); System.out.println("-pack pack the jars. pack and repack are redundant unless"); System.out.println(" sign is also specified."); System.out.println("-unpack unpack pack.gz files. Unpack is mutually exclusive"); System.out.println(" with repack, sign and pack."); System.out.println(); 40 System.out.println("-outputDir <dir> the output directory"); System.out.println("-verbose verbose mode "); } 43 44 public static Options processArguments(String [] args) { 45 if (args.length == 0) { 46 printUsage(); 47 return null; 48 } 49 50 Options options = new Options(); 51 int i = 0; 52 for (; i < args.length - 1; i++) { 53 if (args[i].equals("-pack")) { options.pack = true; 55 } else if (args[i].equals("-unpack")) { options.unpack = true; 57 } else if (args[i].equals("-sign") && i < args.length - 2) { if (args[i + 1].startsWith("-")) { printUsage(); 60 return null; 61 } 62 options.signCommand = args[++i]; 63 } else if (args[i].equals("-repack")) { options.repack = true; 65 } else if (args[i].equals("-outputDir") && i < args.length - 2) { if (args[i + 1].startsWith("-")) { printUsage(); 68 return null; 69 } 70 options.outputDir = args[++i]; 71 } else if (args[i].equals("-verbose")) { options.verbose = true; 73 } else if (args[i].equals("-processAll")) { options.processAll = true; 75 } 76 } 77 78 options.input = new File (args[i]); 79 80 String problemMessage = null; 81 String inputName = options.input.getName(); 82 if (options.unpack) { 83 if (!JarProcessor.canPerformUnpack()) { 84 problemMessage = "The unpack200 command cannot be found."; } else if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".pack.gz")) { problemMessage = "Input file is not a pack.gz file."; } else if (options.pack || options.repack || options.signCommand != null) { 88 problemMessage = "Pack, repack or sign cannot be specified with unpack."; } 90 } else { 91 if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".jar")) { problemMessage = "Input file is not a jar file."; } else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) { 94 problemMessage = "The pack200 command can not be found."; } 96 } 97 if(problemMessage != null){ 98 System.out.println(problemMessage); 99 System.out.println(); 100 printUsage(); 101 return null; 102 } 103 104 return options; 105 } 106 107 110 public static void main(String [] args) { 111 Options options = processArguments(args); 112 if (options == null) 113 return; 114 new JarProcessorExecutor().runJarProcessor(options); 115 } 116 117 } 118 | Popular Tags |