1 /*
   2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug  8157349 8185985 8194953
  27  * @summary  test copy of doc-files, and its contents for HTML meta content.
  28  * @library  ../lib
  29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  30  * @build    JavadocTester
  31  * @run main TestCopyFiles
  32  */
  33 
  34 public class TestCopyFiles extends JavadocTester {
  35 
  36     public static void main(String... args) throws Exception {
  37         TestCopyFiles tester = new TestCopyFiles();
  38         tester.runTests();
  39     }
  40 
  41     @Test
  42     void testDocFilesInModulePackages() {
  43         javadoc("-d", "modules-out",
  44                 "-top", "phi-TOP-phi",
  45                 "-bottom", "phi-BOTTOM-phi",
  46                 "-header", "phi-HEADER-phi",
  47                 "-footer", "phi-FOOTER-phi",
  48                 "-windowtitle", "phi-WINDOW-TITLE-phi",
  49                 "--module-source-path", testSrc("modules"),
  50                 "--module", "acme.mdle");
  51         checkExit(Exit.OK);
  52         checkOrder("acme.mdle/p/doc-files/inpackage.html",
  53                 "\"Hello World\" (phi-WINDOW-TITLE-phi)",
  54                 "phi-TOP-phi",
  55                 // check top navbar
  56                 "<a href=\"../../module-summary.html\">Module</a>",
  57                 "<a href=\"../package-summary.html\">Package</a>",
  58                 "<a href=\"../../../overview-tree.html\">Tree</a>",
  59                 "<a href=\"../../../deprecated-list.html\">Deprecated</a>",
  60                 "<a href=\"../../../index-all.html\">Index</a>",
  61                 "phi-HEADER-phi",
  62                 "In a named module acme.module and named package "
  63                         + "<a href=\"../package-summary.html\"><code>p</code></a>.",
  64                 "\"simpleTagLabel\">Since:</",
  65                 "1940",
  66                 // check bottom navbar
  67                 "<a href=\"../../module-summary.html\">Module</a>",
  68                 "<a href=\"../package-summary.html\">Package</a>",
  69                 "<a href=\"../../../overview-tree.html\">Tree</a>",
  70                 "<a href=\"../../../deprecated-list.html\">Deprecated</a>",
  71                 "<a href=\"../../../index-all.html\">Index</a>",
  72                 "phi-FOOTER-phi",
  73                 "phi-BOTTOM-phi"
  74         );
  75     }
  76 
  77     @Test
  78     void testDocFilesInMultiModulePackagesWithRecursiveCopy() {
  79         javadoc("-d", "multi-modules-out-recursive",
  80                 "-docfilessubdirs",
  81                 "-top", "phi-TOP-phi",
  82                 "-bottom", "phi-BOTTOM-phi",
  83                 "-header", "phi-HEADER-phi",
  84                 "-footer", "phi-FOOTER-phi",
  85                 "-windowtitle", "phi-WINDOW-TITLE-phi",
  86                 "--module-source-path", testSrc("modules"),
  87                 "--module", "acme.mdle,acme2.mdle");
  88         checkExit(Exit.OK);
  89         checkOrder("acme.mdle/p/doc-files/inpackage.html",
  90                 "\"Hello World\" (phi-WINDOW-TITLE-phi)",
  91                 "phi-TOP-phi",
  92                 // check top navbar
  93                 "<a href=\"../../module-summary.html\">Module</a>",
  94                 "<a href=\"../package-summary.html\">Package</a>",
  95                 "<a href=\"../../../overview-tree.html\">Tree</a>",
  96                 "<a href=\"../../../deprecated-list.html\">Deprecated</a>",
  97                 "<a href=\"../../../index-all.html\">Index</a>",
  98                 "phi-HEADER-phi",
  99                 "In a named module acme.module and named package "
 100                         + "<a href=\"../package-summary.html\"><code>p</code></a>.",
 101                 "\"simpleTagLabel\">Since:</",
 102                 "1940",
 103                 // check bottom navbar
 104                 "<a href=\"../../module-summary.html\">Module</a>",
 105                 "<a href=\"../package-summary.html\">Package</a>",
 106                 "<a href=\"../../../overview-tree.html\">Tree</a>",
 107                 "<a href=\"../../../deprecated-list.html\">Deprecated</a>",
 108                 "<a href=\"../../../index-all.html\">Index</a>",
 109                 "phi-FOOTER-phi",
 110                 "phi-BOTTOM-phi"
 111         );
 112 
 113         // check the bottom most doc file
 114         checkOrder("acme2.mdle/p2/doc-files/sub-dir/sub-dir-1/SubSubReadme.html",
 115                 "SubSubReadme (phi-WINDOW-TITLE-phi)",
 116                 "phi-TOP-phi",
 117                 // check top navbar
 118                 "<a href=\"../../../../module-summary.html\">Module</a>",
 119                 "<a href=\"../../../package-summary.html\">Package</a>",
 120                 "<a href=\"../../../../../overview-tree.html\">Tree</a>",
 121                 "<a href=\"../../../../../deprecated-list.html\">Deprecated</a>",
 122                 "<a href=\"../../../../../index-all.html\">Index</a>",
 123                 "phi-HEADER-phi",
 124                 "SubSubReadme.html at third level of doc-file directory.",
 125                 // check bottom navbar
 126                 "<a href=\"../../../../module-summary.html\">Module</a>",
 127                 "<a href=\"../../../package-summary.html\">Package</a>",
 128                 "<a href=\"../../../../../overview-tree.html\">Tree</a>",
 129                 "<a href=\"../../../../../deprecated-list.html\">Deprecated</a>",
 130                 "<a href=\"../../../../../index-all.html\">Index</a>",
 131                 "phi-FOOTER-phi",
 132                 "phi-BOTTOM-phi"
 133         );
 134     }
 135 
 136     @Test
 137     void testDocFilesInModulePackagesWithRecursiveCopy() {
 138         javadoc("-d", "modules-out-recursive",
 139                 "-docfilessubdirs",
 140                 "--module-source-path", testSrc("modules"),
 141                 "--module", "acme.mdle");
 142         checkExit(Exit.OK);
 143         checkOutput("acme.mdle/p/doc-files/inpackage.html", true,
 144                 "In a named module acme.module and named package "
 145                 + "<a href=\"../package-summary.html\"><code>p</code></a>."
 146         );
 147     }
 148 
 149     @Test
 150     void testDocFilesInModulePackagesWithRecursiveCopyWithExclusion() {
 151         javadoc("-d", "modules-out-recursive-with-exclusion",
 152                 "-docfilessubdirs",
 153                 "-excludedocfilessubdir", "sub-dir",
 154                 "--module-source-path", testSrc("modules"),
 155                 "--module", "acme.mdle");
 156         checkExit(Exit.OK);
 157         checkOutput("acme.mdle/p/doc-files/inpackage.html", true,
 158                 "In a named module acme.module and named package "
 159                 + "<a href=\"../package-summary.html\"><code>p</code></a>."
 160         );
 161     }
 162 
 163     @Test
 164     void testDocFilesInPackages() {
 165         javadoc("-d", "packages-out",
 166                 "-sourcepath", testSrc("packages"),
 167                 "p1");
 168         checkExit(Exit.OK);
 169         checkOutput("p1/doc-files/inpackage.html", true,
 170                 "A named package in an unnamed module"
 171         );
 172     }
 173 
 174     @Test
 175     void testDocFilesInPackagesWithRecursiveCopy() {
 176         javadoc("-d", "packages-out-recursive",
 177                 "-docfilessubdirs",
 178                 "-sourcepath", testSrc("packages"),
 179                 "p1");
 180         checkExit(Exit.OK);
 181 
 182         checkOutput("p1/doc-files/inpackage.html", true,
 183                 "A named package in an unnamed module"
 184         );
 185 
 186         checkOutput("p1/doc-files/sub-dir/SubReadme.html", true,
 187                 "<title>SubReadme</title>",
 188                 "SubReadme.html at second level of doc-file directory."
 189         );
 190     }
 191 
 192     @Test
 193     void testDocFilesInPackagesWithRecursiveCopyWithExclusion() {
 194         javadoc("-d", "packages-out-recursive-with-exclusion",
 195                 "-docfilessubdirs",
 196                 "-excludedocfilessubdir", "sub-dir",
 197                 "-sourcepath", testSrc("packages"),
 198                 "p1");
 199         checkExit(Exit.OK);
 200 
 201         checkOutput("p1/doc-files/inpackage.html", true,
 202                 "A named package in an unnamed module"
 203         );
 204     }
 205 
 206     @Test
 207     void testDocFilesInUnnamedPackages() {
 208         javadoc("-d", "unnamed-out",
 209                 "-windowtitle", "phi-WINDOW-TITLE-phi",
 210                 "-sourcepath", testSrc("unnamed"),
 211                 testSrc("unnamed/Foo.java")
 212         );
 213         checkExit(Exit.OK);
 214         checkOutput("doc-files/inpackage.html", true,
 215                 "<title>(phi-WINDOW-TITLE-phi)</title>\n",
 216                 "In an unnamed package"
 217         );
 218     }
 219 
 220     @Test
 221     void testDocFilesInUnnamedPackagesWithRecursiveCopy() {
 222         javadoc("-d", "unnamed-out-recursive",
 223                 "-docfilessubdirs",
 224                 "-windowtitle", "phi-WINDOW-TITLE-phi",
 225                 "-sourcepath", testSrc("unnamed"),
 226                 testSrc("unnamed/Foo.java")
 227         );
 228         checkExit(Exit.OK);
 229         checkOutput("doc-files/inpackage.html", true,
 230                 "<title>(phi-WINDOW-TITLE-phi)</title>\n",
 231                 "In an unnamed package"
 232         );
 233         checkOutput("doc-files/doc-file/SubReadme.html", true,
 234                 "<title>Beep Beep (phi-WINDOW-TITLE-phi)</title>\n",
 235                 "SubReadme.html at second level of doc-file directory for unnamed package."
 236         );
 237     }
 238 
 239     @Test
 240     void testDocFilesInPackagesSource7() {
 241         javadoc("-d", "packages-out-src7",
 242                 "-source", "7",
 243                 "-sourcepath", testSrc("packages"),
 244                 "p1");
 245         checkExit(Exit.OK);
 246         checkOutput("p1/doc-files/inpackage.html", true,
 247                 "A named package in an unnamed module"
 248         );
 249     }
 250 
 251     @Test
 252     void testDocFilesInPackagesSource7UsingClassPath() {
 253         javadoc("-d", "packages-out-src7-cp",
 254                 "-source", "7",
 255                 "-classpath", testSrc("packages"),
 256                 "p1");
 257         checkExit(Exit.OK);
 258         checkOutput("p1/doc-files/inpackage.html", true,
 259                 "A named package in an unnamed module"
 260         );
 261     }
 262 
 263     @Test
 264     void testCopyThrough() {
 265         javadoc("-d", "copy",
 266                 "-sourcepath", testSrc("packages"),
 267                 "p2");
 268         checkExit(Exit.OK);
 269         checkOutput("p2/doc-files/case1.html", true, "<!-- Generated by javadoc");
 270         checkOutput("p2/doc-files/case2.html", false, "<!-- Generated by javadoc");
 271         checkOutput("p2/doc-files/case3.html", false, "<!-- Generated by javadoc");
 272         checkOutput("p2/doc-files/case4.html", false, "<!-- Generated by javadoc");
 273     }
 274 }