KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > jarprocessor > Main


1 /*******************************************************************************
2  * Copyright (c) 2006-2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.jarprocessor;
12
13 import java.io.File JavaDoc;
14
15 public class Main {
16
17     public static class Options {
18         public String JavaDoc outputDir = "."; //$NON-NLS-1$
19
public String JavaDoc 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 JavaDoc input = null;
26     }
27
28     private static void printUsage() {
29         System.out.println("[-option ...]... input"); //$NON-NLS-1$
30
System.out.println("The following options are supported:"); //$NON-NLS-1$
31
System.out.println("-processAll process all jars, regardless of whether they were previously normalized"); //$NON-NLS-1$
32
System.out.println(" By default only normalized jars will be processed."); //$NON-NLS-1$
33
System.out.println("-repack normalize jars "); //$NON-NLS-1$
34
System.out.println("-sign <command> sign jars using <command>"); //$NON-NLS-1$
35
System.out.println("-pack pack the jars. pack and repack are redundant unless"); //$NON-NLS-1$
36
System.out.println(" sign is also specified."); //$NON-NLS-1$
37
System.out.println("-unpack unpack pack.gz files. Unpack is mutually exclusive"); //$NON-NLS-1$
38
System.out.println(" with repack, sign and pack."); //$NON-NLS-1$
39
System.out.println();
40         System.out.println("-outputDir <dir> the output directory"); //$NON-NLS-1$
41
System.out.println("-verbose verbose mode "); //$NON-NLS-1$
42
}
43
44     public static Options processArguments(String JavaDoc[] 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")) {//$NON-NLS-1$
54
options.pack = true;
55             } else if (args[i].equals("-unpack")) { //$NON-NLS-1$
56
options.unpack = true;
57             } else if (args[i].equals("-sign") && i < args.length - 2) { //$NON-NLS-1$
58
if (args[i + 1].startsWith("-")) { //$NON-NLS-1$
59
printUsage();
60                     return null;
61                 }
62                 options.signCommand = args[++i];
63             } else if (args[i].equals("-repack")) { //$NON-NLS-1$
64
options.repack = true;
65             } else if (args[i].equals("-outputDir") && i < args.length - 2) { //$NON-NLS-1$
66
if (args[i + 1].startsWith("-")) { //$NON-NLS-1$
67
printUsage();
68                     return null;
69                 }
70                 options.outputDir = args[++i];
71             } else if (args[i].equals("-verbose")) { //$NON-NLS-1$
72
options.verbose = true;
73             } else if (args[i].equals("-processAll")) { //$NON-NLS-1$
74
options.processAll = true;
75             }
76         }
77
78         options.input = new File JavaDoc(args[i]);
79
80         String JavaDoc problemMessage = null;
81         String JavaDoc inputName = options.input.getName();
82         if (options.unpack) {
83             if (!JarProcessor.canPerformUnpack()) {
84                 problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$
85
} else if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$
86
problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$
87
} else if (options.pack || options.repack || options.signCommand != null) {
88                 problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
89
}
90         } else {
91             if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
92
problemMessage = "Input file is not a jar file."; //$NON-NLS-1$
93
} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
94                 problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
95
}
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     /**
108      * @param args
109      */

110     public static void main(String JavaDoc[] args) {
111         Options options = processArguments(args);
112         if (options == null)
113             return;
114         new JarProcessorExecutor().runJarProcessor(options);
115     }
116
117 }
118
Popular Tags