1 /*
2 * Copyright (c) 2002, 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
74 public final Throwable cause;
75 }
76
77 /*
78 * Help for verbosity.
79 */
80 public boolean verbose = false;
81
82 public PrintWriter log;
83 public DiagnosticListener<? super JavaFileObject> dl;
84
85 Util(PrintWriter log, DiagnosticListener<? super JavaFileObject> dl) {
86 this.log = log;
87 this.dl = dl;
88 }
89
90 public void log(String s) {
91 log.println(s);
92 }
93
94
95 /*
96 * Help for loading localized messages.
97 */
98 private ResourceBundle m;
99
100 private void initMessages() throws Exit {
101 try {
102 m = ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n");
103 } catch (MissingResourceException mre) {
104 fatal("Error loading resources. Please file a bug report.", mre);
105 }
106 }
107
108 private String getText(String key, Object... args) throws Exit {
109 if (m == null)
110 initMessages();
111 try {
112 return MessageFormat.format(m.getString(key), args);
113 } catch (MissingResourceException e) {
114 fatal("Key " + key + " not found in resources.", e);
115 }
116 return null; /* dead code */
117 }
118
119 /*
120 * Usage message.
121 */
122 public void usage() throws Exit {
123 log.println(getText("usage"));
124 }
125
126 public void version() throws Exit {
127 log.println(getText("javah.version",
128 System.getProperty("java.version"), null));
129 }
130
131 /*
132 * Failure modes.
133 */
134 public void bug(String key) throws Exit {
135 bug(key, null);
136 }
137
138 public void bug(String key, Exception e) throws Exit {
139 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key));
140 dl.report(createDiagnostic(Diagnostic.Kind.NOTE, "bug.report"));
141 throw new Exit(11, e);
142 }
143
144 public void error(String key, Object... args) throws Exit {
145 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key, args));
146 throw new Exit(15);
147 }
148
149 private void fatal(String msg, Exception e) throws Exit {
150 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, "", msg));
151 throw new Exit(10, e);
|
1 /*
2 * Copyright (c) 2002, 2016, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
74 public final Throwable cause;
75 }
76
77 /*
78 * Help for verbosity.
79 */
80 public boolean verbose = false;
81
82 public PrintWriter log;
83 public DiagnosticListener<? super JavaFileObject> dl;
84
85 Util(PrintWriter log, DiagnosticListener<? super JavaFileObject> dl) {
86 this.log = log;
87 this.dl = dl;
88 }
89
90 public void log(String s) {
91 log.println(s);
92 }
93
94 /*
95 * Help for loading localized messages.
96 */
97 private ResourceBundle m;
98
99 private void initMessages() throws Exit {
100 try {
101 m = ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n");
102 } catch (MissingResourceException mre) {
103 fatal("Error loading resources. Please file a bug report.", mre);
104 }
105 }
106
107 private String getText(String key, Object... args) throws Exit {
108 if (m == null)
109 initMessages();
110 try {
111 return MessageFormat.format(m.getString(key), args);
112 } catch (MissingResourceException e) {
113 fatal("Key " + key + " not found in resources.", e);
114 }
115 return null; /* dead code */
116 }
117
118 /*
119 * Failure modes.
120 */
121 public void bug(String key) throws Exit {
122 bug(key, null);
123 }
124
125 public void bug(String key, Exception e) throws Exit {
126 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key));
127 dl.report(createDiagnostic(Diagnostic.Kind.NOTE, "bug.report"));
128 throw new Exit(11, e);
129 }
130
131 public void error(String key, Object... args) throws Exit {
132 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key, args));
133 throw new Exit(15);
134 }
135
136 private void fatal(String msg, Exception e) throws Exit {
137 dl.report(createDiagnostic(Diagnostic.Kind.ERROR, "", msg));
138 throw new Exit(10, e);
|