01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17:
18: package org.apache.harmony.tools.jarsigner;
19:
20: import java.io.OutputStream;
21: import java.util.logging.Handler;
22: import java.util.logging.Logger;
23: import java.util.logging.StreamHandler;
24:
25: /**
26: * The main class that bundles command line parsing, interaction with the user,
27: * exception handling and JAR signing and verification work.
28: */
29: public class Main {
30: /**
31: * The main method to run from another program.
32: * Parses the arguments, and performs the actual work
33: * on JAR signing and verification.
34: * If something goes wrong an exception is thrown.
35: *
36: * @param args -
37: * command line with options.
38: */
39: public static void run(String[] args, OutputStream out)
40: throws Exception {
41: // set up logging
42: Logger logger = Logger.getLogger(JSParameters.loggerName);
43: logger.setUseParentHandlers(false);
44: Handler handler = new StreamHandler(out, new JSLogFormatter());
45: logger.addHandler(handler);
46:
47: // parse command line arguments
48: JSParameters param = ArgParser.parseArgs(args, null);
49: // print help if incorrect or no arguments
50: if (param == null) {
51: JSHelper.printHelp();
52: return;
53: }
54: // do the actual work
55: if (param.isVerify()) {
56: JSVerifier.verifyJar(param);
57: } else {
58: JSSigner.signJar(param);
59: }
60: }
61:
62: /**
63: * The main method to run from command line.
64: *
65: * @param args -
66: * command line with options.
67: */
68: public static void main(String[] args) {
69: try {
70: run(args, System.out);
71: } catch (Exception e) {
72: System.out.print("JarSigner error: "
73: + e
74: + ((e.getCause() != null) ? ", caused by "
75: + e.getCause() : ""));
76: //e.printStackTrace();
77: }
78: }
79:
80: }
|