8185985: Html files in doc-files directories should be wrapped with standard header and footer
authorksrini
Thu, 30 Nov 2017 06:14:25 -0800
changeset 48029 e9dab2492924
parent 48028 9e022f580a9d
child 48030 b8a119027122
8185985: Html files in doc-files directories should be wrapped with standard header and footer Reviewed-by: jjg
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocletElement.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/OverviewElement.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeBuilder.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocFile.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
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/StandardDocFileFactory.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
test/langtools/jdk/javadoc/doclet/testCopyFiles/TestCopyFiles.java
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/inpackage.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/sub-dir/SubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/sub-dir/sub-dir-1/SubSubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/package.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/module-info.java
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/Foo.java
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/inpackage.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/sub-dir/SubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/sub-dir/sub-dir-1/SubSubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/package.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/overview.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/packages/p1/doc-files/sub-dir/SubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/unnamed/doc-files/doc-file/SubReadme.html
test/langtools/jdk/javadoc/doclet/testCopyFiles/unnamed/doc-files/inpackage.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.javadoc.internal.doclets.formats.html;
+
+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 jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
+import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.DocFileElement;
+import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
+import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
+import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
+import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
+import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
+import jdk.javadoc.internal.doclets.toolkit.util.Utils;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.PackageElement;
+import javax.tools.FileObject;
+import javax.tools.JavaFileManager.Location;
+import java.util.Collections;
+import java.util.List;
+
+public class DocFilesHandlerImpl implements DocFilesHandler {
+
+    public final Element element;
+    public final Location location;
+    public final DocPath  source;
+    public final HtmlConfiguration configuration;
+
+    /**
+     * Constructor to construct the DocFilesWriter object.
+     *
+     * @param configuration the configuration of this doclet.
+     * @param element the containing element of the doc-files.
+     *
+     */
+    public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
+        this.configuration = configuration;
+        this.element = element;
+
+        switch (element.getKind()) {
+            case MODULE:
+                location = configuration.utils.getLocationForModule((ModuleElement)element);
+                source = DocPaths.DOC_FILES;
+                break;
+            case PACKAGE:
+                location = configuration.utils.getLocationForPackage((PackageElement)element);
+                source = DocPath.forPackage((PackageElement)element).resolve(DocPaths.DOC_FILES);
+                break;
+            default:
+                throw new AssertionError("unsupported element " + element);
+        }
+    }
+
+    /**
+     * Copy doc-files directory and its contents from the source
+     * elements directory to the generated documentation directory.
+     *
+     * @throws DocFileIOException if there is a problem while copying
+     *         the documentation files
+     */
+
+    public void copyDocFiles()  throws DocFileIOException {
+        boolean first = true;
+        for (DocFile srcdir : DocFile.list(configuration, location, source)) {
+            if (!srcdir.isDirectory()) {
+                continue;
+            }
+            DocPath path = null;
+            switch (this.element.getKind()) {
+                case MODULE:
+                    path = DocPath.forModule((ModuleElement)this.element);
+                    break;
+                case PACKAGE:
+                    path = DocPath.forPackage((PackageElement)this.element);
+                    break;
+                default:
+                    throw new AssertionError("unknown kind:" + this.element.getKind());
+            }
+            copyDirectory(srcdir, path.resolve(DocPaths.DOC_FILES), first);
+            first = false;
+        }
+    }
+
+
+    private void copyDirectory(DocFile srcdir, final DocPath dstDocPath,
+                               boolean first) throws DocFileIOException {
+        DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
+        if (srcdir.isSameFile(dstdir)) {
+            return;
+        }
+        for (DocFile srcfile: srcdir.list()) {
+            DocFile destfile = dstdir.resolve(srcfile.getName());
+            if (srcfile.isFile()) {
+                if (destfile.exists() && !first) {
+                    configuration.messages.warning("doclet.Copy_Overwrite_warning",
+                            srcfile.getPath(), dstdir.getPath());
+                } else {
+                    configuration.messages.notice("doclet.Copying_File_0_To_Dir_1",
+                            srcfile.getPath(), dstdir.getPath());
+                    if (Utils.toLowerCase(srcfile.getPath()).endsWith(".html")) {
+                        handleHtmlFile(srcfile, dstDocPath);
+                    } else {
+                        destfile.copyFile(srcfile);
+                    }
+                }
+            } else if (srcfile.isDirectory()) {
+                if (configuration.copydocfilesubdirs
+                        && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
+                    DocPath dirDocPath = dstDocPath.resolve(srcfile.getName());
+                    copyDirectory(srcfile, dirDocPath, first);
+                }
+            }
+        }
+    }
+
+    private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOException {
+        DocPath dfilePath = dstPath.resolve(srcfile.getName());
+        HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element);
+
+        Utils utils = configuration.utils;
+
+        FileObject fileObject = srcfile.getFileObject();
+        DocFileElement dfElement = new DocFileElement(element, fileObject);
+        String title = getWindowTitle(docletWriter, dfElement).trim();
+        HtmlTree htmlContent = docletWriter.getBody(true, title);
+        docletWriter.addTop(htmlContent);
+        docletWriter.addNavLinks(true, htmlContent);
+
+        List<? extends DocTree> fullBody = utils.getFullBody(dfElement);
+        Content bodyContent = docletWriter.commentTagsToContent(null, dfElement, fullBody, false);
+
+        docletWriter.addTagsInfo(dfElement, bodyContent);
+        htmlContent.addContent(bodyContent);
+
+        docletWriter.addNavLinks(false, htmlContent);
+        docletWriter.addBottom(htmlContent);
+        docletWriter.printHtmlDocument(Collections.emptyList(), false, htmlContent);
+    }
+
+    private String getWindowTitle(HtmlDocletWriter docletWriter, Element element) {
+        List<? extends DocTree> preamble = configuration.utils.getPreamble(element);
+        StringBuilder sb = new StringBuilder();
+        boolean titleFound = false;
+        loop:
+        for (DocTree dt : preamble) {
+            switch (dt.getKind()) {
+                case START_ELEMENT:
+                    StartElementTree nodeStart = (StartElementTree)dt;
+                    if (Utils.toLowerCase(nodeStart.getName().toString()).equals("title")) {
+                        titleFound = true;
+                    }
+                    break;
+
+                case END_ELEMENT:
+                    EndElementTree nodeEnd = (EndElementTree)dt;
+                    if (Utils.toLowerCase(nodeEnd.getName().toString()).equals("title")) {
+                        break loop;
+                    }
+                    break;
+
+                case TEXT:
+                    TextTree nodeText = (TextTree)dt;
+                    if (titleFound)
+                        sb.append(nodeText.getBody());
+                    break;
+
+                default:
+                    // do nothing
+            }
+        }
+        return docletWriter.getWindowTitle(sb.toString().trim());
+    }
+
+    private static class DocFileWriter extends HtmlDocletWriter {
+
+        final PackageElement pkg;
+
+        /**
+         * Constructor to construct the HtmlDocletWriter object.
+         *
+         * @param configuration the configuruation of this doclet.
+         * @param path          the file to be generated.
+         * @param e             the anchoring element.
+         */
+        public DocFileWriter(HtmlConfiguration configuration, DocPath path, Element e) {
+            super(configuration, path);
+            switch (e.getKind()) {
+                case PACKAGE:
+                    pkg = (PackageElement)e;
+                    break;
+                default:
+                    throw new AssertionError("unsupported element: " + e.getKind());
+            }
+        }
+
+        /**
+         * Get the module link.
+         *
+         * @return a content tree for the module link
+         */
+        @Override
+        protected Content getNavLinkModule() {
+            Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(pkg),
+                    contents.moduleLabel);
+            Content li = HtmlTree.LI(linkContent);
+            return li;
+        }
+
+        /**
+         * Get this package link.
+         *
+         * @return a content tree for the package link
+         */
+        @Override
+        protected Content getNavLinkPackage() {
+            Content linkContent = getPackageLink(pkg,
+                    contents.packageLabel);
+            Content li = HtmlTree.LI(linkContent);
+            return li;
+        }
+    }
+}
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Thu Nov 30 06:14:25 2017 -0800
@@ -2268,13 +2268,14 @@
      * @param annotationDoc the annotation being documented
      * @param linkInfo the information about the link
      * @param annotation the annotation string to which the annotation will be added
