8149565: -locale option issues

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2018-06-18 13:40:16 -07:00
parent 72a9d65a2c
commit b75d70e381
4 changed files with 56 additions and 56 deletions

View File

@ -36,6 +36,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.IllformedLocaleException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.MissingResourceException; import java.util.MissingResourceException;
@ -853,46 +854,17 @@ public class Start extends ToolOption.Helper {
* then return default locale. * then return default locale.
*/ */
private Locale getLocale(String localeName) throws ToolException { private Locale getLocale(String localeName) throws ToolException {
Locale userlocale = null; try {
if (localeName == null || localeName.isEmpty()) { // Tolerate, at least for a while, the older syntax accepted by javadoc,
return Locale.getDefault(); // using _ as the separator
} localeName = localeName.replace("_", "-");
int firstuscore = localeName.indexOf('_'); Locale l = new Locale.Builder().setLanguageTag(localeName).build();
int seconduscore = -1; // Ensure that a non-empty language is available for the <HTML lang=...> element
String language = null; return (l.getLanguage().isEmpty()) ? Locale.ENGLISH : l;
String country = null; } catch (IllformedLocaleException e) {
String variant = null;
if (firstuscore == 2) {
language = localeName.substring(0, firstuscore);
seconduscore = localeName.indexOf('_', firstuscore + 1);
if (seconduscore > 0) {
if (seconduscore != firstuscore + 3
|| localeName.length() <= seconduscore + 1) {
String text = messager.getText("main.malformed_locale_name", localeName);
throw new ToolException(CMDERR, text);
}
country = localeName.substring(firstuscore + 1,
seconduscore);
variant = localeName.substring(seconduscore + 1);
} else if (localeName.length() == firstuscore + 3) {
country = localeName.substring(firstuscore + 1);
} else {
String text = messager.getText("main.malformed_locale_name", localeName);
throw new ToolException(CMDERR, text);
}
} else if (firstuscore == -1 && localeName.length() == 2) {
language = localeName;
} else {
String text = messager.getText("main.malformed_locale_name", localeName); String text = messager.getText("main.malformed_locale_name", localeName);
throw new ToolException(CMDERR, text); throw new ToolException(CMDERR, text);
} }
userlocale = searchLocale(language, country, variant);
if (userlocale == null) {
String text = messager.getText("main.illegal_locale_name", localeName);
throw new ToolException(CMDERR, text);
} else {
return userlocale;
}
} }
/** /**

View File

@ -285,7 +285,6 @@ main.doclet_could_not_set_location=Could not set location for {0}
main.doclet_no_classloader_found=Could not obtain classloader to load {0} main.doclet_no_classloader_found=Could not obtain classloader to load {0}
main.could_not_instantiate_class=Could not instantiate class {0} main.could_not_instantiate_class=Could not instantiate class {0}
main.doclet_class_not_found=Cannot find doclet class {0} main.doclet_class_not_found=Cannot find doclet class {0}
main.illegal_locale_name=Locale not available: {0}
main.malformed_locale_name=Malformed locale name: {0} main.malformed_locale_name=Malformed locale name: {0}
main.file_not_found=File not found: "{0}" main.file_not_found=File not found: "{0}"
main.illegal_class_name=Illegal class name: "{0}" main.illegal_class_name=Illegal class name: "{0}"

View File

@ -26,7 +26,6 @@
########################################################################### ###########################################################################
# #
# javadoc # javadoc
jdk/javadoc/tool/VerifyLocale.java 8149565 generic-all -locale option issues
jdk/javadoc/tool/enum/docComments/Main.java 8152313 generic-all convert to doclet test framework jdk/javadoc/tool/enum/docComments/Main.java 8152313 generic-all convert to doclet test framework
jdk/javadoc/tool/enum/enumType/Main.java 8152313 generic-all convert to doclet test framework jdk/javadoc/tool/enum/enumType/Main.java 8152313 generic-all convert to doclet test framework
jdk/javadoc/tool/varArgs/Main.java 8152313 generic-all convert to doclet test framework jdk/javadoc/tool/varArgs/Main.java 8152313 generic-all convert to doclet test framework

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,18 +23,24 @@
/* /*
* @test * @test
* @bug 8035473 * @bug 8035473 8149565
* @summary Verify that init method works correctly. * @summary Verify that init method works correctly.
* @modules jdk.javadoc/jdk.javadoc.internal.tool * @modules jdk.javadoc/jdk.javadoc.internal.tool
* @ignore 8149565
*/ */
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import javax.tools.DocumentationTool;
import javax.tools.DocumentationTool.DocumentationTask;
import javax.tools.JavaFileObject;
import javax.tools.ToolProvider;
import jdk.javadoc.doclet.Doclet; import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.Reporter; import jdk.javadoc.doclet.Reporter;
@ -49,30 +55,54 @@ public class VerifyLocale implements Doclet {
Reporter reporter; Reporter reporter;
public static void main(String[] args) { public static void main(String[] args) {
String thisFile = "" + DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
new java.io.File(System.getProperty("test.src", "."), Path thisFile =
"VerifyLocale.java"); Paths.get(System.getProperty("test.src", ".")).resolve("VerifyLocale.java");
JavaFileObject fo = tool.getStandardFileManager(null, null, null)
.getJavaFileObjects(thisFile).iterator().next();
int skipCount = 0;
int testCount = 0;
for (Locale loc : Locale.getAvailableLocales()) { for (Locale loc : Locale.getAvailableLocales()) {
language = loc.getLanguage(); language = loc.getLanguage();
country = loc.getCountry(); country = loc.getCountry();
variant = loc.getVariant(); variant = loc.getVariant();
if (!language.equals("")) { System.err.printf("test locale: %s [%s,%s,%s] %s%n",
String[] command_line = { loc, language, country, variant, loc.toLanguageTag());
// jumble the options in some weird order
"-doclet", "VerifyLocale", // skip locales for which the round-trip fails
"-locale", language + (country.equals("") ? "" : ("_" + country + (variant.equals("") ? "" : "_" + variant))), if (!loc.equals(Locale.forLanguageTag(loc.toLanguageTag()))) {
"-docletpath", System.getProperty("test.classes", "."), System.err.println("skipped " + loc + "!");
thisFile System.err.println();
}; skipCount++;
if (jdk.javadoc.internal.tool.Main.execute(command_line) != 0) continue;
throw new Error("Javadoc encountered warnings or errors.");
} }
if (!language.equals("")) {
List<String> options = List.of("-locale", loc.toLanguageTag());
System.err.println("test options: " + options);
DocumentationTask t = tool.getTask(null, null, null,
VerifyLocale.class, options, List.of(fo));
if (!t.call())
throw new Error("Javadoc encountered warnings or errors.");
testCount++;
}
System.err.println();
} }
System.err.println("Skipped " + skipCount + " locales");
System.err.println("Tested " + testCount + " locales");
} }
public boolean run(DocletEnvironment root) { public boolean run(DocletEnvironment root) {
reporter.print(Kind.NOTE, "just a test: Locale is: " + locale.getDisplayName()); reporter.print(Kind.NOTE, String.format("doclet locale is: %s [%s,%s,%s] %s (%s)",
locale,
locale.getLanguage(),
locale.getCountry(),
locale.getVariant(),
locale.toLanguageTag(),
locale.getDisplayName()));
return language.equals(locale.getLanguage()) return language.equals(locale.getLanguage())
&& country.equals(locale.getCountry()) && country.equals(locale.getCountry())
&& variant.equals(locale.getVariant()); && variant.equals(locale.getVariant());