001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.tools.unpack200;
018:
019: import org.apache.harmony.pack200.Archive;
020:
021: public class Main {
022:
023: public static void main(String args[]) throws Exception {
024:
025: String inputFileName = null;
026: String outputFileName = null;
027: boolean removePackFile = false;
028: boolean verbose = false;
029: boolean quiet = false;
030: boolean overrideDeflateHint = false;
031: boolean deflateHint = false;
032: String logFileName = null;
033:
034: for (int i = 0; i < args.length; i++) {
035: if (args[i].equals("--help") || args[i].equals("-help")
036: || args[i].equals("-h") || args[i].equals("-?")) {
037: printHelp();
038: return;
039: } else if (args[i].equals("-Htrue")
040: || args[i].equals("--deflate-hint=true")) {
041: overrideDeflateHint = true;
042: deflateHint = true;
043: } else if (args[i].equals("-Hfalse")
044: || args[i].equals("--deflate-hint=false")) {
045: overrideDeflateHint = true;
046: deflateHint = false;
047: } else if (args[i].equals("-Hkeep")
048: || args[i].equals("--deflate-hint=keep")) {
049: overrideDeflateHint = false;
050: } else if (args[i].equals("-r")
051: || args[i].equals("--remove-pack-file")) {
052: removePackFile = true;
053: } else if (args[i].equals("-v")
054: || args[i].equals("--verbose")) {
055: verbose = true;
056: quiet = false;
057: } else if (args[i].equals("-q")
058: || args[i].equals("--quiet")) {
059: quiet = true;
060: verbose = false;
061: } else if (args[i].startsWith("-l")) {
062: logFileName = args[i].substring(2);
063: } else if (args[i].equals("-V")
064: || args[i].equals("--version")) {
065: printVersion();
066: return;
067: } else {
068: inputFileName = args[i];
069: if (args.length > i + 1) {
070: outputFileName = args[i + 1];
071: }
072: break;
073: }
074: }
075: if (inputFileName == null || outputFileName == null) {
076: printUsage();
077: return;
078: }
079: Archive archive = new Archive(inputFileName, outputFileName);
080: archive.setRemovePackFile(removePackFile);
081: archive.setVerbose(verbose);
082: archive.setQuiet(quiet);
083: if (overrideDeflateHint) {
084: archive.setDeflateHint(deflateHint);
085: }
086: if (logFileName != null) {
087: archive.setLogFile(logFileName);
088: }
089: archive.unpack();
090: }
091:
092: private static void printUsage() {
093: System.out
094: .println("Usage: unpack200 [-opt... | --option=value]... x.pack[.gz] y.jar");
095: System.out
096: .println("(For more information, run unpack200 --help)");
097: }
098:
099: private static void printHelp() {
100: System.out
101: .println("Usage: unpack200 [-opt... | --option=value]... x.pack[.gz] y.jar");
102: System.out.println();
103: System.out.println("Options:");
104: System.out
105: .println("-H{h}, --deflate-hint={h} Set the deflate hint for the output file to {h}, either true, false or keep");
106: System.out
107: .println("-r, --remove-pack-file Delete the input file after unpacking");
108: System.out
109: .println("-v, --verbose Print verbose output");
110: System.out
111: .println("-q, --quiet Print no output");
112: System.out
113: .println("-l{F}, --log-file={F} Print output to the log file {F}");
114: System.out
115: .println("-?, -h, --help Show the help message");
116: System.out
117: .println("-V, --version Show the program version number");
118: }
119:
120: private static void printVersion() {
121: System.out.println("Apache Harmony unpack200 version 0.0"); // TODO - version number
122: }
123:
124: }
|