test/langtools/jdk/javadoc/tool/CheckResourceKeys.java
author jjg
Wed, 23 May 2018 11:49:57 -0700
changeset 50240 b9c483223a91
parent 48543 7067fe4e054e
permissions -rw-r--r--
8202947: Fix minor issues with taglets Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     1
/*
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
     2
 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     4
 *
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     8
 *
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    13
 * accompanied this code).
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    14
 *
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    18
 *
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    21
 * questions.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    22
 */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    23
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    24
/*
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    25
 * @test
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    26
 * @bug 8000612
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    27
 * @summary need test program to validate javadoc resource bundles
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    28
 * @modules jdk.javadoc/jdk.javadoc.internal.tool
42496
49cd6effe616 8170953: CheckResourceKeys tests should declare the resource package to be open
jjg
parents: 41252
diff changeset
    29
 *          jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.resources:open
49cd6effe616 8170953: CheckResourceKeys tests should declare the resource package to be open
jjg
parents: 41252
diff changeset
    30
 *          jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.resources:open
49cd6effe616 8170953: CheckResourceKeys tests should declare the resource package to be open
jjg
parents: 41252
diff changeset
    31
 *          jdk.javadoc/jdk.javadoc.internal.tool.resources:open
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    32
 *          jdk.jdeps/com.sun.tools.classfile
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    33
 */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    34
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    35
import java.io.*;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    36
import java.util.*;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    37
import javax.tools.*;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    38
import com.sun.tools.classfile.*;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    39
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    40
/**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    41
 * Compare string constants in javadoc classes against keys in javadoc resource bundles.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    42
 */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    43
