CheckResourceKeys.java revision 604
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 2362N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @bug 6964768 6964461 6964469 6964487 6964460 6964481 0N/A * @summary need test program to validate javac resource bundles 4378N/A * Compare string constants in javac classes against keys in javac resource bundles. 0N/A * look for keys in resource bundles that are no longer required 0N/A * look for keys in resource bundles that are missing 0N/A * @throws Exception if invoked by jtreg and errors occur 0N/A System.
err.
println(
" -finddeadkeys find keys in resource bundles which are no longer required");
0N/A System.
err.
println(
" -findmissingkeys find keys in resource bundles that are required but missing");
0N/A * Find keys in resource bundles which are probably no longer required. 0N/A * A key is probably required if there is a string fragment in the code 0N/A * that is part of the resource key, or if the key is well-known 0N/A * according to various pragmatic rules. "compiler.err.",
"compiler.warn.",
"compiler.note.",
"compiler.misc.",
// some keys are used directly, without a prefix. // remove standard prefix error(
"Resource key does not start with a standard prefix: " +
rk);
// keys ending in .1 are often synthesized // verbose keys are generated by ClassReader.printVerbose // mandatory warning messages are synthesized with no characteristic substring // check known (valid) exceptions error(
"Resource key not found in code: " +
rk);
* The keys for mandatory warning messages are all synthesized and do not * have a significant recognizable substring to look for. String[]
bases = {
"deprecated",
"unchecked",
"varargs",
"sunapi" };
String[]
tails = {
".filename",
".filename.additional",
".plural",
".plural.additional",
".recompile" };
// See Resolve.getErrorKey "compiler.err.cant.resolve.args",
"compiler.err.cant.resolve.args.params",
"compiler.err.cant.resolve.location.args",
"compiler.err.cant.resolve.location.args.params",
// JavaCompiler, reports #errors and #warnings "compiler.misc.count.error",
"compiler.misc.count.error.plural",
"compiler.misc.count.warn",
"compiler.misc.count.warn.plural",
"compiler.warn.lintOption",
"compiler.misc.base.membership" // (sic) "compiler.err.cant.read.file",
// UNUSED "compiler.err.illegal.self.ref",
// UNUSED "compiler.err.io.exception",
// UNUSED "compiler.err.limit.pool.in.class",
// UNUSED "compiler.err.name.reserved.for.internal.use",
// UNUSED "compiler.err.no.match.entry",
// UNUSED "compiler.err.not.within.bounds.explain",
// UNUSED "compiler.err.signature.doesnt.match.intf",
// UNUSED "compiler.err.signature.doesnt.match.supertype",
// UNUSED "compiler.err.type.var.more.than.once",
// UNUSED "compiler.err.type.var.more.than.once.in.result",
// UNUSED "compiler.misc.ccf.found.later.version",
// UNUSED "compiler.misc.non.denotable.type",
// UNUSED "compiler.misc.unnamed.package",
// should be required, CR 6964147 "compiler.misc.verbose.retro",
// UNUSED "compiler.misc.verbose.retro.with",
// UNUSED "compiler.misc.verbose.retro.with.list",
// UNUSED "compiler.warn.proc.type.already.exists",
// TODO in JavacFiler "javac.err.invalid.arg",
// UNUSED ?? "javac.opt.arg.class",
// UNUSED ?? "javac.opt.arg.pathname",
// UNUSED ?? "javac.opt.moreinfo",
// option commented out "javac.opt.nogj",
// UNUSED "javac.opt.printflat",
// option commented out "javac.opt.printsearch",
// option commented out "javac.opt.prompt",
// option commented out "javac.opt.retrofit",
// UNUSED "javac.opt.s",
// option commented out "javac.opt.scramble",
// option commented out "javac.opt.scrambleall" // option commented out * For all strings in the code that look like they might be fragments of * a resource key, verify that a key exists. // ignore filenames (i.e. in SourceFile attribute // ignore package and class names if (
cs.
matches(
"(com|java|javax|sun)\\.[A-Za-z.]+"))
// explicit known exceptions // look for matching resource error(
"no match for \"" +
cs +
"\"");
* Look for a resource that ends in this string fragment. * Get the set of strings from (most of) the javac classfiles. "javax.annotation.processing",
// ignore resource files, and files which are not really part of javac // depending on how the test is run, javac may be on bootclasspath or classpath * Get the set of strings from a class file. * Only strings that look like they might be a resource key are returned. * Get the set of keys from the javac resource bundles.