|
Lines 25-30
Link Here
|
| 25 |
public boolean pack = false; |
25 |
public boolean pack = false; |
| 26 |
public boolean repack = false; |
26 |
public boolean repack = false; |
| 27 |
public boolean unpack = false; |
27 |
public boolean unpack = false; |
|
|
28 |
public boolean verbose = false; |
| 28 |
public File input = null; |
29 |
public File input = null; |
| 29 |
} |
30 |
} |
| 30 |
|
31 |
|
|
Lines 39-44
Link Here
|
| 39 |
System.out.println(" with repack, sign and pack."); //$NON-NLS-1$ |
40 |
System.out.println(" with repack, sign and pack."); //$NON-NLS-1$ |
| 40 |
System.out.println(); |
41 |
System.out.println(); |
| 41 |
System.out.println("-outputDir <dir> the output directory"); //$NON-NLS-1$ |
42 |
System.out.println("-outputDir <dir> the output directory"); //$NON-NLS-1$ |
|
|
43 |
System.out.println("-verbose verbose mode "); //$NON-NLS-1$ |
| 42 |
} |
44 |
} |
| 43 |
|
45 |
|
| 44 |
public static Options processArguments(String[] args) { |
46 |
public static Options processArguments(String[] args) { |
|
Lines 68-95
Link Here
|
| 68 |
return null; |
70 |
return null; |
| 69 |
} |
71 |
} |
| 70 |
options.outputDir = args[++i]; |
72 |
options.outputDir = args[++i]; |
|
|
73 |
} else if (args[i].equals("-verbose")) { //$NON-NLS-1$ |
| 74 |
options.verbose = true; |
| 71 |
} |
75 |
} |
| 72 |
} |
76 |
} |
| 73 |
|
77 |
|
| 74 |
options.input = new File(args[i]); |
78 |
options.input = new File(args[i]); |
| 75 |
|
79 |
|
| 76 |
String problemMessage = null; |
80 |
String problemMessage = null; |
|
|
81 |
String inputName = options.input.getName(); |
| 77 |
if (options.unpack) { |
82 |
if (options.unpack) { |
| 78 |
if (!JarProcessor.canPerformUnpack()) { |
83 |
if (!JarProcessor.canPerformUnpack()) { |
| 79 |
problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$ |
84 |
problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$ |
| 80 |
} else if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$ |
85 |
} else if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 81 |
problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$ |
86 |
problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$ |
| 82 |
} else if (options.pack || options.repack || options.signCommand != null) { |
87 |
} else if (options.pack || options.repack || options.signCommand != null) { |
| 83 |
problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$ |
88 |
problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$ |
| 84 |
} |
89 |
} |
| 85 |
} else { |
90 |
} else { |
| 86 |
if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ |
91 |
if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 87 |
problemMessage = "Input file is not a jar file."; //$NON-NLS-1$ |
92 |
problemMessage = "Input file is not a jar file."; //$NON-NLS-1$ |
| 88 |
} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) { |
93 |
} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) { |
| 89 |
problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$ |
94 |
problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$ |
| 90 |
} |
95 |
} |
| 91 |
} |
96 |
} |
| 92 |
if(problemMessage != null){ |
97 |
if (problemMessage != null) { |
| 93 |
System.out.println(problemMessage); |
98 |
System.out.println(problemMessage); |
| 94 |
System.out.println(); |
99 |
System.out.println(); |
| 95 |
printUsage(); |
100 |
printUsage(); |
|
Lines 99-113
Link Here
|
| 99 |
return options; |
104 |
return options; |
| 100 |
} |
105 |
} |
| 101 |
|
106 |
|
| 102 |
/** |
107 |
public static void runJarProcessor(Options options) { |
| 103 |
* @param args |
|
|
| 104 |
* @throws FileNotFoundException |
| 105 |
*/ |
| 106 |
public static void main(String[] args) { |
| 107 |
Options options = processArguments(args); |
| 108 |
if (options == null) |
| 109 |
return; |
| 110 |
|
| 111 |
if (options.input.getName().endsWith(".zip")) { //$NON-NLS-1$ |
108 |
if (options.input.getName().endsWith(".zip")) { //$NON-NLS-1$ |
| 112 |
ZipProcessor processor = new ZipProcessor(); |
109 |
ZipProcessor processor = new ZipProcessor(); |
| 113 |
processor.setWorkingDirectory(options.outputDir); |
110 |
processor.setWorkingDirectory(options.outputDir); |
|
Lines 115-151
Link Here
|
| 115 |
processor.setPack(options.pack); |
112 |
processor.setPack(options.pack); |
| 116 |
processor.setRepack(options.repack || (options.pack && options.signCommand != null)); |
113 |
processor.setRepack(options.repack || (options.pack && options.signCommand != null)); |
| 117 |
processor.setUnpack(options.unpack); |
114 |
processor.setUnpack(options.unpack); |
|
|
115 |
processor.setVerbose(options.verbose); |
| 118 |
try { |
116 |
try { |
| 119 |
processor.processZip(options.input); |
117 |
processor.processZip(options.input); |
| 120 |
} catch (ZipException e) { |
118 |
} catch (ZipException e) { |
| 121 |
// TODO Auto-generated catch block |
119 |
if (options.verbose) |
| 122 |
e.printStackTrace(); |
120 |
e.printStackTrace(); |
| 123 |
} catch (IOException e) { |
121 |
} catch (IOException e) { |
| 124 |
// TODO Auto-generated catch block |
122 |
if (options.verbose) |
| 125 |
e.printStackTrace(); |
123 |
e.printStackTrace(); |
| 126 |
} |
124 |
} |
| 127 |
} else { |
125 |
} else { |
| 128 |
JarProcessor processor = new JarProcessor(); |
126 |
JarProcessor processor = new JarProcessor(); |
| 129 |
processor.setWorkingDirectory(options.outputDir); |
127 |
processor.setWorkingDirectory(options.outputDir); |
|
|
128 |
processor.setVerbose(options.verbose); |
| 130 |
|
129 |
|
| 131 |
if (options.repack || (options.pack && options.signCommand != null)) |
130 |
if (options.repack || (options.pack && options.signCommand != null)) |
| 132 |
processor.addProcessStep(new PackUnpackStep(null)); |
131 |
processor.addProcessStep(new PackUnpackStep(null, options.verbose)); |
| 133 |
|
132 |
|
| 134 |
if (options.signCommand != null) |
133 |
if (options.signCommand != null) |
| 135 |
processor.addProcessStep(new SignCommandStep(null, options.signCommand)); |
134 |
processor.addProcessStep(new SignCommandStep(null, options.signCommand, options.verbose)); |
| 136 |
|
135 |
|
| 137 |
if (options.pack) |
136 |
if (options.pack) |
| 138 |
processor.addProcessStep(new PackStep(null)); |
137 |
processor.addProcessStep(new PackStep(null, options.verbose)); |
| 139 |
else if (options.unpack) |
138 |
else if (options.unpack) |
| 140 |
processor.addProcessStep(new UnpackStep(null)); |
139 |
processor.addProcessStep(new UnpackStep(null, options.verbose)); |
| 141 |
|
140 |
|
| 142 |
try { |
141 |
try { |
| 143 |
processor.process(options.input, options.unpack ? Utils.PACK_GZ_FILTER : Utils.JAR_FILTER); |
142 |
processor.process(options.input, options.unpack ? Utils.PACK_GZ_FILTER : Utils.JAR_FILTER); |
| 144 |
} catch (FileNotFoundException e) { |
143 |
} catch (FileNotFoundException e) { |
| 145 |
// TODO Auto-generated catch block |
144 |
if (options.verbose) |
| 146 |
e.printStackTrace(); |
145 |
e.printStackTrace(); |
| 147 |
} |
146 |
} |
| 148 |
} |
147 |
} |
| 149 |
} |
148 |
} |
| 150 |
|
149 |
|
|
|
150 |
/** |
| 151 |
* @param args |
| 152 |
* @throws FileNotFoundException |
| 153 |
*/ |
| 154 |
public static void main(String[] args) { |
| 155 |
Options options = processArguments(args); |
| 156 |
if (options == null) |
| 157 |
return; |
| 158 |
runJarProcessor(options); |
| 159 |
} |
| 160 |
|
| 151 |
} |
161 |
} |