1 /*
2 * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.openjdk.asmtools;
24
25 import org.openjdk.asmtools.util.I18NResourceBundle;
26 import org.openjdk.asmtools.util.ProductInfo;
27
28 /**
29 * Wrapper class that reads the first command line argument and invokes a corresponding
30 * tool.
31 */
32 public class Main {
33
34 public static final I18NResourceBundle i18n
35 = I18NResourceBundle.getBundleForClass(Main.class);
36
37 /**
38 * Parses the first argument and deligates execution to an appropriate tool
39 *
40 * @param args - command line arguments
41 */
42 public static void main(String args[]) {
43 if (args.length == 0) {
44 usage(i18n.getString("main.error.no_arguments"), 1);
45 }
46 String cmd = args[0];
47 if (cmd.equals("-?") || cmd.equals("-h") || cmd.equals("-help")) {
48 usage(null, 0);
49 } else if (cmd.equals("-version")) {
50 printVersion();
51 } else {
52 String[] newArgs = new String[args.length - 1];
53 System.arraycopy(args, 1, newArgs, 0, args.length - 1);
54 if (cmd.equals("jasm")) {
55 jasm(newArgs);
56 } else if (cmd.equals("jdis")) {
57 jdis(newArgs);
58 } else if (cmd.equals("jcoder")) {
59 jcoder(newArgs);
60 } else if (cmd.equals("jdec")) {
61 jdec(newArgs);
62 } else if (cmd.equals("jcdec")) {
63 jcdec(newArgs);
64 } else {
65 usage(i18n.getString("main.error.unknown_tool", cmd), 1);
66 }
67 }
68 }
69
70 /**
71 * Prints usage info and error message, afterwards invokes System.exit()
72 *
73 * @param msg - error message to print, or null if no errors occurred
74 * @param exitCode - exit code to be returned by System.exit()
75 */
76 public static void usage(String msg, int exitCode) {
77 System.err.println(i18n.getString("main.usage", "asmtools.jar"));
78 if (msg != null) {
79 System.err.println(msg);
80 }
81 System.exit(exitCode);
82 }
83
84 /**
85 * Prints the tools version
86 */
87 public static void printVersion() {
88 System.out.println(ProductInfo.FULL_VERSION);
89 }
90
91 /**
92 * Invokes jasm main class with passed arguments
93 */
94 public static void jasm(String[] args) {
95 org.openjdk.asmtools.jasm.Main.main(args);
96 }
97
98 /**
99 * Invokes jcdec main class with passed arguments
100 */
101 public static void jcdec(String[] args) {
102 org.openjdk.asmtools.jcdec.Main.main(args);
103 }
104
105 /**
106 * Invokes jcoder main class with passed arguments
107 */
108 public static void jcoder(String[] args) {
109 org.openjdk.asmtools.jcoder.Main.main(args);
110 }
111
112 /**
113 * Invokes jdec main class with passed arguments
114 */
115 public static void jdec(String[] args) {
116 org.openjdk.asmtools.jdec.Main.main(args);
117 }
118
119 /**
120 * Invokes jdis main class with passed arguments
121 */
122 public static void jdis(String[] args) {
123 org.openjdk.asmtools.jdis.Main.main(args);
124 }
125 }