-     * @param pairs annotation type element and value pairs
+     * @param map annotation type element to annotation value pairs
      * @param indent the number of extra spaces to indent the annotations.
      * @param linkBreak if true, add new line between each member value
      */
     private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo,
-        ContentBuilder annotation, Map<? extends ExecutableElement,? extends AnnotationValue>map,
-        int indent, boolean linkBreak) {
+                                ContentBuilder annotation,
+                                Map<? extends ExecutableElement, ? extends AnnotationValue> map,
+                                int indent, boolean linkBreak) {
         linkInfo.label = new StringContent("@");
         linkInfo.label.addContent(annotationDoc.getSimpleName());
         annotation.addContent(getLink(linkInfo));
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java	Thu Nov 30 06:14:25 2017 -0800
@@ -26,6 +26,7 @@
 package jdk.javadoc.internal.doclets.formats.html;
 
 
+import javax.lang.model.element.Element;
 import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
@@ -37,6 +38,7 @@
 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
 import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
 import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
+import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
 import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter;
 import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter;
@@ -235,4 +237,12 @@
     public SerializedFormWriter getSerializedFormWriter() {
         return new SerializedFormWriterImpl(configuration);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public DocFilesHandler getDocFilesHandler(Element element) {
+        return new DocFilesHandlerImpl(configuration, element);
+    }
 }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java	Thu Nov 30 06:14:25 2017 -0800
@@ -375,7 +375,6 @@
         }
         initialized = true;
         this.docEnv = docEnv;
-        overviewElement = new OverviewElement(docEnv);
         Splitter specifiedSplitter = new Splitter(docEnv, false);
         specifiedModuleElements = Collections.unmodifiableSet(specifiedSplitter.mset);
         specifiedPackageElements = Collections.unmodifiableSet(specifiedSplitter.pset);
@@ -715,6 +714,7 @@
      * initializes certain components before anything else is started.
      */
     protected boolean finishOptionSettings0() throws DocletException {
+
         initDestDirectory();
         for (String link : linkList) {
             extern.link(link, reporter);
@@ -731,6 +731,7 @@
                 group.checkPackageGroups(grp.first, grp.second);
             }
         });
