8199892: Missing landmarks when generating docs using html sources

Reviewed-by: jjg
This commit is contained in:
Priya Lakshmi Muthuswamy 2019-01-14 15:09:15 +05:30
parent 955d587990
commit f00057cb16
2 changed files with 57 additions and 15 deletions

View File

@ -25,16 +25,13 @@
package jdk.javadoc.internal.doclets.formats.html;
import com.sun.source.doctree.AttributeTree;
import com.sun.source.doctree.AttributeTree.ValueKind;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.StartElementTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.util.DocTreeFactory;
import com.sun.source.util.SimpleDocTreeVisitor;
import com.sun.tools.doclint.HtmlTag;
import com.sun.tools.doclint.HtmlTag.Attr;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation;
import jdk.javadoc.internal.doclets.toolkit.Content;
@ -184,16 +181,28 @@ public class DocFilesHandlerImpl implements DocFilesHandler {
Content pkgLinkContent = docletWriter.getPackageLink(pkg, docletWriter.contents.packageLabel);
navBar.setNavLinkPackage(pkgLinkContent);
navBar.setUserHeader(docletWriter.getUserHeaderFooter(true));
htmlContent.addContent(navBar.getContent(true));
Content header = docletWriter.createTagIfAllowed(
jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag.HEADER, HtmlTree::HEADER,
ContentBuilder::new);
header.addContent(navBar.getContent(true));
htmlContent.addContent(header);
List<? extends DocTree> fullBody = utils.getFullBody(dfElement);
Content bodyContent = docletWriter.commentTagsToContent(null, dfElement, fullBody, false);
docletWriter.addTagsInfo(dfElement, bodyContent);
htmlContent.addContent(bodyContent);
Content main = docletWriter.createTagIfAllowed(
jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag.MAIN, HtmlTree::MAIN,
ContentBuilder::new);
main.addContent(bodyContent);
htmlContent.addContent(main);
navBar.setUserFooter(docletWriter.getUserHeaderFooter(false));
htmlContent.addContent(navBar.getContent(false));
docletWriter.addBottom(htmlContent);
Content footer = docletWriter.createTagIfAllowed(
jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag.FOOTER, HtmlTree::FOOTER,
ContentBuilder::new);
footer.addContent(navBar.getContent(false));
docletWriter.addBottom(footer);
htmlContent.addContent(footer);
docletWriter.printHtmlDocument(Collections.emptyList(), false, localTagsContent, htmlContent);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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 8210047
* @bug 8210047 8199892
* @summary some pages contains content outside of landmark region
* @library /tools/lib ../../lib
* @modules
@ -31,12 +31,14 @@
* jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build javadoc.tester.*
* @run main TestHtmlLankmarkRegions
* @run main TestHtmlLandmarkRegions
*/
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import builder.ClassBuilder;
import toolbox.ModuleBuilder;
@ -44,16 +46,16 @@ import toolbox.ToolBox;
import javadoc.tester.JavadocTester;
public class TestHtmlLankmarkRegions extends JavadocTester {
public class TestHtmlLandmarkRegions extends JavadocTester {
final ToolBox tb;
public static void main(String... args) throws Exception {
TestHtmlLankmarkRegions tester = new TestHtmlLankmarkRegions();
TestHtmlLandmarkRegions tester = new TestHtmlLandmarkRegions();
tester.runTests(m -> new Object[]{Paths.get(m.getName())});
}
TestHtmlLankmarkRegions() {
TestHtmlLandmarkRegions() {
tb = new ToolBox();
}
@ -201,6 +203,37 @@ public class TestHtmlLankmarkRegions extends JavadocTester {
);
}
@Test
public void testDocFiles(Path base) throws Exception {
Path srcDir = base.resolve("src");
createPackages(srcDir);
Path docFiles = Files.createDirectory(srcDir.resolve("pkg1").resolve("doc-files"));
Files.write(docFiles.resolve("s.html"), List.of(
"<html>\n"
+ " <head>\n"
+ " <title>\"Hello World\"</title>\n"
+ " </head>\n"
+ " <body>\n"
+ " A sample doc file.\n"
+ " </body>\n"
+ "</html>"));
Path outDir = base.resolve("out5");
javadoc("-d", outDir.toString(),
"-sourcepath", srcDir.toString(),
"pkg1", "pkg2");
checkExit(Exit.OK);
checkOrder("pkg1/doc-files/s.html",
"<header role=\"banner\">\n"
+ "<nav role=\"navigation\">\n",
"<main role=\"main\">A sample doc file",
"<footer role=\"contentinfo\">\n"
+ "<nav role=\"navigation\">"
);
}
void createModules(Path srcDir) throws Exception {
new ModuleBuilder(tb, "m1")
.classes("package p1; public class a{}")