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("p/doc-files/inpackage.html",
  53                 "\"Hello World\" (phi-WINDOW-TITLE-phi)",
  54                 "phi-TOP-phi",
  55                 // check top navbar
  56                 "<a href=\"../../acme.mdle-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=\"../../acme.mdle-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("p/doc-files/inpackage.html",
  90                 "\"Hello World\" (phi-WINDOW-TITLE-phi)",
  91                 "phi-TOP-phi",
  92                 // check top navbar
  93                 "<a href=\"../../acme.mdle-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=\"../../acme.mdle-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("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=\"../../../../acme2.mdle-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=\"../../../../acme2.mdle-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     @Test
 136     void testDocFilesInModulePackagesWithRecursiveCopy() {
 137         javadoc("-d", "modules-out-recursive",
 138                 "-docfilessubdirs",
 139                 "--module-source-path", testSrc("modules"),
 140                 "--module", "acme.mdle");
 141         checkExit(Exit.OK);
 142         checkOutput("p/doc-files/inpackage.html", true,
 143                 "In a named module acme.module and named package "
 144                 + "<a href=\"../package-summary.html\"><code>p</code></a>."
 145         );
 146     }
 147 
 148     @Test
 149     void testDocFilesInModulePackagesWithRecursiveCopyWithExclusion() {
 150         javadoc("-d", "modules-out-recursive-with-exclusion",
 151                 "-docfilessubdirs",
 152                 "-excludedocfilessubdir", "sub-dir",
 153                 "--module-source-path", testSrc("modules"),
 154                 "--module", "acme.mdle");
 155         checkExit(Exit.OK);
 156         checkOutput("p/doc-files/inpackage.html", true,
 157                 "In a named module acme.module and named package "
 158                 + "<a href=\"../package-summary.html\"><code>p</code></a>."
 159         );
 160     }
 161 
 162     @Test
 163     void testDocFilesInPackages() {
 164         javadoc("-d", "packages-out",
 165                 "-sourcepath", testSrc("packages"),
 166                 "p1");
 167         checkExit(Exit.OK);
 168         checkOutput("p1/doc-files/inpackage.html", true,
 169                 "A named package in an unnamed module"
 170         );
 171     }
 172 
 173     @Test
 174     void testDocFilesInPackagesWithRecursiveCopy() {
 175         javadoc("-d", "packages-out-recursive",
 176                 "-docfilessubdirs",
 177                 "-sourcepath", testSrc("packages"),
 178                 "p1");
 179         checkExit(Exit.OK);
 180 
 181         checkOutput("p1/doc-files/inpackage.html", true,
 182                 "A named package in an unnamed module"
 183         );
 184 
 185         checkOutput("p1/doc-files/sub-dir/SubReadme.html", true,
 186                 "<title>SubReadme</title>",
 187                 "SubReadme.html at second level of doc-file directory."
 188         );
 189     }
 190 
 191     @Test
 192     void testDocFilesInPackagesWithRecursiveCopyWithExclusion() {
 193         javadoc("-d", "packages-out-recursive-with-exclusion",
 194                 "-docfilessubdirs",
 195                 "-excludedocfilessubdir", "sub-dir",
 196                 "-sourcepath", testSrc("packages"),
 197                 "p1");
 198         checkExit(Exit.OK);
 199 
 200         checkOutput("p1/doc-files/inpackage.html", true,
 201                 "A named package in an unnamed module"
 202         );
 203     }
 204 
 205     @Test
 206     void testDocFilesInUnnamedPackages() {
 207         javadoc("-d", "unnamed-out",
 208                 "-windowtitle", "phi-WINDOW-TITLE-phi",
 209                 "-sourcepath", testSrc("unnamed"),
 210                 testSrc("unnamed/Foo.java")
 211         );
 212         checkExit(Exit.OK);
 213         checkOutput("doc-files/inpackage.html", true,
 214                 "<title>(phi-WINDOW-TITLE-phi)</title>\n",
 215                 "In an unnamed package"
 216         );
 217     }
 218 
 219     @Test
 220     void testDocFilesInUnnamedPackagesWithRecursiveCopy() {
 221         javadoc("-d", "unnamed-out-recursive",
 222                 "-docfilessubdirs",
 223                 "-windowtitle", "phi-WINDOW-TITLE-phi",
 224                 "-sourcepath", testSrc("unnamed"),
 225                 testSrc("unnamed/Foo.java")
 226         );
 227         checkExit(Exit.OK);
 228         checkOutput("doc-files/inpackage.html", true,
 229                 "<title>(phi-WINDOW-TITLE-phi)</title>\n",
 230                 "In an unnamed package"
 231         );
 232         checkOutput("doc-files/doc-file/SubReadme.html", true,
 233                 "<title>Beep Beep (phi-WINDOW-TITLE-phi)</title>\n",
 234                 "SubReadme.html at second level of doc-file directory for unnamed package."
 235         );
 236     }
 237 
 238     @Test
 239     void testDocFilesInPackagesSource7() {
 240         javadoc("-d", "packages-out-src7",
 241                 "-source", "7",
 242                 "-sourcepath", testSrc("packages"),
 243                 "p1");
 244         checkExit(Exit.OK);
 245         checkOutput("p1/doc-files/inpackage.html", true,
 246                 "A named package in an unnamed module"
 247         );
 248     }
 249 
 250     @Test
 251     void testDocFilesInPackagesSource7UsingClassPath() {
 252         javadoc("-d", "packages-out-src7-cp",
 253                 "-source", "7",
 254                 "-classpath", testSrc("packages"),
 255                 "p1");
 256         checkExit(Exit.OK);
 257         checkOutput("p1/doc-files/inpackage.html", true,
 258                 "A named package in an unnamed module"
 259         );
 260     }
 261 
 262     @Test
 263     void testCopyThrough() {
 264         javadoc("-d", "copy",
 265                 "-sourcepath", testSrc("packages"),
 266                 "p2");
 267         checkExit(Exit.OK);
 268         checkOutput("p2/doc-files/case1.html", true, "<!-- Generated by javadoc");
 269         checkOutput("p2/doc-files/case2.html", false, "<!-- Generated by javadoc");
 270         checkOutput("p2/doc-files/case3.html", false, "<!-- Generated by javadoc");
 271         checkOutput("p2/doc-files/case4.html", false, "<!-- Generated by javadoc");
 272     }
 273 }