test/jdk/javadoc/tool/CheckResourceKeys.java

Print this page

        

@@ -104,20 +104,46 @@
             findDeadKeys(codeKeys, resourceKeys);
 
         if (findMissingKeys)
             findMissingKeys(codeKeys, resourceKeys);
 
+        usageTests(false);
+        usageTests(true);
+
         return (errors == 0);
     }
 
+    void usageTests(boolean xflag) {
+        String[] argarray = { xflag ? "-X" : "-help" };
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        if (jdk.javadoc.internal.tool.Main.execute(argarray, pw) == 0) {
+            pw.flush();
+            String s = sw.toString();
+            if (s.isEmpty()) {
+                error("no javadoc output ?");
+                return;
+            }
+            if (sw.toString().contains("<MISSING KEY>")) {
+                System.out.println(s);
+                error("missing resources in output ?");
+            }
+        } else {
+            error("failed to execute javadoc");
+        }
+    }
+
     /**
      * Find keys in resource bundles which are probably no longer required.
      * A key is required if there is a string in the code that is a resource key,
      * or if the key is well-known according to various pragmatic rules.
      */
     void findDeadKeys(Set<String> codeKeys, Set<String> resourceKeys) {
         for (String rk: resourceKeys) {
+            // ignore these synthesized keys, tested by usageTests
+            if (rk.startsWith("doclet.usage.") || rk.startsWith("doclet.xusage"))
+                continue;
             if (codeKeys.contains(rk))
                 continue;
 
             error("Resource key not found in code: " + rk);
         }

@@ -127,10 +153,13 @@
      * For all strings in the code that look like they might be
      * a resource key, verify that a key exists.
      */
     void findMissingKeys(Set<String> codeKeys, Set<String> resourceKeys) {
         for (String ck: codeKeys) {
+            // ignore these synthesized keys, tested by usageTests
+            if (ck.startsWith("doclet.usage.") || ck.startsWith("doclet.xusage."))
+                continue;
             if (resourceKeys.contains(ck))
                 continue;
             error("No resource for \"" + ck + "\"");
         }
     }

@@ -142,12 +171,12 @@
         Set<String> results = new TreeSet<String>();
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
         try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
             JavaFileManager.Location javadocLoc = findJavadocLocation(fm);
             String[] pkgs = {
-                "com.sun.tools.doclets",
-                "com.sun.tools.javadoc"
+                "jdk.javadoc.internal.doclets",
+                "jdk.javadoc.internal.tool"
             };
             for (String pkg: pkgs) {
                 for (JavaFileObject fo: fm.list(javadocLoc,
                         pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
                     String name = fo.getName();

@@ -184,11 +213,11 @@
         JavaFileManager.Location[] locns =
             { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
         try {
             for (JavaFileManager.Location l: locns) {
                 JavaFileObject fo = fm.getJavaFileForInput(l,
-                    "com.sun.tools.javadoc.Main", JavaFileObject.Kind.CLASS);
+                    "jdk.javadoc.internal.tool.Main", JavaFileObject.Kind.CLASS);
                 if (fo != null) {
                     System.err.println("found javadoc in " + l);
                     return l;
                 }
             }

@@ -223,13 +252,13 @@
     /**
      * Get the set of keys from the javadoc resource bundles.
      */
     Set<String> getResourceKeys() {
         String[] names = {
-                "com.sun.tools.doclets.formats.html.resources.standard",
-                "com.sun.tools.doclets.internal.toolkit.resources.doclets",
-                "com.sun.tools.javadoc.resources.javadoc",
+                "jdk.javadoc.internal.doclets.formats.html.resources.standard",
+                "jdk.javadoc.internal.doclets.toolkit.resources.doclets",
+                "jdk.javadoc.internal.tool.resources.javadoc",
         };
         Set<String> results = new TreeSet<String>();
         for (String name : names) {
             ResourceBundle b = ResourceBundle.getBundle(name);
             results.addAll(b.keySet());