8177048: javadoc should support -version and/or --version
authorpmuthuswamy
Sat, 15 Jul 2017 11:06:32 -0700
changeset 45912 865870b7fe9b
parent 45911 d0cc0622370f
child 45913 90f6a96c1603
8177048: javadoc should support -version and/or --version Reviewed-by: jjg, ksrini
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties
langtools/test/jdk/javadoc/doclet/testVersionOption/TestVersionOption.java
langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java	Thu Jul 13 19:34:31 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java	Sat Jul 15 11:06:32 2017 -0700
@@ -38,7 +38,9 @@
 import java.util.Comparator;
 import java.util.List;
 import java.util.Locale;
+import java.util.MissingResourceException;
 import java.util.Objects;
+import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -177,6 +179,16 @@
         usage("main.Xusage", OptionKind.EXTENDED, "main.Xusage.foot");
     }
 
+    @Override
+    void version() {
+        messager.notice("javadoc.version", messager.programName, version("release"));
+    }
+
+    @Override
+    void fullVersion() {
+        messager.notice("javadoc.fullversion", messager.programName, version("full"));
+    }
+
     private void usage(String headerKey, OptionKind kind, String footerKey) {
         messager.notice(headerKey);
         showToolOptions(kind);
@@ -193,6 +205,24 @@
             messager.notice(footerKey);
     }
 
+    private static final String versionRBName = "jdk.javadoc.internal.tool.resources.version";
+    private static ResourceBundle versionRB;
+
+    private static String version(String key) {
+        if (versionRB == null) {
+            try {
+                versionRB = ResourceBundle.getBundle(versionRBName);
+            } catch (MissingResourceException e) {
+                return Log.getLocalizedString("version.not.available");
+            }
+        }
+        try {
+            return versionRB.getString(key);
+        } catch (MissingResourceException e) {
+            return Log.getLocalizedString("version.not.available");
+        }
+    }
+
     void showToolOptions(OptionKind kind) {
         Comparator<ToolOption> comp = new Comparator<ToolOption>() {
             final Collator collator = Collator.getInstance(Locale.US);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java	Thu Jul 13 19:34:31 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolOption.java	Sat Jul 15 11:06:32 2017 -0700
@@ -359,6 +359,20 @@
         public void process(Helper helper) {
             throw new AssertionError("the -J flag should be caught by the launcher.");
         }
+    },
+
+    VERSION("--version", STANDARD) {
+        @Override
+        public void process(Helper helper) throws OptionException {
+            throw new OptionException(OK, helper::version);
+        }
+    },
+
+    FULLVERSION("--full-version", HIDDEN) {
+        @Override
+        public void process(Helper helper) throws OptionException {
+            throw new OptionException(OK, helper::fullVersion);
+        }
     };
 
     public final String primaryName;
@@ -456,6 +470,9 @@
         abstract void usage();
         abstract void Xusage();
 
+        abstract void version();
+        abstract void fullVersion();
+
         abstract String getLocalizedMessage(String msg, Object... args);
 
         abstract OptionHelper getOptionHelper();
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties	Thu Jul 13 19:34:31 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties	Sat Jul 15 11:06:32 2017 -0700
@@ -200,6 +200,9 @@
 main.opt.quiet.desc=\
     Do not display status messages
 
+main.opt.version.desc=\
+    Print version information
+
 main.opt.J.arg=\
     <flag>
 main.opt.J.desc=\
@@ -306,3 +309,5 @@
 javadoc.warning.msg={0}: warning - {1}
 javadoc.note.msg = {1}
 javadoc.note.pos.msg= {0}: {1}
+javadoc.version={0} {1}
+javadoc.fullversion={0} full version "{1}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testVersionOption/TestVersionOption.java	Sat Jul 15 11:06:32 2017 -0700
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017, 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      8177048
+ * @summary  javadoc should support --version and --full-version flags
+ * @library ../lib
+ * @modules jdk.javadoc/jdk.javadoc.internal.tool
+ * @build    JavadocTester TestVersionOption
+ * @run main TestVersionOption
+ */
+
+public class TestVersionOption extends JavadocTester {
+
+    public static void main(String... args) throws Exception {
+        TestVersionOption tester = new TestVersionOption();
+        tester.runTests();
+    }
+
+    @Test
+    void testFullVersionOption() {
+        javadoc("--full-version");
+        checkExit(Exit.OK);
+
+        checkOutput(Output.OUT, true, "javadoc full version \"" + System.getProperty("java.runtime.version") + "\"");
+    }
+
+
+    @Test
+    void testVersionOption() {
+        javadoc("--version");
+        checkExit(Exit.OK);
+
+        checkOutput(Output.OUT, true, "javadoc " + System.getProperty("java.version"));
+    }
+
+}
--- a/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java	Thu Jul 13 19:34:31 2017 +0000
+++ b/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java	Sat Jul 15 11:06:32 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2017, 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
@@ -91,6 +91,7 @@
 
     static {
         ignore("javax/tools/ToolProvider", "instance");
+        ignore("jdk/javadoc/internal/tool/Start", "versionRB");
         ignore("com/sun/tools/javah/JavahTask", "versionRB");
         ignore("com/sun/tools/classfile/Dependencies$DefaultFilter", "instance");
         ignore("com/sun/tools/javap/JavapTask", "versionRB");