1/*
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 8035473
27 * @summary Verify that init method works correctly.
28 * @modules jdk.javadoc/jdk.javadoc.internal.tool
29 * @ignore 8149565
30 */
31
32import java.util.Collections;
33import java.util.Locale;
34import java.util.Set;
35
36import javax.lang.model.SourceVersion;
37import javax.tools.Diagnostic.Kind;
38
39import jdk.javadoc.doclet.Doclet;
40import jdk.javadoc.doclet.Reporter;
41import jdk.javadoc.doclet.DocletEnvironment;
42
43public class VerifyLocale implements Doclet {
44    static String language;
45    static String country;
46    static String variant;
47
48    Locale locale;
49    Reporter reporter;
50
51    public static void main(String[] args) {
52        String thisFile = "" +
53            new java.io.File(System.getProperty("test.src", "."),
54                             "VerifyLocale.java");
55
56        for (Locale loc : Locale.getAvailableLocales()) {
57            language = loc.getLanguage();
58            country = loc.getCountry();
59            variant = loc.getVariant();
60            if (!language.equals("")) {
61                String[] command_line = {
62                    // jumble the options in some weird order
63                    "-doclet", "VerifyLocale",
64                    "-locale", language + (country.equals("") ? "" : ("_" + country + (variant.equals("") ? "" : "_" + variant))),
65                    "-docletpath", System.getProperty("test.classes", "."),
66                    thisFile
67                };
68                if (jdk.javadoc.internal.tool.Main.execute(command_line) != 0)
69                    throw new Error("Javadoc encountered warnings or errors.");
70            }
71        }
72    }
73
74    public boolean run(DocletEnvironment root) {
75        reporter.print(Kind.NOTE, "just a test: Locale is: " + locale.getDisplayName());
76        return language.equals(locale.getLanguage())
77               && country.equals(locale.getCountry())
78               && variant.equals(locale.getVariant());
79    }
80
81    @Override
82    public String getName() {
83        return "Test";
84    }
85
86    @Override
87    public Set<Option> getSupportedOptions() {
88        return Collections.emptySet();
89    }
90
91    @Override
92    public SourceVersion getSupportedSourceVersion() {
93        return SourceVersion.latest();
94    }
95
96    public void init(Locale locale, Reporter reporter) {
97        this.locale = locale;
98        this.reporter = reporter;
99    }
100}
101