8006615: [doclint] move remaining messages into resource bundle
Reviewed-by: mcimadamore, vromero
--- a/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Mon Jun 03 16:56:54 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Mon Jun 03 17:09:26 2013 -0700
@@ -77,13 +77,14 @@
// <editor-fold defaultstate="collapsed" desc="Command-line entry point">
public static void main(String... args) {
+ DocLint dl = new DocLint();
try {
- new DocLint().run(args);
+ dl.run(args);
} catch (BadArgs e) {
System.err.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
- System.err.println(e);
+ System.err.println(dl.localize("dc.main.ioerror", e.getLocalizedMessage()));
System.exit(2);
}
}
@@ -92,9 +93,10 @@
// <editor-fold defaultstate="collapsed" desc="Simple API">
- public static class BadArgs extends Exception {
+ public class BadArgs extends Exception {
private static final long serialVersionUID = 0;
BadArgs(String code, Object... args) {
+ super(localize(code, args));
this.code = code;
this.args = args;
}
@@ -124,7 +126,7 @@
if (javacFiles.isEmpty()) {
if (!needHelp)
- out.println("no files given");
+ out.println(localize("dc.main.no.files.given"));
}
JavacTool tool = JavacTool.create();
@@ -204,49 +206,9 @@
}
void showHelp(PrintWriter out) {
- out.println("Usage:");
- out.println(" doclint [options] source-files...");
- out.println("");
- out.println("Options:");
- out.println(" -Xmsgs ");
- out.println(" Same as -Xmsgs:all");
- out.println(" -Xmsgs:values");
- out.println(" Specify categories of issues to be checked, where 'values'");
- out.println(" is a comma-separated list of any of the following:");
- out.println(" reference show places where comments contain incorrect");
- out.println(" references to Java source code elements");
- out.println(" syntax show basic syntax errors within comments");
- out.println(" html show issues with HTML tags and attributes");
- out.println(" accessibility show issues for accessibility");
- out.println(" missing show issues with missing documentation");
- out.println(" all all of the above");
- out.println(" Precede a value with '-' to negate it");
- out.println(" Categories may be qualified by one of:");
- out.println(" /public /protected /package /private");
- out.println(" For positive categories (not beginning with '-')");
- out.println(" the qualifier applies to that access level and above.");
- out.println(" For negative categories (beginning with '-')");
- out.println(" the qualifier applies to that access level and below.");
- out.println(" If a qualifier is missing, the category applies to");
- out.println(" all access levels.");
- out.println(" For example, -Xmsgs:all,-syntax/private");
- out.println(" This will enable all messages, except syntax errors");
- out.println(" in the doc comments of private methods.");
- out.println(" If no -Xmsgs options are provided, the default is");
- out.println(" equivalent to -Xmsgs:all/protected, meaning that");
- out.println(" all messages are reported for protected and public");
- out.println(" declarations only. ");
- out.println(" -stats");
- out.println(" Report statistics on the reported issues.");
- out.println(" -h -help --help -usage -?");
- out.println(" Show this message.");
- out.println("");
- out.println("The following javac options are also supported");
- out.println(" -bootclasspath, -classpath, -sourcepath, -Xmaxerrs, -Xmaxwarns");
- out.println("");
- out.println("To run doclint on part of a project, put the compiled classes for your");
- out.println("project on the classpath (or bootclasspath), then specify the source files");
- out.println("to be checked on the command line.");
+ String msg = localize("dc.main.usage");
+ for (String line: msg.split("\n"))
+ out.println(line);
}
List<File> splitPath(String path) {
@@ -353,6 +315,11 @@
return false;
}
+ private String localize(String code, Object... args) {
+ Messages m = (env != null) ? env.messages : new Messages(null);
+ return m.localize(code, args);
+ }
+
// <editor-fold defaultstate="collapsed" desc="DeclScanner">
static abstract class DeclScanner extends TreePathScanner<Void, Void> {
--- a/langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties Mon Jun 03 16:56:54 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclint/resources/doclint.properties Mon Jun 03 17:09:26 2013 -0700
@@ -67,3 +67,50 @@
dc.tag.start.unmatched = end tag missing: </{0}>
dc.tag.unknown = unknown tag: {0}
dc.text.not.allowed = text not allowed in <{0}> element
+
+dc.main.ioerror=IO error: {0}
+dc.main.no.files.given=No files given
+dc.main.usage=\
+Usage:\n\
+\ doclint [options] source-files...\n\
+\n\
+Options:\n\
+\ -Xmsgs \n\
+\ Same as -Xmsgs:all\n\
+\ -Xmsgs:values\n\
+\ Specify categories of issues to be checked, where ''values''\n\
+\ is a comma-separated list of any of the following:\n\
+\ reference show places where comments contain incorrect\n\
+\ references to Java source code elements\n\
+\ syntax show basic syntax errors within comments\n\
+\ html show issues with HTML tags and attributes\n\
+\ accessibility show issues for accessibility\n\
+\ missing show issues with missing documentation\n\
+\ all all of the above\n\
+\ Precede a value with ''-'' to negate it\n\
+\ Categories may be qualified by one of:\n\
+\ /public /protected /package /private\n\
+\ For positive categories (not beginning with ''-'')\n\
+\ the qualifier applies to that access level and above.\n\
+\ For negative categories (beginning with ''-'')\n\
+\ the qualifier applies to that access level and below.\n\
+\ If a qualifier is missing, the category applies to\n\
+\ all access levels.\n\
+\ For example, -Xmsgs:all,-syntax/private\n\
+\ This will enable all messages, except syntax errors\n\
+\ in the doc comments of private methods.\n\
+\ If no -Xmsgs options are provided, the default is\n\
+\ equivalent to -Xmsgs:all/protected, meaning that\n\
+\ all messages are reported for protected and public\n\
+\ declarations only. \n\
+\ -stats\n\
+\ Report statistics on the reported issues.\n\
+\ -h -help --help -usage -?\n\
+\ Show this message.\n\
+\n\
+The following javac options are also supported\n\
+\ -bootclasspath, -classpath, -sourcepath, -Xmaxerrs, -Xmaxwarns\n\
+\n\
+To run doclint on part of a project, put the compiled classes for your\n\
+project on the classpath (or bootclasspath), then specify the source files\n\
+to be checked on the command line.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/ResourceTest.java Mon Jun 03 17:09:26 2013 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006615
+ * @summary move remaining messages into resource bundle
+ */
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+import com.sun.tools.doclint.DocLint;
+
+public class ResourceTest {
+ public static void main(String... args) throws Exception {
+ Locale prev = Locale.getDefault();
+ Locale.setDefault(Locale.ENGLISH);
+ try {
+ new ResourceTest().run();
+ } finally {
+ Locale.setDefault(prev);
+ }
+ }
+
+ public void run() throws Exception {
+ test(Arrays.asList("-help"),
+ Arrays.asList("Usage:", "Options"));
+ test(Arrays.asList("-foo"),
+ Arrays.asList("bad option: -foo"));
+ }
+
+ void test(List<String> opts, List<String> expects) throws Exception {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ try {
+ new DocLint().run(pw, opts.toArray(new String[opts.size()]));
+ } catch (DocLint.BadArgs e) {
+ pw.println("BadArgs: " + e.getMessage());
+ } catch (IOException e) {
+ pw.println("IOException: " + e.getMessage());
+ } finally {
+ pw.close();
+ }
+
+ String out = sw.toString();
+ if (!out.isEmpty()) {
+ System.err.println(out);
+ }
+
+ for (String e: expects) {
+ if (!out.contains(e))
+ throw new Exception("expected string not found: " + e);
+ }
+ }
+}
+
--- a/langtools/test/tools/doclint/tool/RunTest.java Mon Jun 03 16:56:54 2013 -0700
+++ b/langtools/test/tools/doclint/tool/RunTest.java Mon Jun 03 17:09:26 2013 -0700
@@ -173,7 +173,7 @@
pw.close();
String out = sw.toString();
- String expect = "no files given";
+ String expect = "No files given";
if (!Objects.equals(out.trim(), expect)) {
error("unexpected output");
System.err.println("EXPECT>>" + expect + "<<");