Skip to content
Permalink
Browse files

8222793: Javadoc tool ignores "-locale" param and uses default locale…

… for all messages and texts

Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Feb 5, 2020
1 parent c0f23a8 commit 98f5d98a8826800a5ea25d796977f4a558426e3c
@@ -39,6 +39,9 @@

import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;
import jdk.javadoc.doclet.StandardDoclet;
import jdk.javadoc.doclet.Taglet;
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
import jdk.javadoc.internal.doclets.toolkit.DocletException;
import jdk.javadoc.internal.doclets.toolkit.Messages;
@@ -113,13 +116,24 @@
private final HtmlOptions options;

/**
* Creates an object to hold the configuration for a doclet.
* Constructs the full configuration needed by the doclet, including
* the format-specific part, defined in this class, and the format-independent
* part, defined in the supertype.
*
* @param doclet the doclet
* @apiNote The {@code doclet} parameter is used when
* {@link Taglet#init(DocletEnvironment, Doclet) initializing tags}.
* Some doclets (such as the {@link StandardDoclet}), may delegate to another
* (such as the {@link HtmlDoclet}). In such cases, the primary doclet (i.e
* {@code StandardDoclet}) should be provided here, and not any internal
* class like {@code HtmlDoclet}.
*
* @param doclet the doclet for this run of javadoc
* @param locale the locale for the generated documentation
* @param reporter the reporter to use for console messages
*/
public HtmlConfiguration(Doclet doclet) {
super(doclet);
resources = new Resources(this,
public HtmlConfiguration(Doclet doclet, Locale locale, Reporter reporter) {
super(doclet, locale, reporter);
resources = new Resources(locale,
BaseConfiguration.sharedResourceBundleName,
"jdk.javadoc.internal.doclets.formats.html.resources.standard");

@@ -55,30 +55,50 @@
*/
public class HtmlDoclet extends AbstractDoclet {

public HtmlDoclet(Doclet parent) {
configuration = new HtmlConfiguration(parent);
/**
* Creates a doclet to generate HTML documentation,
* specifying the "initiating doclet" to be used when
* initializing any taglets for this doclet.
* An initiating doclet is one that delegates to
* this doclet.
*
* @param initiatingDoclet the initiating doclet
*/
public HtmlDoclet(Doclet initiatingDoclet) {
this.initiatingDoclet = initiatingDoclet;
}

@Override // defined by Doclet
public String getName() {
return "Html";
}

/**
* The initiating doclet, to be specified when creating
* the configuration.
*/
private final Doclet initiatingDoclet;

/**
* The global configuration information for this run.
* Initialized in {@link #init(Locale, Reporter)}.
*/
private final HtmlConfiguration configuration;
private HtmlConfiguration configuration;

/**
* Object for generating messages and diagnostics.
*/
private Messages messages;


/**
* Base path for resources for this doclet.
*/
private static final DocPath DOCLET_RESOURCES = DocPath
.create("/jdk/javadoc/internal/doclets/formats/html/resources");

@Override // defined by Doclet
public void init(Locale locale, Reporter reporter) {
configuration.reporter = reporter;
configuration.locale = locale;
configuration = new HtmlConfiguration(initiatingDoclet, locale, reporter);
messages = configuration.getMessages();
}

@@ -148,9 +148,9 @@
*/
public Extern extern;

public Reporter reporter;
public final Reporter reporter;

public Locale locale;
public final Locale locale;

public abstract Messages getMessages();

@@ -202,20 +202,23 @@
public PropertyUtils propertyUtils = null;

/**
* Constructs the configurations needed by the doclet.
* Constructs the format-independent configuration needed by the doclet.
*
* @apiNote
* The {@code doclet} parameter is used when {@link Taglet#init(DocletEnvironment, Doclet)
* initializing tags}.
* Some doclets (such as the {@link StandardDoclet), may delegate to another
* @apiNote The {@code doclet} parameter is used when
* {@link Taglet#init(DocletEnvironment, Doclet) initializing tags}.
* Some doclets (such as the {@link StandardDoclet}), may delegate to another
* (such as the {@link HtmlDoclet}). In such cases, the primary doclet (i.e
* {@code StandardDoclet}) should be provided here, and not any internal
* class like {@code HtmlDoclet}.
*
* @param doclet the doclet for this run of javadoc
* @param doclet the doclet for this run of javadoc
* @param locale the locale for the generated documentation
* @param reporter the reporter to use for console messages
*/
public BaseConfiguration(Doclet doclet) {
public BaseConfiguration(Doclet doclet, Locale locale, Reporter reporter) {
this.doclet = doclet;
this.locale = locale;
this.reporter = reporter;
}

public abstract BaseOptions getOptions();
@@ -45,7 +45,7 @@
public class Messages {
private final BaseConfiguration configuration;
private final Resources resources;
private Reporter reporter;
private final Reporter reporter;

/**
* Creates a {@code Messages} object to provide standardized access to
@@ -58,6 +58,7 @@
public Messages(BaseConfiguration configuration) {
this.configuration = configuration;
resources = configuration.getResources();
reporter = configuration.getReporter();
}

// ***** Errors *****
@@ -140,25 +141,14 @@ public void notice(String key, Object... args) {
// ***** Internal support *****

private void report(Diagnostic.Kind k, String msg) {
initReporter();
reporter.print(k, msg);
}

private void report(Diagnostic.Kind k, DocTreePath p, String msg) {
initReporter();
reporter.print(k, p, msg);
}

private void report(Diagnostic.Kind k, Element e, String msg) {
initReporter();
reporter.print(k, e, msg);
}

// Lazy init the reporter for now, until we can fix/improve
// the init of HtmlConfiguration in HtmlDoclet (and similar.)
private void initReporter() {
if (reporter == null) {
reporter = configuration.reporter;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@@ -41,9 +41,6 @@
public class Resources {
public final String annotationTypeSummary;
public final String classSummary;
private final BaseConfiguration configuration;
private final String commonBundleName;
private final String docletBundleName;
public final String enumSummary;
public final String errorSummary;
public final String exceptionSummary;
@@ -55,21 +52,21 @@
protected ResourceBundle docletBundle;

/**
* Creates a {@code Resources} to provide access the resource
* Creates a {@code Resources} object to provide access the resource
* bundles used by a doclet.
*
* @param configuration the configuration for the doclet,
* to provide access the locale to be used when accessing the
* names resource bundles.
* @param locale the locale to be used when accessing the
* resource bundles.
* @param commonBundleName the name of the bundle containing the strings
* common to all output formats
* common to all output formats
* @param docletBundleName the name of the bundle containing the strings
* specific to a particular format
* specific to a particular format
*/
public Resources(BaseConfiguration configuration, String commonBundleName, String docletBundleName) {
this.configuration = configuration;
this.commonBundleName = commonBundleName;
this.docletBundleName = docletBundleName;
public Resources(Locale locale, String commonBundleName, String docletBundleName) {

this.commonBundle = ResourceBundle.getBundle(commonBundleName, locale);
this.docletBundle = ResourceBundle.getBundle(docletBundleName, locale);

this.annotationTypeSummary = getText("doclet.Annotation_Types_Summary");
this.classSummary = getText("doclet.Class_Summary");
this.enumSummary = getText("doclet.Enum_Summary");
@@ -81,7 +78,7 @@ public Resources(BaseConfiguration configuration, String commonBundleName, Strin
}

/**
* Gets the string for the given key from one of the doclet's
* Returns the string for the given key from one of the doclet's
* resource bundles.
*
* The more specific bundle is checked first;
@@ -90,18 +87,16 @@ public Resources(BaseConfiguration configuration, String commonBundleName, Strin
* @param key the key for the desired string
* @return the string for the given key
* @throws MissingResourceException if the key is not found in either
* bundle.
* bundle.
*/
public String getText(String key) throws MissingResourceException {
initBundles();

if (docletBundle.containsKey(key))
return docletBundle.getString(key);

return commonBundle.getString(key);
}
/**
* Gets the string for the given key from one of the doclet's
* Returns the string for the given key from one of the doclet's
* resource bundles, substituting additional arguments into
* into the resulting string with {@link MessageFormat#format}.
*
@@ -117,16 +112,4 @@ public String getText(String key) throws MissingResourceException {
public String getText(String key, Object... args) throws MissingResourceException {
return MessageFormat.format(getText(key), args);
}

/**
* Lazily initializes the bundles. This is (currently) necessary because
* this object may be created before the locale to be used is known.
*/
protected void initBundles() {
if (commonBundle == null) {
Locale locale = configuration.getLocale();
this.commonBundle = ResourceBundle.getBundle(commonBundleName, locale);
this.docletBundle = ResourceBundle.getBundle(docletBundleName, locale);
}
}
}

0 comments on commit 98f5d98

Please sign in to comment.