8177048: javadoc should support -version and/or --version
Reviewed-by: jjg, ksrini
This commit is contained in:
parent
e9afe31818
commit
0fc53f8797
@ -38,7 +38,9 @@ import java.util.Collections;
|
||||
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 @@ public class Start extends ToolOption.Helper {
|
||||
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 @@ public class Start extends ToolOption.Helper {
|
||||
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);
|
||||
|
@ -359,6 +359,20 @@ public enum ToolOption {
|
||||
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 @@ public enum ToolOption {
|
||||
abstract void usage();
|
||||
abstract void Xusage();
|
||||
|
||||
abstract void version();
|
||||
abstract void fullVersion();
|
||||
|
||||
abstract String getLocalizedMessage(String msg, Object... args);
|
||||
|
||||
abstract OptionHelper getOptionHelper();
|
||||
|
@ -200,6 +200,9 @@ main.opt.encoding.desc=\
|
||||
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.error.msg={0}: error - {1}
|
||||
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}"
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
@ -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 @@ public class DetectMutableStaticFields {
|
||||
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user