Skip to content
Permalink
Browse files

8238437: Support separate locales for console messages and HTML content

Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Feb 8, 2020
1 parent faa88c1 commit 3461ce98003534b0fb5e13a50b1ec8dae26c17d1
Showing with 267 additions and 186 deletions.
  1. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java
  2. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Contents.java
  3. +27 −13 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java
  4. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
  5. +19 −30 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlOptions.java
  6. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkFactoryImpl.java
  7. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java
  8. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java
  9. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Navigation.java
  10. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java
  11. +12 −16 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java
  12. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseOptions.java
  13. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java
  14. +15 −5 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Messages.java
  15. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Resources.java
  16. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractBuilder.java
  17. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ParamTaglet.java
  18. +2 −9 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/PropertyGetterTaglet.java
  19. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/PropertySetterTaglet.java
  20. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java
  21. +2 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Extern.java
  22. +4 −4 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Group.java
  23. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/MetaKeywords.java
  24. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/StandardDocFileFactory.java
  25. +1 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
  26. +1 −22 src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java
  27. +63 −12 test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java
  28. +100 −50 test/langtools/jdk/javadoc/tool/testLocaleOption/TestLocaleOption.java
@@ -89,7 +89,7 @@ public AbstractMemberWriter(SubWriterHolderWriter writer, TypeElement typeElemen
this.typeElement = typeElement;
this.utils = configuration.utils;
this.contents = configuration.contents;
this.resources = configuration.resources;
this.resources = configuration.docResources;
this.links = writer.links;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, 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
@@ -182,7 +182,7 @@
* resources used to look up resource keys, and other details.
*/
Contents(HtmlConfiguration configuration) {
this.resources = configuration.getResources();
this.resources = configuration.getDocResources();

allClassesLabel = getNonBreakContent("doclet.All_Classes");
allImplementedInterfacesLabel = getContent("doclet.All_Implemented_Interfaces");
@@ -78,7 +78,7 @@
*/
public static final String HTML_DEFAULT_CHARSET = "utf-8";

public final Resources resources;
public final Resources docResources;

/**
* First file to appear in the right-hand frame in the generated
@@ -133,17 +133,31 @@
*/
public HtmlConfiguration(Doclet doclet, Locale locale, Reporter reporter) {
super(doclet, locale, reporter);
resources = new Resources(locale,

// Use the default locale for console messages.
Resources msgResources = new Resources(Locale.getDefault(),
BaseConfiguration.sharedResourceBundleName,
"jdk.javadoc.internal.doclets.formats.html.resources.standard");

messages = new Messages(this);
// Use the provided locale for generated docs
// Ideally, the doc resources would be in different resource files than the
// message resources, so that we do not have different copies of the same resources.
if (locale.equals(Locale.getDefault())) {
docResources = msgResources;
} else {
docResources = new Resources(locale,
BaseConfiguration.sharedResourceBundleName,
"jdk.javadoc.internal.doclets.formats.html.resources.standard");
}

messages = new Messages(this, msgResources);
contents = new Contents(this);
options = new HtmlOptions(this);

String v;
try {
ResourceBundle rb = ResourceBundle.getBundle(versionBundleName, getLocale());
// the version bundle is not localized
ResourceBundle rb = ResourceBundle.getBundle(versionBundleName, Locale.getDefault());
try {
v = rb.getString("release");
} catch (MissingResourceException e) {
@@ -166,10 +180,15 @@ public String getDocletVersion() {
}

@Override
public Resources getResources() {
return resources;
public Resources getDocResources() {
return docResources;
}

/**
* Returns a utility object providing commonly used fragments of content.
*
* @return a utility object providing commonly used fragments of content
*/
public Contents getContents() {
return contents;
}
@@ -335,12 +354,7 @@ protected void buildSearchTagIndex() {
Character unicode = (tagLabel.length() == 0)
? '*'
: Character.toUpperCase(tagLabel.charAt(0));
List<SearchIndexItem> list = tagSearchIndexMap.get(unicode);
if (list == null) {
list = new ArrayList<>();
tagSearchIndexMap.put(unicode, list);
}
list.add(sii);
tagSearchIndexMap.computeIfAbsent(unicode, k -> new ArrayList<>()).add(sii);
}
tagSearchIndexKeys = tagSearchIndexMap.keySet();
}
@@ -359,7 +373,7 @@ protected boolean finishOptionSettings0() throws DocletException {
if (options.charset() == null) {
options.setCharset(options.docEncoding());
} else if (!options.charset().equals(options.docEncoding())) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict", "-charset", "-docencoding"));
messages.error("doclet.Option_conflict", "-charset", "-docencoding");
return false;
}
}
@@ -213,7 +213,7 @@ public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path) {
this.options = configuration.getOptions();
this.contents = configuration.contents;
this.messages = configuration.messages;
this.resources = configuration.resources;
this.resources = configuration.docResources;
this.links = new Links(path);
this.utils = configuration.utils;
this.path = path;
@@ -33,15 +33,12 @@
import java.util.TreeSet;

import com.sun.tools.doclint.DocLint;
import jdk.javadoc.doclet.Reporter;
import jdk.javadoc.internal.doclets.toolkit.BaseOptions;
import jdk.javadoc.internal.doclets.toolkit.Messages;
import jdk.javadoc.internal.doclets.toolkit.Resources;
import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;

import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.WARNING;

/**
* Storage for all options supported by the
* {@link jdk.javadoc.doclet.StandardDoclet standard doclet},
@@ -199,8 +196,8 @@

@Override
public Set<? extends Option> getSupportedOptions() {
Resources resources = config.getResources();
Reporter reporter = config.getReporter();
Messages messages = config.getMessages();
Resources resources = messages.getResources();

List<Option> options = List.of(
new Option(resources, "--add-stylesheet", 1) {
@@ -255,13 +252,11 @@ public boolean process(String opt, List<String> args) {
@Override
public boolean process(String opt, List<String> args) {
if (noHelp) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-helpfile", "-nohelp"));
messages.error("doclet.Option_conflict", "-helpfile", "-nohelp");
return false;
}
if (!helpFile.isEmpty()) {
reporter.print(ERROR, resources.getText("doclet.Option_reuse",
"-helpfile"));
messages.error("doclet.Option_reuse", "-helpfile");
return false;
}
helpFile = args.get(0);
@@ -281,8 +276,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
noHelp = true;
if (!helpFile.isEmpty()) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-nohelp", "-helpfile"));
messages.error("doclet.Option_conflict", "-nohelp", "-helpfile");
return false;
}
return true;
@@ -302,8 +296,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
createIndex = false;
if (splitIndex) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-noindex", "-splitindex"));
messages.error("doclet.Option_conflict", "-noindex", "-splitindex");
return false;
}
return true;
@@ -323,8 +316,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
noOverview = true;
if (overviewPath != null) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-nooverview", "-overview"));
messages.error("doclet.Option_conflict", "-nooverview", "-overview");
return false;
}
return true;
@@ -344,8 +336,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
overviewPath = args.get(0);
if (noOverview) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-overview", "-nooverview"));
messages.error("doclet.Option_conflict", "-overview", "-nooverview");
return false;
}
return true;
@@ -365,8 +356,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
splitIndex = true;
if (!createIndex) {
reporter.print(ERROR, resources.getText("doclet.Option_conflict",
"-splitindex", "-noindex"));
messages.error("doclet.Option_conflict", "-splitindex", "-noindex");
return false;
}
return true;
@@ -418,11 +408,11 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
String dopt = opt.replace("-Xdoclint:", DocLint.XMSGS_CUSTOM_PREFIX);
if (dopt.contains("/")) {
reporter.print(ERROR, resources.getText("doclet.Option_doclint_no_qualifiers"));
messages.error("doclet.Option_doclint_no_qualifiers");
return false;
}
if (!DocLint.isValidOption(dopt)) {
reporter.print(ERROR, resources.getText("doclet.Option_doclint_invalid_arg"));
messages.error("doclet.Option_doclint_invalid_arg");
return false;
}
doclintOpts.add(dopt);
@@ -435,7 +425,7 @@ public boolean process(String opt, List<String> args) {
public boolean process(String opt, List<String> args) {
String dopt = opt.replace("-Xdoclint/package:", DocLint.XCHECK_PACKAGE);
if (!DocLint.isValidOption(dopt)) {
reporter.print(ERROR, resources.getText("doclet.Option_doclint_package_invalid_arg"));
messages.error("doclet.Option_doclint_package_invalid_arg");
return false;
}
doclintOpts.add(dopt);
@@ -450,7 +440,7 @@ public boolean process(String opt, List<String> args) {
try {
new URL(docrootParent);
} catch (MalformedURLException e) {
reporter.print(ERROR, resources.getText("doclet.MalformedURL", docrootParent));
messages.error("doclet.MalformedURL", docrootParent);
return false;
}
return true;
@@ -460,7 +450,7 @@ public boolean process(String opt, List<String> args) {
new XOption(resources, "--no-frames") {
@Override
public boolean process(String opt, List<String> args) {
reporter.print(WARNING, resources.getText("doclet.NoFrames_specified"));
messages.warning("doclet.NoFrames_specified");
return true;
}
}
@@ -477,30 +467,29 @@ protected boolean validateOptions() {
return false;
}

Resources resources = config.getResources();
Reporter reporter = config.getReporter();
Messages messages = config.getMessages();

// check if helpfile exists
if (!helpFile.isEmpty()) {
DocFile help = DocFile.createFileForInput(config, helpFile);
if (!help.exists()) {
reporter.print(ERROR, resources.getText("doclet.File_not_found", helpFile));
messages.error("doclet.File_not_found", helpFile);
return false;
}
}
// check if stylesheetFile exists
if (!stylesheetFile.isEmpty()) {
DocFile stylesheet = DocFile.createFileForInput(config, stylesheetFile);
if (!stylesheet.exists()) {
reporter.print(ERROR, resources.getText("doclet.File_not_found", stylesheetFile));
messages.error("doclet.File_not_found", stylesheetFile);
return false;
}
}
// check if additional stylesheets exists
for (String ssheet : additionalStylesheets) {
DocFile ssfile = DocFile.createFileForInput(config, ssheet);
if (!ssfile.exists()) {
reporter.print(ERROR, resources.getText("doclet.File_not_found", ssheet));
messages.error("doclet.File_not_found", ssheet);
return false;
}
}
@@ -234,7 +234,7 @@ public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
* @return the tool tip for the appropriate class.
*/
private String getClassToolTip(TypeElement typeElement, boolean isTypeLink) {
Resources resources = m_writer.configuration.getResources();
Resources resources = m_writer.configuration.getDocResources();
if (isTypeLink) {
return resources.getText("doclet.Href_Type_Param_Title",
utils.getSimpleName(typeElement));
@@ -97,7 +97,7 @@ private SourceToHTMLConverter(HtmlConfiguration configuration, DocletEnvironment
this.configuration = configuration;
this.options = configuration.getOptions();
this.messages = configuration.getMessages();
this.resources = configuration.resources;
this.resources = configuration.docResources;
this.utils = configuration.utils;
this.docEnv = rd;
this.outputdir = outputdir;
@@ -88,7 +88,7 @@ public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence, bo
configuration = htmlWriter.configuration;
options = configuration.getOptions();
utils = configuration.utils;
resources = configuration.getResources();
resources = configuration.getDocResources();
}

@Override
@@ -141,7 +141,7 @@ public Navigation(Element element, HtmlConfiguration configuration, PageMode pag
this.path = path;
this.pathToRoot = path.parent().invert();
this.links = new Links(path);
this.rowListTitle = configuration.getResources().getText("doclet.Navigation");
this.rowListTitle = configuration.getDocResources().getText("doclet.Navigation");
this.searchLabel = contents.getContent("doclet.search");
}

@@ -151,7 +151,7 @@ public boolean run(DocletEnvironment docEnv) {

private void reportInternalError(Throwable t) {
if (getClass().equals(StandardDoclet.class) || getClass().equals(HtmlDoclet.class)) {
System.err.println(configuration.getResources().getText("doclet.internal.report.bug"));
System.err.println(configuration.getDocResources().getText("doclet.internal.report.bug"));
}
dumpStack(true, t);
}

0 comments on commit 3461ce9

Please sign in to comment.