8201396: fix broken links generated by javadoc doclet
authorjjg
Tue, 10 Apr 2018 15:05:10 -0700
changeset 49569 d4d2f634b72f
parent 49568 3e9cb3562d83
child 49570 25515c7e96b0
8201396: fix broken links generated by javadoc doclet Reviewed-by: ksrini
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleFrameWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexFrameWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModulePackageIndexFrameWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java
test/langtools/jdk/javadoc/doclet/testModuleDirs/TestModuleDirs.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleFrameWriter.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleFrameWriter.java	Tue Apr 10 15:05:10 2018 -0700
@@ -40,6 +40,7 @@
 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
 import jdk.javadoc.internal.doclets.toolkit.Content;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
+import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
 
 /**
@@ -100,8 +101,11 @@
         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
                 ? HtmlTree.MAIN()
                 : body;
+        DocPath moduleSummary = configuration.useModuleDirectories
+                ? DocPaths.DOT_DOT.resolve(configuration.docPaths.moduleSummary(moduleElement))
+                : configuration.docPaths.moduleSummary(moduleElement);
         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
-                mdlgen.links.createLink(configuration.docPaths.moduleSummary(moduleElement), mdlLabel, "", "classFrame"));
+                mdlgen.links.createLink(moduleSummary, mdlLabel, "", "classFrame"));
         htmlTree.addContent(heading);
         HtmlTree div = new HtmlTree(HtmlTag.DIV);
         div.setStyle(HtmlStyle.indexContainer);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexFrameWriter.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexFrameWriter.java	Tue Apr 10 15:05:10 2018 -0700
@@ -36,7 +36,6 @@
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
-import jdk.javadoc.internal.doclets.formats.html.markup.Links;
 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
 import jdk.javadoc.internal.doclets.toolkit.Content;
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModulePackageIndexFrameWriter.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModulePackageIndexFrameWriter.java	Tue Apr 10 15:05:10 2018 -0700
@@ -37,7 +37,6 @@
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
-import jdk.javadoc.internal.doclets.formats.html.markup.Links;
 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
 import jdk.javadoc.internal.doclets.toolkit.Content;
@@ -189,7 +188,10 @@
      * @param ul the Content object to which the all classes link should be added
      */
     protected void addAllClassesLink(Content ul) {
-        Content linkContent = links.createLink(DocPaths.ALLCLASSES_FRAME,
+        DocPath allClassesFrame = configuration.useModuleDirectories
+                ? DocPaths.DOT_DOT.resolve(DocPaths.ALLCLASSES_FRAME)
+                : DocPaths.ALLCLASSES_FRAME;
+        Content linkContent = links.createLink(allClassesFrame,
                 contents.allClassesLabel, "", "packageFrame");
         Content li = HtmlTree.LI(linkContent);
         ul.addContent(li);
@@ -202,7 +204,10 @@
      * @param ul the Content object to which the all packages link should be added
      */
     protected void addAllPackagesLink(Content ul) {
-        Content linkContent = links.createLink(DocPaths.OVERVIEW_FRAME,
+        DocPath overviewFrame = configuration.useModuleDirectories
+                ? DocPaths.DOT_DOT.resolve(DocPaths.OVERVIEW_FRAME)
+                : DocPaths.OVERVIEW_FRAME;
+        Content linkContent = links.createLink(overviewFrame,
                 contents.allPackagesLabel, "", "packageListFrame");
         Content li = HtmlTree.LI(linkContent);
         ul.addContent(li);
@@ -215,7 +220,10 @@
      * @param ul the Content object to which the all modules link should be added
      */
     protected void addAllModulesLink(Content ul) {
-        Content linkContent = links.createLink(DocPaths.MODULE_OVERVIEW_FRAME,
+        DocPath moduleOverviewFrame = configuration.useModuleDirectories
+                ? DocPaths.DOT_DOT.resolve(DocPaths.MODULE_OVERVIEW_FRAME)
+                : DocPaths.MODULE_OVERVIEW_FRAME;
+        Content linkContent = links.createLink(moduleOverviewFrame,
                 contents.allModulesLabel, "", "packageListFrame");
         Content li = HtmlTree.LI(linkContent);
         ul.addContent(li);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java	Tue Apr 10 15:05:10 2018 -0700
@@ -30,10 +30,6 @@
 import java.util.Collections;
 import java.util.List;
 
-import javax.lang.model.element.ModuleElement;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-
 /**
  * Abstraction for immutable relative paths.
  * Paths always use '/' as a separator, and never begin or end with '/'.
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Tue Apr 10 15:05:10 2018 -0700
@@ -49,6 +49,8 @@
         moduleSeparator = useModuleDirectories ? "/module-" : "-";
     }
 
+    public static final DocPath DOT_DOT = DocPath.create("..");
+
     /** The name of the file for all classes, without using frames, when --no-frames is specified. */
     public static final DocPath ALLCLASSES = DocPath.create("allclasses.html");
 
--- a/test/langtools/jdk/javadoc/doclet/testModuleDirs/TestModuleDirs.java	Tue Apr 10 23:32:54 2018 +0200
+++ b/test/langtools/jdk/javadoc/doclet/testModuleDirs/TestModuleDirs.java	Tue Apr 10 15:05:10 2018 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8195795
+ * @bug 8195795 8201396
  * @summary test the use of module directories in output,
  *          and the --no-module-directories option
  * @modules jdk.javadoc/jdk.javadoc.internal.api
@@ -71,46 +71,85 @@
     @Test
     public void testNoModuleDirs(Path base) throws IOException {
         Path src = base.resolve("src");
-        new ModuleBuilder(tb, "m")
-                .classes("package p; public class A {}")
-                .exports("p")
+        new ModuleBuilder(tb, "ma")
+                .classes("package pa; public class A {}")
+                .exports("pa")
+                .write(src);
+        new ModuleBuilder(tb, "mb")
+                .classes("package pb; public class B {}")
+                .exports("pb")
                 .write(src);
 
         javadoc("-d", base.resolve("api").toString(),
                 "-quiet",
                 "--module-source-path", src.toString(),
                 "--no-module-directories",
-                "--module", "m");
+                "--module", "ma,mb");
 
         checkExit(Exit.OK);
         checkFiles(true,
-                "m-summary.html",
-                "p/package-summary.html");
+                "ma-frame.html",
+                "ma-summary.html",
+                "pa/package-summary.html");
         checkFiles(false,
-                "m/module-summary.html",
-                "m/p/package-summary.html");
+                "ma/module-frame.html",
+                "ma/module-summary.html",
+                "ma/pa/package-summary.html");
+        checkOutput("ma-frame.html", true,
+                "<ul>\n"
+                + "<li><a href=\"allclasses-frame.html\" target=\"packageFrame\">All&nbsp;Classes</a></li>\n"
+                + "<li><a href=\"overview-frame.html\" target=\"packageListFrame\">All&nbsp;Packages</a></li>\n"
+                + "<li><a href=\"module-overview-frame.html\" target=\"packageListFrame\">All&nbsp;Modules</a></li>\n"
+                + "</ul>\n");
+        checkOutput("ma-summary.html", true,
+                "<ul class=\"navList\" id=\"allclasses_navbar_top\">\n"
+                + "<li><a href=\"allclasses-noframe.html\">All&nbsp;Classes</a></li>\n"
+                + "</ul>\n");
+        checkOutput("pa/package-summary.html", true,
+                "<li><a href=\"../deprecated-list.html\">Deprecated</a></li>\n"
+                + "<li><a href=\"../index-all.html\">Index</a></li>");
+
     }
 
     @Test
     public void testModuleDirs(Path base) throws IOException {
         Path src = base.resolve("src");
-        new ModuleBuilder(tb, "m")
-                .classes("package p; public class A {}")
-                .exports("p")
+        new ModuleBuilder(tb, "ma")
+                .classes("package pa; public class A {}")
+                .exports("pa")
+                .write(src);
+        new ModuleBuilder(tb, "mb")
+                .classes("package pb; public class B {}")
+                .exports("pb")
                 .write(src);
 
         javadoc("-d", base.resolve("api").toString(),
                 "-quiet",
                 "--module-source-path", src.toString(),
-                "--module", "m");
+                "--module", "ma,mb");
 
         checkExit(Exit.OK);
         checkFiles(false,
-                "m-summary.html",
-                "p/package-summary.html");
+                "ma-frame.html",
+                "ma-summary.html",
+                "pa/package-summary.html");
         checkFiles(true,
-                "m/module-summary.html",
-                "m/p/package-summary.html");
+                "ma/module-frame.html",
+                "ma/module-summary.html",
+                "ma/pa/package-summary.html");
+        checkOutput("ma/module-frame.html", true,
+                "<ul>\n"
+                + "<li><a href=\"../allclasses-frame.html\" target=\"packageFrame\">All&nbsp;Classes</a></li>\n"
+                + "<li><a href=\"../overview-frame.html\" target=\"packageListFrame\">All&nbsp;Packages</a></li>\n"
+                + "<li><a href=\"../module-overview-frame.html\" target=\"packageListFrame\">All&nbsp;Modules</a></li>\n"
+                + "</ul>\n");
+        checkOutput("ma/module-summary.html", true,
+                "<ul class=\"navList\" id=\"allclasses_navbar_top\">\n"
+                + "<li><a href=\"../allclasses-noframe.html\">All&nbsp;Classes</a></li>\n"
+                + "</ul>\n");
+        checkOutput("ma/pa/package-summary.html", true,
+                "<li><a href=\"../../deprecated-list.html\">Deprecated</a></li>\n"
+                + "<li><a href=\"../../index-all.html\">Index</a></li>");
     }
 }