+        overviewElement = new OverviewElement(workArounds.getUnnamedPackage(), getOverviewPath());
         return true;
     }
 
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java	Thu Nov 30 06:14:25 2017 -0800
@@ -177,8 +177,11 @@
         PackageElement pe = null;
         switch (e.getKind()) {
             case OTHER:
-                fo = configuration.getOverviewPath();
-                pe = configuration.workArounds.getUnnamedPackage();
+                if (e instanceof DocletElement) {
+                    DocletElement de = (DocletElement)e;
+                    fo = de.getFileObject();
+                    pe = de.getPackageElement();
+                }
                 break;
             case PACKAGE:
                 fo = configuration.workArounds.getJavaFileObject((PackageElement)e);
@@ -209,13 +212,12 @@
         });
     }
 
-    public void setDocCommentTree(Element element, List<DocTree> fullBody,
-            List<DocTree> blockTags, Utils utils) {
+    public void setDocCommentTree(Element element, List<? extends DocTree> fullBody,
+                                  List<? extends DocTree> blockTags, Utils utils) {
         DocCommentTree docTree = treeFactory.newDocCommentTree(fullBody, blockTags);
         dcTreesMap.put(element, new DocCommentDuo(null, docTree));
-        // There maybe an entry with the original comments usually null,
-        // therefore remove that entry if it exists, and allow a new one
-        // to be reestablished.
+        // A method having null comment (no comment) that might need to be replaced
+        // with a synthetic comment, remove such a comment from the cache.
         utils.removeCommentHelper(element);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,85 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.javadoc.internal.doclets.toolkit;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ElementVisitor;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.type.TypeMirror;
+import javax.tools.FileObject;
+
+import jdk.javadoc.doclet.DocletEnvironment;
+
+/**
+ * This is a pseudo element wrapper for doc-files html contents, essentially to
+ * associate the doc-file's html documentation's DocCommentTree to an element.
+ *
+ *  <p><b>This is NOT part of any supported API.
+ *  If you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+public class DocFileElement implements DocletElement {
+
+    private final Element element;
+    private final FileObject fo;
+
+    public DocFileElement(Element element, FileObject fo) {
+        this.element = element;
+        this.fo = fo;
+    }
+
+    @Override
+    public PackageElement getPackageElement() {
+        switch(element.getKind()) {
+            case MODULE:
+                // uncomment to support doc-files in modules
+                // return configuration.workArounds.getUnnamedPackage();
+                throw new UnsupportedOperationException("not implemented");
+            case PACKAGE:
+                return (PackageElement)element;
+            default:
+                throw new AssertionError("unknown kind: " + element.getKind());
+        }
+    }
+
+    @Override
+    public FileObject getFileObject() {
+        return fo;
+    }
+
+    @Override
+    public Kind getSubKind() {
+        return Kind.DOCFILE;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package jdk.javadoc.internal.doclets.toolkit;
+
+/**
+ * The interface for copying doc-files to the output.
+ *
+ *  <p><b>This is NOT part of any supported API.
+ *  If you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+
+public interface DocFilesHandler {
+    void copyDocFiles() throws DocletException;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocletElement.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.javadoc.internal.doclets.toolkit;
+
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ElementVisitor;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.type.TypeMirror;
+import javax.tools.FileObject;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+public interface DocletElement extends Element {
+
+    public default TypeMirror asType() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default ElementKind getKind() {
+        return ElementKind.OTHER;
+    }
+
+    default Set<Modifier> getModifiers() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default Name getSimpleName() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default Element getEnclosingElement() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default java.util.List<? extends Element> getEnclosedElements() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default java.util.List<? extends AnnotationMirror> getAnnotationMirrors() {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default <A extends Annotation> A getAnnotation(Class<A> annotationType) {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    default <R, P> R accept(ElementVisitor<R, P> v, P p) {
+        return v.visitUnknown(this, p);
+    }
+
+    default <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
+        throw new UnsupportedOperationException("Unsupported method");
+    }
+
+    /**
+     * Returns the anchoring package element, in the case of a
+     * module element, this is the module's unnamed package.
+     * @return the anchor element.
+     */
+    PackageElement getPackageElement();
+
+    /**
+     * Returns the file object associated with this special
+     * element such as overview.html, doc-file/foo.html.
+     * @return the file object
+     */
+    FileObject getFileObject();
+
+    /**
+     * Returns the subkind of this element.
+     * @return a subkind
+     */
+    Kind getSubKind();
+
+    /**
+     * Sub kind enums that this element supports.
+     */
+    public static enum Kind {
+        OVERVIEW, DOCFILE;
+    }
+}
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/OverviewElement.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/OverviewElement.java	Thu Nov 30 06:14:25 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
@@ -25,17 +25,9 @@
 
 package jdk.javadoc.internal.doclets.toolkit;
 
-import java.lang.annotation.Annotation;
-import java.util.Set;
-
-import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.ElementVisitor;
-import javax.lang.model.element.Name;
-import javax.lang.model.type.TypeMirror;
-
-import jdk.javadoc.doclet.DocletEnvironment;
+import javax.lang.model.element.PackageElement;
+import javax.tools.FileObject;
 
 /**
  * This is a pseudo element wrapper for the overview element, essentially to
@@ -46,62 +38,28 @@
  *  This code and its internal interfaces are subject to change or
  *  deletion without notice.</b>
  */
-public class OverviewElement implements Element {
-
-    public final DocletEnvironment docEnv;
-
-    OverviewElement(DocletEnvironment docEnv) {
-        this.docEnv = docEnv;
-    }
-
-    @Override
-    public TypeMirror asType() {
-        throw new UnsupportedOperationException("Unsupported method");
-    }
+public class OverviewElement implements DocletElement {
 
-    @Override
-    public ElementKind getKind() {
-        return ElementKind.OTHER;
-    }
+    private final PackageElement pkg;
+    private final FileObject fo;
 
-    @Override
-    public Set<javax.lang.model.element.Modifier> getModifiers() {
-        throw new UnsupportedOperationException("Unsupported method");
-    }
-
-    @Override
-    public Name getSimpleName() {
-        throw new UnsupportedOperationException("Unsupported method");
+    public OverviewElement(PackageElement pkg, FileObject fo) {
+        this.pkg = pkg;
+        this.fo = fo;
     }
 
     @Override
-    public Element getEnclosingElement() {
-        throw new UnsupportedOperationException("Unsupported method");
+    public PackageElement getPackageElement() {
+        return pkg;
     }
 
-    @Override
-    public java.util.List<? extends Element> getEnclosedElements() {
-        throw new UnsupportedOperationException("Unsupported method");
-    }
-
-    @Override
-    public java.util.List<? extends AnnotationMirror> getAnnotationMirrors() {
-        throw new UnsupportedOperationException("Unsupported method");
+    public FileObject getFileObject() {
+        return fo;
     }
 
     @Override
-    public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
-        throw new UnsupportedOperationException("Unsupported method");
-    }
-
-    @Override
-    public <R, P> R accept(ElementVisitor<R, P> v, P p) {
-        return v.visitUnknown(this, p);
-    }
-
-    @Override
-    public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
-        throw new UnsupportedOperationException("Unsupported method");
+    public Kind getSubKind() {
+        return Kind.OVERVIEW;
     }
 }
 
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java	Thu Nov 30 06:14:25 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -25,6 +25,7 @@
 
 package jdk.javadoc.internal.doclets.toolkit;
 
+import javax.lang.model.element.Element;
 import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
@@ -222,4 +223,11 @@
      * @return the writer for the serialized form.
      */
     public SerializedFormWriter getSerializedFormWriter();
+
+    /**
+     * Return the handler for doc files.
+     *
+     * @return the handler for the doc files.
+     */
+    DocFilesHandler getDocFilesHandler(Element pkg);
 }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeBuilder.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeBuilder.java	Thu Nov 30 06:14:25 2017 -0800
@@ -30,6 +30,7 @@
 
 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
 import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
 import jdk.javadoc.internal.doclets.toolkit.DocletException;
 
 
@@ -132,7 +133,10 @@
             //Only copy doc files dir if the containing package is not
             //documented AND if we have not documented a class from the same
             //package already. Otherwise, we are making duplicate copies.
-            utils.copyDocFiles(containingPackage);
+            DocFilesHandler docFilesHandler = configuration
+                    .getWriterFactory()
+                    .getDocFilesHandler(containingPackage);
+            docFilesHandler.copyDocFiles();
             containingPackagesSeen.add(containingPackage);
         }
     }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java	Thu Nov 30 06:14:25 2017 -0800
@@ -34,12 +34,15 @@
 import javax.lang.model.type.TypeMirror;
 
 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
+import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
 import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
-import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
 import jdk.javadoc.internal.doclets.toolkit.PropertyWriter;
 import jdk.javadoc.internal.doclets.toolkit.WriterFactory;
 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
 
+
+
+
 /**
  * The factory for constructing builders.
  *
@@ -87,7 +90,7 @@
      * @param pkg the package being documented.
      * @param prevPkg the previous package being documented.
      * @param nextPkg the next package being documented.
-     * @return the builder that builds the constant summary.
+     * @return the builder that builds the package summary.
      */
     public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg, PackageElement prevPkg,
             PackageElement nextPkg) {
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java	Thu Nov 30 06:14:25 2017 -0800
@@ -30,6 +30,7 @@
 
 import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
 import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
 import jdk.javadoc.internal.doclets.toolkit.DocletException;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
@@ -269,7 +270,7 @@
      *
      * @throws DocFileIOException if there is a problem while copying the files
      */
-     private void copyDocFiles() throws DocFileIOException {
+     private void copyDocFiles() throws DocletException {
         PackageElement containingPackage = utils.containingPackage(typeElement);
         if ((configuration.packages == null ||
             !configuration.packages.contains(containingPackage)) &&
@@ -277,7 +278,10 @@
             //Only copy doc files dir if the containing package is not
             //documented AND if we have not documented a class from the same
             //package already. Otherwise, we are making duplicate copies.
-            utils.copyDocFiles(containingPackage);
+            DocFilesHandler docFilesHandler = configuration
+                    .getWriterFactory()
+                    .getDocFilesHandler(containingPackage);
+            docFilesHandler.copyDocFiles();
             containingPackagesSeen.add(containingPackage);
         }
      }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java	Thu Nov 30 06:14:25 2017 -0800
@@ -30,7 +30,6 @@
 import jdk.javadoc.internal.doclets.toolkit.Content;
 import jdk.javadoc.internal.doclets.toolkit.DocletException;
 import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter;
-import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
 
 
 /**
@@ -117,7 +116,9 @@
 
         moduleWriter.addModuleFooter(contentTree);
         moduleWriter.printDocument(contentTree);
-        utils.copyDirectory(mdle, DocPaths.moduleSummary(mdle));
+        // uncomment to support doc-files in modules
+        // DocFilesHandler docFilesHandler = configuration.getWriterFactory().getDocFilesWriter(mdle);
+        // docFilesHandler.copyDocFiles();
     }
 
     /**
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java	Thu Nov 30 06:14:25 2017 -0800
@@ -32,6 +32,7 @@
 import javax.lang.model.element.TypeElement;
 
 import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
 import jdk.javadoc.internal.doclets.toolkit.DocletException;
 import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter;
 
@@ -122,7 +123,10 @@
 
         packageWriter.addPackageFooter(contentTree);
         packageWriter.printDocument(contentTree);
-        utils.copyDocFiles(packageElement);
+        DocFilesHandler docFilesHandler = configuration
+                .getWriterFactory()
+                .getDocFilesHandler(packageElement);
+        docFilesHandler.copyDocFiles();
     }
 
     /**
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java	Thu Nov 30 06:14:25 2017 -0800
@@ -43,6 +43,7 @@
 import jdk.javadoc.doclet.Doclet;
 import jdk.javadoc.doclet.DocletEnvironment;
 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
+import jdk.javadoc.internal.doclets.toolkit.DocletElement;
 import jdk.javadoc.internal.doclets.toolkit.Messages;
 import jdk.javadoc.internal.doclets.toolkit.Resources;
 
@@ -571,6 +572,7 @@
         return serializedFormTags;
     }
 
+    @SuppressWarnings("fallthrough")
     /**
      * Returns the custom tags for a given element.
      *
@@ -597,7 +599,17 @@
             case PACKAGE:
                 return getPackageCustomTaglets();
             case OTHER:
-                return getOverviewCustomTaglets();
+                if (e instanceof DocletElement) {
+                    DocletElement de = (DocletElement)e;
+                    switch (de.getSubKind()) {
+                        case DOCFILE:
+                            return getPackageCustomTaglets();
+                        case OVERVIEW:
+                            return getOverviewCustomTaglets();
+                        default:
+                            // fall through
+                    }
+                }
             default:
                 throw new AssertionError("unknown element: " + e + " ,kind: " + e.getKind());
         }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocFile.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocFile.java	Thu Nov 30 06:14:25 2017 -0800
@@ -33,6 +33,7 @@
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 
+import javax.tools.FileObject;
 import javax.tools.JavaFileManager.Location;
 import javax.tools.StandardLocation;
 
@@ -102,6 +103,12 @@
     }
 
     /**
+     * Returns a file object for the file.
+     * @return a file object
+     */
+    public abstract FileObject getFileObject();
+
+    /**
      * Open an input stream for the file.
      *
      * @return an open input stream for the file
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java	Thu Nov 30 06:14:25 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
@@ -25,6 +25,7 @@
 
 package jdk.javadoc.internal.doclets.toolkit.util;
 
+import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
 
@@ -73,6 +74,12 @@
         return (typeElement == null) ? empty : new DocPath(utils.getSimpleName(typeElement) + ".html");
     }
 
+    public static DocPath forModule(ModuleElement mdle) {
+        return mdle == null || mdle.isUnnamed()
+                ? empty
+                : DocPath.create(mdle.getQualifiedName().toString());
+    }
+
     /**
      * Return the path for the package of a class.
      * For example, if the class is java.lang.Object,
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Nov 30 06:14:25 2017 -0800
@@ -170,6 +170,11 @@
     /** The name of the file for the package usage info. */
     public static final DocPath PACKAGE_USE = DocPath.create("package-use.html");
 
+    /** The name of the output directory for module documentation files. */
+    public static DocPath moduleDocFiles(ModuleElement mdle) {
+        return DocPath.create(mdle.getQualifiedName() + "-doc-files");
+    }
+
     /** The name of the file for the module frame. */
     public static DocPath moduleFrame(ModuleElement mdle) {
         return DocPath.create(mdle.getQualifiedName() + "-frame.html");
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/StandardDocFileFactory.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/StandardDocFileFactory.java	Thu Nov 30 06:14:25 2017 -0800
@@ -151,6 +151,11 @@
             this.file = newFile(getDestDir(), path.getPath());
         }
 
+        @Override
+        public FileObject getFileObject()  {
+            return getJavaFileObjectForInput(file);
+        }
+
         /**
          * Open an input stream for the file.
          *
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Thu Nov 30 06:14:25 2017 -0800
@@ -74,10 +74,12 @@
 import com.sun.source.doctree.DocTree.Kind;
 import com.sun.source.doctree.ParamTree;
 import com.sun.source.doctree.SerialFieldTree;
+import com.sun.source.doctree.StartElementTree;
 import com.sun.source.tree.CompilationUnitTree;
 import com.sun.source.tree.LineMap;
 import com.sun.source.util.DocSourcePositions;
 import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
 import com.sun.source.util.TreePath;
 import com.sun.tools.javac.model.JavacTypes;
 import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration;
@@ -265,97 +267,7 @@
         return getEnclosingTypeElement(e) == null || isStatic(e);
     }
 
-    /**
-     * Copy doc-files directory and its contents from the source
-     * package directory to the generated documentation directory.
-     * For example, given a package java.lang, this method will copy
-     * the doc-files directory, found in the package directory to the
-     * generated documentation hierarchy.
-     *
-     * @param pe the package containing the doc files to be copied
-     * @throws DocFileIOException if there is a problem while copying
-     *         the documentation files
-     */
-    public void copyDocFiles(PackageElement pe) throws DocFileIOException {
-        Location sourceLoc = getLocationForPackage(pe);
-        copyDirectory(sourceLoc, DocPath.forPackage(pe).resolve(DocPaths.DOC_FILES));
-    }
-
-    /**
-     * Copy the given directory contents from the source package directory
-     * to the generated documentation directory. For example, given a package
-     * java.lang, this method will copy the entire directory, to the generated
-     * documentation hierarchy.
-     *
-     * @param pe the package containing the directory to be copied
-     * @param dir the directory to be copied
-     * @throws DocFileIOException if there is a problem while copying
-     *         the documentation files
-     */
-    public void copyDirectory(PackageElement pe, DocPath dir) throws DocFileIOException {
-        copyDirectory(getLocationForPackage(pe), dir);
-    }
-
-    /**
-     * Copy the given directory and its contents from the source
-     * module directory to the generated documentation directory.
-     * For example, given a package java.lang, this method will
-     * copy the entire directory, to the generated documentation
-     * hierarchy.
-     *
-     * @param mdle the module containing the directory to be copied
-     * @param dir the directory to be copied
-     * @throws DocFileIOException if there is a problem while copying
-     *         the documentation files
-     */
-    public void copyDirectory(ModuleElement mdle, DocPath dir) throws DocFileIOException  {
-        copyDirectory(getLocationForModule(mdle), dir);
-    }
-
-    /**
-     * Copy files from a doc path location to the output.
-     *
-     * @param locn the location from which to read files
-     * @param dir the directory to be copied
-     * @throws DocFileIOException if there is a problem
-     *         copying the files
-     */
-    public void copyDirectory(Location locn, DocPath dir)  throws DocFileIOException {
-        boolean first = true;
-        for (DocFile f : DocFile.list(configuration, locn, dir)) {
-            if (!f.isDirectory()) {
-                continue;
-            }
-            DocFile srcdir = f;
-            DocFile destdir = DocFile.createFileForOutput(configuration, dir);
-            if (srcdir.isSameFile(destdir)) {
-                continue;
-            }
-
-            for (DocFile srcfile: srcdir.list()) {
-                DocFile destfile = destdir.resolve(srcfile.getName());
-                if (srcfile.isFile()) {
-                    if (destfile.exists() && !first) {
-                        messages.warning("doclet.Copy_Overwrite_warning",
-                                srcfile.getPath(), destdir.getPath());
-                    } else {
-                        messages.notice("doclet.Copying_File_0_To_Dir_1",
-                                srcfile.getPath(), destdir.getPath());
-                        destfile.copyFile(srcfile);
-                    }
-                } else if (srcfile.isDirectory()) {
-                    if (configuration.copydocfilesubdirs
-                            && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
-                        copyDirectory(locn, dir.resolve(srcfile.getName()));
-                    }
-                }
-            }
-
-            first = false;
-        }
-    }
-
-    protected Location getLocationForPackage(PackageElement pd) {
+    public Location getLocationForPackage(PackageElement pd) {
         ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(pd);
 
         if (mdle == null)
@@ -364,7 +276,7 @@
         return getLocationForModule(mdle);
     }
 
-    protected Location getLocationForModule(ModuleElement mdle) {
+    public Location getLocationForModule(ModuleElement mdle) {
         Location loc = configuration.workArounds.getLocationForModule(mdle);
         if (loc != null)
             return loc;
@@ -3127,6 +3039,13 @@
         return dcTree;
     }
 
+    public List<? extends DocTree> getPreamble(Element element) {
+        DocCommentTree docCommentTree = getDocCommentTree(element);
+        return docCommentTree == null
+                ? Collections.emptyList()
+                : docCommentTree.getPreamble();
+    }
+
     public List<? extends DocTree> getFullBody(Element element) {
         DocCommentTree docCommentTree = getDocCommentTree(element);
             return (docCommentTree == null)
--- a/test/langtools/jdk/javadoc/doclet/testCopyFiles/TestCopyFiles.java	Thu Nov 30 04:43:09 2017 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/TestCopyFiles.java	Thu Nov 30 06:14:25 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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,8 +23,8 @@
 
 /*
  * @test
- * @bug  8157349
- * @summary  test copy of doc-files
+ * @bug  8157349 8185985
+ * @summary  test copy of doc-files, and its contents for HTML meta content.
  * @library  ../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  * @build    JavadocTester
@@ -39,13 +39,123 @@
     }
 
     @Test
-    void testDocFilesInModules() {
+    void testDocFilesInModulePackages() {
         javadoc("-d", "modules-out",
+                "-top", "phi-TOP-phi",
+                "-bottom", "phi-BOTTOM-phi",
+                "-header", "phi-HEADER-phi",
+                "-footer", "phi-FOOTER-phi",
+                "-windowtitle", "phi-WINDOW-TITLE-phi",
+                "--module-source-path", testSrc("modules"),
+                "--module", "acme.mdle");
+        checkExit(Exit.OK);
+        checkOrder("p/doc-files/inpackage.html",
+                "\"Hello World\" (phi-WINDOW-TITLE-phi)",
+                "phi-TOP-phi",
+                // check top navbar
+                "<a href=\"../../acme.mdle-summary.html\">Module</a>",
+                "<a href=\"../../p/package-summary.html\">Package</a>",
+                "<a href=\"../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../index-all.html\">Index</a>",
+                "phi-HEADER-phi",
+                "In a named module acme.module and named package "
+                        + "<a href=\"../../p/package-summary.html\"><code>p</code></a>.",
+                "\"simpleTagLabel\">Since:</",
+                "1940",
+                // check bottom navbar
+                "<a href=\"../../acme.mdle-summary.html\">Module</a>",
+                "<a href=\"../../p/package-summary.html\">Package</a>",
+                "<a href=\"../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../index-all.html\">Index</a>",
+                "phi-FOOTER-phi",
+                "phi-BOTTOM-phi"
+        );
+    }
+
+    @Test
+    void testDocFilesInMultiModulePackagesWithRecursiveCopy() {
+        javadoc("-d", "multi-modules-out-recursive",
+                "-docfilessubdirs",
+                "-top", "phi-TOP-phi",
+                "-bottom", "phi-BOTTOM-phi",
+                "-header", "phi-HEADER-phi",
+                "-footer", "phi-FOOTER-phi",
+                "-windowtitle", "phi-WINDOW-TITLE-phi",
+                "--module-source-path", testSrc("modules"),
+                "--module", "acme.mdle,acme2.mdle");
+        checkExit(Exit.OK);
+        checkOrder("p/doc-files/inpackage.html",
+                "\"Hello World\" (phi-WINDOW-TITLE-phi)",
+                "phi-TOP-phi",
+                // check top navbar
+                "<a href=\"../../acme.mdle-summary.html\">Module</a>",
+                "<a href=\"../../p/package-summary.html\">Package</a>",
+                "<a href=\"../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../index-all.html\">Index</a>",
+                "phi-HEADER-phi",
+                "In a named module acme.module and named package "
+                        + "<a href=\"../../p/package-summary.html\"><code>p</code></a>.",
+                "\"simpleTagLabel\">Since:</",
+                "1940",
+                // check bottom navbar
+                "<a href=\"../../acme.mdle-summary.html\">Module</a>",
+                "<a href=\"../../p/package-summary.html\">Package</a>",
+                "<a href=\"../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../index-all.html\">Index</a>",
+                "phi-FOOTER-phi",
+                "phi-BOTTOM-phi"
+        );
+
+        // check the bottom most doc file
+        checkOrder("p2/doc-files/sub-dir/sub-dir-1/SubSubReadme.html",
+                "SubSubReadme (phi-WINDOW-TITLE-phi)",
+                "phi-TOP-phi",
+                // check top navbar
+                "<a href=\"../../../../acme2.mdle-summary.html\">Module</a>",
+                "<a href=\"../../../../p2/package-summary.html\">Package</a>",
+                "<a href=\"../../../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../../../index-all.html\">Index</a>",
+                "phi-HEADER-phi",
+                "SubSubReadme.html at third level of doc-file directory.",
+                // check bottom navbar
+                "<a href=\"../../../../acme2.mdle-summary.html\">Module</a>",
+                "<a href=\"../../../../p2/package-summary.html\">Package</a>",
+                "<a href=\"../../../../overview-tree.html\">Tree</a>",
+                "<a href=\"../../../../deprecated-list.html\">Deprecated</a>",
+                "<a href=\"../../../../index-all.html\">Index</a>",
+                "phi-FOOTER-phi",
+                "phi-BOTTOM-phi"
+        );
+    }
+    @Test
+    void testDocFilesInModulePackagesWithRecursiveCopy() {
+        javadoc("-d", "modules-out-recursive",
+                "-docfilessubdirs",
                 "--module-source-path", testSrc("modules"),
                 "--module", "acme.mdle");
         checkExit(Exit.OK);
         checkOutput("p/doc-files/inpackage.html", true,
-                "In a named module and named package"
+                "In a named module acme.module and named package "
+                + "<a href=\"../../p/package-summary.html\"><code>p</code></a>."
+        );
+    }
+
+    @Test
+    void testDocFilesInModulePackagesWithRecursiveCopyWithExclusion() {
+        javadoc("-d", "modules-out-recursive-with-exclusion",
+                "-docfilessubdirs",
+                "-excludedocfilessubdir", "sub-dir",
+                "--module-source-path", testSrc("modules"),
+                "--module", "acme.mdle");
+        checkExit(Exit.OK);
+        checkOutput("p/doc-files/inpackage.html", true,
+                "In a named module acme.module and named package "
+                + "<a href=\"../../p/package-summary.html\"><code>p</code></a>."
         );
     }
 
@@ -61,18 +171,71 @@
     }
 
     @Test
+    void testDocFilesInPackagesWithRecursiveCopy() {
+        javadoc("-d", "packages-out-recursive",
+                "-docfilessubdirs",
+                "-sourcepath", testSrc("packages"),
+                "p1");
+        checkExit(Exit.OK);
+
+        checkOutput("p1/doc-files/inpackage.html", true,
+                "A named package in an unnamed module"
+        );
+
+        checkOutput("p1/doc-files/sub-dir/SubReadme.html", true,
+                "<title>SubReadme</title>",
+                "SubReadme.html at second level of doc-file directory."
+        );
+    }
+
+    @Test
+    void testDocFilesInPackagesWithRecursiveCopyWithExclusion() {
+        javadoc("-d", "packages-out-recursive-with-exclusion",
+                "-docfilessubdirs",
+                "-excludedocfilessubdir", "sub-dir",
+                "-sourcepath", testSrc("packages"),
+                "p1");
+        checkExit(Exit.OK);
+
+        checkOutput("p1/doc-files/inpackage.html", true,
+                "A named package in an unnamed module"
+        );
+    }
+
+    @Test
     void testDocFilesInUnnamedPackages() {
         javadoc("-d", "unnamed-out",
+                "-windowtitle", "phi-WINDOW-TITLE-phi",
                 "-sourcepath", testSrc("unnamed"),
                 testSrc("unnamed/Foo.java")
         );
         checkExit(Exit.OK);
         checkOutput("doc-files/inpackage.html", true,
+                "<title>(phi-WINDOW-TITLE-phi)</title>\n",
                 "In an unnamed package"
         );
     }
 
     @Test
+    void testDocFilesInUnnamedPackagesWithRecursiveCopy() {
+        javadoc("-d", "unnamed-out-recursive",
+                "-docfilessubdirs",
+                "-windowtitle", "phi-WINDOW-TITLE-phi",
+                "-sourcepath", testSrc("unnamed"),
+                testSrc("unnamed/Foo.java")
+        );
+        checkExit(Exit.OK);
+        checkOutput("doc-files/inpackage.html", true,
+                "<title>(phi-WINDOW-TITLE-phi)</title>\n",
+                "In an unnamed package"
+        );
+        checkOutput("doc-files/doc-file/SubReadme.html", true,
+                "<title>Beep Beep (phi-WINDOW-TITLE-phi)</title>\n",
+                "SubReadme.html at second level of doc-file directory for unnamed package."
+        );
+    }
+
+    @Test
     void testDocFilesInPackagesSource7() {
         javadoc("-d", "packages-out-src7",
                 "-source", "7",
--- a/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/inpackage.html	Thu Nov 30 04:43:09 2017 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/inpackage.html	Thu Nov 30 06:14:25 2017 -0800
@@ -28,6 +28,8 @@
     <title>"Hello World"</title>
   </head>
   <body>
-    In a named module and named package 
+    In a named module acme.module and named package {@link p}.
+    @author Wile E. Coyote
+    @since 1940
   </body>
 </html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/sub-dir/SubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SubReadme</title>
+</head>
+<body>
+    SubReadme.html at second level of doc-file directory for acme.module.
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/doc-files/sub-dir/sub-dir-1/SubSubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SubSubReadme</title>
+</head>
+<body>
+    SubSubReadme.html at third level of doc-file directory.
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme.mdle/p/package.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>package.html file for p</title>
+</head>
+<body>
+    A named package {@link p} in a name module acme.mdle.
+    @author WECoyote
+    @since 1940
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/module-info.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /**
+  * A test module.
+  */
+module acme2.mdle {
+    exports p2;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/Foo.java	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p2;
+
+/**
+ * A test class.
+ */
+public class Foo {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/inpackage.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!--
+Copyright (c) 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
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.  Oracle designates this
+particular file as subject to the "Classpath" exception as provided
+by Oracle in the LICENSE file that accompanied this code.
+
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+-->
+
+<html>
+  <head>
+    <title>"Hello World"</title>
+  </head>
+  <body>
+    In a named module acme2.mdle and named package {@link p2}.
+    @author Wile E. Coyote
+    @since 1940
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/sub-dir/SubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SubReadme</title>
+</head>
+<body>
+    SubReadme.html at second level of doc-file directory for acme2.mdle.
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/doc-files/sub-dir/sub-dir-1/SubSubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SubSubReadme</title>
+</head>
+<body>
+    SubSubReadme.html at third level of doc-file directory.
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/acme2.mdle/p2/package.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>package.html file for p</title>
+</head>
+<body>
+    A named package {@link p2} in a name module acme2.mdle.
+    @author WECoyote
+    @since 1940
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/modules/overview.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>My overview html file</title>
+</head>
+<body>
+The overview html file
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/packages/p1/doc-files/sub-dir/SubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SubReadme</title>
+</head>
+<body>
+    SubReadme.html at second level of doc-file directory.
+</body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/unnamed/doc-files/doc-file/SubReadme.html	Thu Nov 30 06:14:25 2017 -0800
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+  ~ Copyright (c) 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
+  ~ under the terms of the GNU General Public License version 2 only, as
+  ~ published by the Free Software Foundation.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ This code is distributed in the hope that it will be useful, but WITHOUT
+  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  ~ version 2 for more details (a copy is included in the LICENSE file that
+  ~ accompanied this code).
+  ~
+  ~ You should have received a copy of the GNU General Public License version
+  ~ 2 along with this work; if not, write to the Free Software Foundation,
+  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  ~
+  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  ~ or visit www.oracle.com if you need additional information or have any
+  ~ questions.
+  -->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <TITLE>Beep Beep</TITLE>
+</head>
+<body>
+     SubReadme.html at second level of doc-file directory for unnamed package.
+</body>
+</html>
\ No newline at end of file
--- a/test/langtools/jdk/javadoc/doclet/testCopyFiles/unnamed/doc-files/inpackage.html	Thu Nov 30 04:43:09 2017 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testCopyFiles/unnamed/doc-files/inpackage.html	Thu Nov 30 06:14:25 2017 -0800
@@ -24,9 +24,6 @@
 -->
 
 <html>
-  <head>
-    <title>"Hello World"</title>
-  </head>
   <body>
     In an unnamed package 
   </body>