Path: blob/master/test/langtools/jdk/javadoc/tool/VerifyLocale.java
40957 views
/*1* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8035473 814956526* @summary Verify that init method works correctly.27* @modules jdk.javadoc/jdk.javadoc.internal.tool28*/2930import java.nio.file.Path;31import java.nio.file.Paths;32import java.util.Collections;33import java.util.List;34import java.util.Locale;35import java.util.Set;3637import javax.lang.model.SourceVersion;38import javax.tools.Diagnostic.Kind;39import javax.tools.DocumentationTool;40import javax.tools.DocumentationTool.DocumentationTask;41import javax.tools.JavaFileObject;42import javax.tools.ToolProvider;4344import jdk.javadoc.doclet.Doclet;45import jdk.javadoc.doclet.Reporter;46import jdk.javadoc.doclet.DocletEnvironment;4748public class VerifyLocale implements Doclet {49static String language;50static String country;51static String variant;5253Locale locale;54Reporter reporter;5556public static void main(String[] args) {57DocumentationTool tool = ToolProvider.getSystemDocumentationTool();58Path thisFile =59Paths.get(System.getProperty("test.src", ".")).resolve("VerifyLocale.java");60JavaFileObject fo = tool.getStandardFileManager(null, null, null)61.getJavaFileObjects(thisFile).iterator().next();6263int skipCount = 0;64int testCount = 0;6566for (Locale loc : Locale.getAvailableLocales()) {6768language = loc.getLanguage();69country = loc.getCountry();70variant = loc.getVariant();71System.err.printf("test locale: %s [%s,%s,%s] %s%n",72loc, language, country, variant, loc.toLanguageTag());7374// skip locales for which the round-trip fails75if (!loc.equals(Locale.forLanguageTag(loc.toLanguageTag()))) {76System.err.println("skipped " + loc + "!");77System.err.println();78skipCount++;79continue;80}8182if (!language.equals("")) {83List<String> options = List.of("-locale", loc.toLanguageTag());84System.err.println("test options: " + options);85DocumentationTask t = tool.getTask(null, null, null,86VerifyLocale.class, options, List.of(fo));87if (!t.call())88throw new Error("Javadoc encountered warnings or errors.");89testCount++;90}91System.err.println();92}93System.err.println("Skipped " + skipCount + " locales");94System.err.println("Tested " + testCount + " locales");95}9697public boolean run(DocletEnvironment root) {98reporter.print(Kind.NOTE, String.format("doclet locale is: %s [%s,%s,%s] %s (%s)",99locale,100locale.getLanguage(),101locale.getCountry(),102locale.getVariant(),103locale.toLanguageTag(),104locale.getDisplayName()));105return language.equals(locale.getLanguage())106&& country.equals(locale.getCountry())107&& variant.equals(locale.getVariant());108}109110@Override111public String getName() {112return "Test";113}114115@Override116public Set<Option> getSupportedOptions() {117return Collections.emptySet();118}119120@Override121public SourceVersion getSupportedSourceVersion() {122return SourceVersion.latest();123}124125public void init(Locale locale, Reporter reporter) {126this.locale = locale;127this.reporter = reporter;128}129}130131132