8166175: javadoc search doesn't work on local doc bundles
authorbpatel
Thu, 26 Jan 2017 13:01:12 -0800
changeset 43370 5969237f927c
parent 43369 aafd33c96bac
child 43371 ff36ce949e5b
8166175: javadoc search doesn't work on local doc bundles Reviewed-by: jjg, ksrini
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java
langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Thu Jan 26 14:14:01 2017 +0100
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Thu Jan 26 13:01:12 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -437,23 +437,23 @@
     protected void createSearchIndexFiles() throws DocFileIOException {
         if (configuration.showModules) {
             createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JSON, DocPaths.MODULE_SEARCH_INDEX_ZIP,
-                    configuration.moduleSearchIndex);
+                    DocPaths.MODULE_SEARCH_INDEX_JS, configuration.moduleSearchIndex, "moduleSearchIndex");
         }
         createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
-                configuration.packageSearchIndex);
+                DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");
         createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JSON, DocPaths.TYPE_SEARCH_INDEX_ZIP,
-                configuration.typeSearchIndex);
+                DocPaths.TYPE_SEARCH_INDEX_JS, configuration.typeSearchIndex, "typeSearchIndex");
         createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JSON, DocPaths.MEMBER_SEARCH_INDEX_ZIP,
-                configuration.memberSearchIndex);
+                DocPaths.MEMBER_SEARCH_INDEX_JS, configuration.memberSearchIndex, "memberSearchIndex");
         createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JSON, DocPaths.TAG_SEARCH_INDEX_ZIP,
-                configuration.tagSearchIndex);
+                DocPaths.TAG_SEARCH_INDEX_JS, configuration.tagSearchIndex, "tagSearchIndex");
     }
 
     /**
      * @throws DocFileIOException if there is a problem creating the search index file
      */
     protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
-            List<SearchIndexItem> searchIndex) throws DocFileIOException {
+            DocPath searchIndexJS, List<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
         if (!searchIndex.isEmpty()) {
             StringBuilder searchVar = new StringBuilder("[");
             boolean first = true;
@@ -466,6 +466,14 @@
                 }
             }
             searchVar.append("]");
+            DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
+            try (Writer wr = jsFile.openWriter()) {
+                wr.write(varName);
+                wr.write(" = ");
+                wr.write(searchVar.toString());
+            } catch (IOException ie) {
+                throw new DocFileIOException(jsFile, DocFileIOException.Mode.WRITE, ie);
+            }
 
             DocFile zipFile = DocFile.createFileForOutput(configuration, searchIndexZip);
             try (OutputStream fos = zipFile.openOutputStream();
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js	Thu Jan 26 14:14:01 2017 +0100
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js	Thu Jan 26 13:01:12 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,6 +77,21 @@
                     tagSearchIndex = JSON.parse(zip.file("tag-search-index.json").asText());
                 });
             });
+    if (!moduleSearchIndex) {
+        createElem(doc, tag, 'module-search-index.js');
+    }
+    if (!packageSearchIndex) {
+        createElem(doc, tag, 'package-search-index.js');
+    }
+    if (!typeSearchIndex) {
+        createElem(doc, tag, 'type-search-index.js');
+    }
+    if (!memberSearchIndex) {
+        createElem(doc, tag, 'member-search-index.js');
+    }
+    if (!tagSearchIndex) {
+        createElem(doc, tag, 'tag-search-index.js');
+    }
 }
 
 function createElem(doc, tag, path) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Jan 26 14:14:01 2017 +0100
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Jan 26 13:01:12 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -121,12 +121,18 @@
     /** The name of the member search index zip file. */
     public static final DocPath MEMBER_SEARCH_INDEX_ZIP = DocPath.create("member-search-index.zip");
 
+    /** The name of the member search index js file. */
+    public static final DocPath MEMBER_SEARCH_INDEX_JS = DocPath.create("member-search-index.js");
+
     /** The name of the module search index file. */
     public static final DocPath MODULE_SEARCH_INDEX_JSON = DocPath.create("module-search-index.json");
 
-    /** The name of the module search index zipfile. */
+    /** The name of the module search index zip file. */
     public static final DocPath MODULE_SEARCH_INDEX_ZIP = DocPath.create("module-search-index.zip");
 
+    /** The name of the module search index js file. */
+    public static final DocPath MODULE_SEARCH_INDEX_JS = DocPath.create("module-search-index.js");
+
     /** The name of the file for the overview frame. */
     public static final DocPath OVERVIEW_FRAME = DocPath.create("overview-frame.html");
 
@@ -149,9 +155,12 @@
     /** The name of the package search index file. */
     public static final DocPath PACKAGE_SEARCH_INDEX_JSON = DocPath.create("package-search-index.json");
 
-    /** The name of the package search index zipfile. */
+    /** The name of the package search index zip file. */
     public static final DocPath PACKAGE_SEARCH_INDEX_ZIP = DocPath.create("package-search-index.zip");
 
+    /** The name of the package search index js file. */
+    public static final DocPath PACKAGE_SEARCH_INDEX_JS = DocPath.create("package-search-index.js");
+
     /** The name of the file for the package summary. */
     public static final DocPath PACKAGE_SUMMARY = DocPath.create("package-summary.html");
 
@@ -202,12 +211,18 @@
     /** The name of the tag search index zip file. */
     public static final DocPath TAG_SEARCH_INDEX_ZIP = DocPath.create("tag-search-index.zip");
 
+    /** The name of the tag search index js file. */
+    public static final DocPath TAG_SEARCH_INDEX_JS = DocPath.create("tag-search-index.js");
+
     /** The name of the type search index file. */
     public static final DocPath TYPE_SEARCH_INDEX_JSON = DocPath.create("type-search-index.json");
 
     /** The name of the type search index zip file. */
     public static final DocPath TYPE_SEARCH_INDEX_ZIP = DocPath.create("type-search-index.zip");
 
+    /** The name of the type search index js file. */
+    public static final DocPath TYPE_SEARCH_INDEX_JS = DocPath.create("type-search-index.js");
+
     /** The name of the image file for undo button on the search box. */
     public static final DocPath X_IMG = DocPath.create("x.png");
 
--- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Thu Jan 26 14:14:01 2017 +0100
+++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Thu Jan 26 13:01:12 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8141492 8071982 8141636 8147890
+ * @bug 8141492 8071982 8141636 8147890 8166175
  * @summary Test the search feature of javadoc.
  * @author bpatel
  * @library ../lib
@@ -47,10 +47,14 @@
         checkSearchJS();
         checkFiles(false,
                 "package-search-index.zip",
-                "tag-search-index.zip");
+                "tag-search-index.zip",
+                "package-search-index.js",
+                "tag-search-index.js");
         checkFiles(true,
                 "member-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -67,7 +71,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -84,7 +92,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -100,6 +112,10 @@
                 "package-search-index.zip",
                 "tag-search-index.zip",
                 "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js",
                 "index-all.html");
     }
 
@@ -117,7 +133,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -133,6 +153,10 @@
                 "package-search-index.zip",
                 "tag-search-index.zip",
                 "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js",
                 "index-all.html");
     }
 
@@ -150,7 +174,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -167,7 +195,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -184,7 +216,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -197,11 +233,15 @@
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(false,
-                "tag-search-index.zip");
+                "tag-search-index.zip",
+                "tag-search-index.js");
         checkFiles(true,
                 "member-search-index.zip",
                 "package-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "type-search-index.js");
     }
 
     void checkDocLintErrors() {