public class CheckResourceKeys {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    44
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    45
     * Main program.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    46
     * Options:
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    47
     * -finddeadkeys
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    48
     *      look for keys in resource bundles that are no longer required
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    49
     * -findmissingkeys
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    50
     *      look for keys in resource bundles that are missing
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    51
     *
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    52
     * @throws Exception if invoked by jtreg and errors occur
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    53
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    54
    public static void main(String... args) throws Exception {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    55
        CheckResourceKeys c = new CheckResourceKeys();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    56
        if (c.run(args))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    57
            return;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    58
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    59
        if (is_jtreg())
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    60
            throw new Exception(c.errors + " errors occurred");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    61
        else
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    62
            System.exit(1);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    63
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    64
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    65
    static boolean is_jtreg() {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    66
        return (System.getProperty("test.src") != null);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    67
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    68
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    69
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    70
     * Main entry point.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    71
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    72
    boolean run(String... args) throws Exception {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    73
        boolean findDeadKeys = false;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    74
        boolean findMissingKeys = false;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    75
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    76
        if (args.length == 0) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    77
            if (is_jtreg()) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    78
                findDeadKeys = true;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    79
                findMissingKeys = true;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    80
            } else {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    81
                System.err.println("Usage: java CheckResourceKeys <options>");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    82
                System.err.println("where options include");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    83
                System.err.println("  -finddeadkeys      find keys in resource bundles which are no longer required");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    84
                System.err.println("  -findmissingkeys   find keys in resource bundles that are required but missing");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    85
                return true;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    86
            }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    87
        } else {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    88
            for (String arg: args) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    89
                if (arg.equalsIgnoreCase("-finddeadkeys"))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    90
                    findDeadKeys = true;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    91
                else if (arg.equalsIgnoreCase("-findmissingkeys"))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    92
                    findMissingKeys = true;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    93
                else
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    94
                    error("bad option: " + arg);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    95
            }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    96
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    97
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    98
        if (errors > 0)
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
    99
            return false;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   100
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   101
        Set<String> codeKeys = getCodeKeys();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   102
        Set<String> resourceKeys = getResourceKeys();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   103
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   104
        System.err.println("found " + codeKeys.size() + " keys in code");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   105
        System.err.println("found " + resourceKeys.size() + " keys in resource bundles");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   106
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   107
        if (findDeadKeys)
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   108
            findDeadKeys(codeKeys, resourceKeys);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   109
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   110
        if (findMissingKeys)
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   111
            findMissingKeys(codeKeys, resourceKeys);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   112
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   113
        usageTests(false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   114
        usageTests(true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   115
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   116
        return (errors == 0);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   117
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   118
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   119
    void usageTests(boolean xflag) {
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
   120
        String[] argarray = { xflag ? "-X" : "--help" };
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   121
        StringWriter sw = new StringWriter();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   122
        PrintWriter pw = new PrintWriter(sw);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   123
        if (jdk.javadoc.internal.tool.Main.execute(argarray, pw) == 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   124
            pw.flush();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   125
            String s = sw.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   126
            if (s.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   127
                error("no javadoc output ?");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   128
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   129
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   130
            if (sw.toString().contains("<MISSING KEY>")) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   131
                System.out.println(s);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   132
                error("missing resources in output ?");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   133
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   134
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   135
            error("failed to execute javadoc");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   136
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   137
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   138
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   139
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   140
     * Find keys in resource bundles which are probably no longer required.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   141
     * A key is required if there is a string in the code that is a resource key,
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   142
     * or if the key is well-known according to various pragmatic rules.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   143
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   144
    void findDeadKeys(Set<String> codeKeys, Set<String> resourceKeys) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   145
        for (String rk: resourceKeys) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   146
            // ignore these synthesized keys, tested by usageTests
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   147
            if (rk.startsWith("doclet.usage.") || rk.startsWith("doclet.xusage"))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   148
                continue;
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   149
            // ignore these synthesized keys, tested by usageTests
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   150
            if (rk.matches("main\\.opt\\..*\\.(arg|desc)"))
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   151
                continue;
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   152
            if (codeKeys.contains(rk))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   153
                continue;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   154
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   155
            error("Resource key not found in code: '" + rk + '"');
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   156
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   157
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   158
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   159
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   160
     * For all strings in the code that look like they might be
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   161
     * a resource key, verify that a key exists.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   162
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   163
    void findMissingKeys(Set<String> codeKeys, Set<String> resourceKeys) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   164
        for (String ck: codeKeys) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   165
            // ignore these synthesized keys, tested by usageTests
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   166
            if (ck.startsWith("doclet.usage.") || ck.startsWith("doclet.xusage."))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   167
                continue;
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   168
            // ignore this partial key, tested by usageTests
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   169
            if (ck.equals("main.opt."))
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40308
diff changeset
   170
                continue;
50240
b9c483223a91 8202947: Fix minor issues with taglets
jjg
parents: 48543
diff changeset
   171
            // ignore this system property name
b9c483223a91 8202947: Fix minor issues with taglets
jjg
parents: 48543
diff changeset
   172
            if (ck.equals("javadoc.internal.show.taglets"))
b9c483223a91 8202947: Fix minor issues with taglets
jjg
parents: 48543
diff changeset
   173
                continue;
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   174
            if (resourceKeys.contains(ck))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   175
                continue;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   176
            error("No resource for \"" + ck + "\"");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   177
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   178
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   179
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   180
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   181
     * Get the set of strings from (most of) the javadoc classfiles.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   182
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   183
    Set<String> getCodeKeys() throws IOException {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   184
        Set<String> results = new TreeSet<String>();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   185
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   186
        try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   187
            JavaFileManager.Location javadocLoc = findJavadocLocation(fm);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   188
            String[] pkgs = {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   189
                "jdk.javadoc.internal.doclets",
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   190
                "jdk.javadoc.internal.tool"
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   191
            };
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   192
            for (String pkg: pkgs) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   193
                for (JavaFileObject fo: fm.list(javadocLoc,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   194
                        pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   195
                    String name = fo.getName();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   196
                    // ignore resource files
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   197
                    if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*"))
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   198
                        continue;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   199
                    scan(fo, results);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   200
                }
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   201
            }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   202
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   203
            // special handling for code strings synthesized in
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   204
            // com.sun.tools.doclets.internal.toolkit.util.Util.getTypeName
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   205
            String[] extras = {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   206
                "AnnotationType", "Class", "Enum", "Error", "Exception", "Interface"
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   207
            };
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   208
            for (String s: extras) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   209
                if (results.contains("doclet." + s))
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   210
                    results.add("doclet." + s.toLowerCase());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   211
            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   212
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   213
            // special handling for code strings synthesized in
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   214
            // com.sun.tools.javadoc.Messager
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   215
            results.add("javadoc.error.msg");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   216
            results.add("javadoc.note.msg");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   217
            results.add("javadoc.note.pos.msg");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   218
            results.add("javadoc.warning.msg");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   219
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 14545
diff changeset
   220
            return results;
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   221
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   222
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   223
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   224
    // depending on how the test is run, javadoc may be on bootclasspath or classpath
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   225
    JavaFileManager.Location findJavadocLocation(JavaFileManager fm) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   226
        JavaFileManager.Location[] locns =
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   227
            { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   228
        try {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   229
            for (JavaFileManager.Location l: locns) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   230
                JavaFileObject fo = fm.getJavaFileForInput(l,
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   231
                    "jdk.javadoc.internal.tool.Main", JavaFileObject.Kind.CLASS);
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   232
                if (fo != null) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   233
                    System.err.println("found javadoc in " + l);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   234
                    return l;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   235
                }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   236
            }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   237
        } catch (IOException e) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   238
            throw new Error(e);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   239
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   240
        throw new IllegalStateException("Cannot find javadoc");
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   241
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   242
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   243
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   244
     * Get the set of strings from a class file.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   245
     * Only strings that look like they might be a resource key are returned.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   246
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   247
    void scan(JavaFileObject fo, Set<String> results) throws IOException {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   248
        //System.err.println("scan " + fo.getName());
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   249
        InputStream in = fo.openInputStream();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   250
        try {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   251
            ClassFile cf = ClassFile.read(in);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   252
            for (ConstantPool.CPInfo cpinfo: cf.constant_pool.entries()) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   253
                if (cpinfo.getTag() == ConstantPool.CONSTANT_Utf8) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   254
                    String v = ((ConstantPool.CONSTANT_Utf8_info) cpinfo).value;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   255
                    if (v.matches("(doclet|main|javadoc|tag)\\.[A-Za-z0-9-_.]+"))
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   256
                        results.add(v);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   257
                }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   258
            }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   259
        } catch (ConstantPoolException ignore) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   260
        } finally {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   261
            in.close();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   262
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   263
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   264
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   265
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   266
     * Get the set of keys from the javadoc resource bundles.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   267
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   268
    Set<String> getResourceKeys() {
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 42496
diff changeset
   269
        Module jdk_javadoc = ModuleLayer.boot().findModule("jdk.javadoc").get();
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   270
        String[] names = {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   271
                "jdk.javadoc.internal.doclets.formats.html.resources.standard",
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   272
                "jdk.javadoc.internal.doclets.toolkit.resources.doclets",
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30846
diff changeset
   273
                "jdk.javadoc.internal.tool.resources.javadoc",
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   274
        };
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   275
        Set<String> results = new TreeSet<String>();
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   276
        for (String name : names) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   277
            ResourceBundle b = ResourceBundle.getBundle(name, jdk_javadoc);
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   278
            results.addAll(b.keySet());
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   279
        }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   280
        return results;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   281
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   282
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   283
    /**
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   284
     * Report an error.
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   285
     */
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   286
    void error(String msg) {
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   287
        System.err.println("Error: " + msg);
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   288
        errors++;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   289
    }
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   290
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   291
    int errors;
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
diff changeset
   292
}