test/langtools/jdk/javadoc/doclet/testDocFiles/TestDocFiles.java
changeset 59210 78184b74af6e
parent 53097 2e82ca64b25d
equal deleted inserted replaced
59209:8a24f1e73c0d 59210:78184b74af6e
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8008949
    26  * @bug 8008949 8234051
    27  * @summary verify that doc-files get copied
    27  * @summary doclet crashes if HTML files in module doc-files directories
    28  * @library ../../lib
    28  * @library /tools/lib ../../lib
    29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
    29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
    30  * @build javadoc.tester.*
    30  * @build toolbox.ToolBox javadoc.tester.*
    31  * @run main TestDocFiles
    31  * @run main TestDocFiles
    32  */
    32  */
    33 
    33 
       
    34 import java.io.IOException;
       
    35 import java.nio.file.Path;
       
    36 
       
    37 import toolbox.ToolBox;
    34 import javadoc.tester.JavadocTester;
    38 import javadoc.tester.JavadocTester;
    35 
    39 
    36 public class TestDocFiles extends JavadocTester {
    40 public class TestDocFiles extends JavadocTester {
    37 
    41 
    38     public static void main(String... args) throws Exception {
    42     public static void main(String... args) throws Exception {
    39         TestDocFiles tester = new TestDocFiles();
    43         TestDocFiles tester = new TestDocFiles();
    40         tester.runTests();
    44         tester.runTests(m -> new Object[] { Path.of(m.getName()) });
    41     }
    45     }
    42 
    46 
       
    47     ToolBox tb = new ToolBox();
       
    48 
       
    49     /**
       
    50      * Check doc-files support for a package that is not in a module.
       
    51      * @param base the base directory for scratch files
       
    52      * @throws IOException if an exception occurs
       
    53      */
    43     @Test
    54     @Test
    44     public void test() {
    55     public void testPackage(Path base) throws IOException {
    45         javadoc("-d", "out",
    56         Path src = base.resolve("src");
    46                 "-sourcepath", testSrc,
    57 
    47                 "pkg");
    58         // write the skeletal Java files
       
    59         tb.writeJavaFiles(src,
       
    60                 "package p; public class C { }\n");
       
    61 
       
    62         // write the doc files for the package
       
    63         Path pkgDocFiles = src.resolve("p").resolve("doc-files");
       
    64         tb.writeFile(pkgDocFiles.resolve("pkg-file.txt"),
       
    65                 "package text file\n");
       
    66         tb.writeFile(pkgDocFiles.resolve("pkg-file.html"),
       
    67                 "<html>\n"
       
    68                 + "<head><title>Package HTML file</title></head>\n"
       
    69                 + "<body><h1>Package HTML file</h1>File content</body>\n"
       
    70                 + "</html>\n");
       
    71 
       
    72         javadoc("-d", base.resolve("out").toString(),
       
    73                 "--source-path", src.toString(),
       
    74                 "p");
    48         checkExit(Exit.OK);
    75         checkExit(Exit.OK);
    49 
    76 
    50         checkOutput("pkg/doc-files/test.txt", true,
    77         checkOutput("p/doc-files/pkg-file.txt", true,
    51                 "test file");
    78                 "package text file");
       
    79         checkOutput("p/doc-files/pkg-file.html", true,
       
    80                 "Package HTML file");
       
    81     }
       
    82 
       
    83     /**
       
    84      * Check doc-files support for a module and a package that is in a module.
       
    85      * @param base the base directory for scratch files
       
    86      * @throws IOException if an exception occurs
       
    87      */
       
    88     @Test
       
    89     public void testModules(Path base) throws IOException {
       
    90         Path src = base.resolve("src");
       
    91 
       
    92         // write the skeletal Java files
       
    93         tb.writeJavaFiles(src,
       
    94                 "module m { exports p; }\n",
       
    95                 "package p; public class C { }\n");
       
    96 
       
    97         // write the doc files for the module
       
    98         Path mdlDocFiles = src.resolve("doc-files");
       
    99         tb.writeFile(mdlDocFiles.resolve("mdl-file.txt"),
       
   100                 "module text file\n");
       
   101         tb.writeFile(mdlDocFiles.resolve("mdl-file.html"),
       
   102                 "<html>\n"
       
   103                 + "<head><title>Module HTML file</title></head>\n"
       
   104                 + "<body><h1>Module HTML file</h1>File content</body>\n"
       
   105                 + "</html>\n");
       
   106 
       
   107         // write the doc files for a package in the module
       
   108         Path pkgDocFiles = src.resolve("p").resolve("doc-files");
       
   109         tb.writeFile(pkgDocFiles.resolve("pkg-file.txt"),
       
   110                 "package text file\n");
       
   111         tb.writeFile(pkgDocFiles.resolve("pkg-file.html"),
       
   112                 "<html>\n"
       
   113                 + "<head><title>Package HTML file</title></head>\n"
       
   114                 + "<body><h1>Package HTML file</h1>File content</body>\n"
       
   115                 + "</html>\n");
       
   116 
       
   117         javadoc("-d", base.resolve("out").toString(),
       
   118                 "--source-path", src.toString(),
       
   119                 "--module", "m");
       
   120         checkExit(Exit.OK);
       
   121 
       
   122         checkOutput("m/doc-files/mdl-file.txt", true,
       
   123                 "module text file");
       
   124         checkOutput("m/doc-files/mdl-file.html", true,
       
   125                 "Module HTML file");
       
   126         checkOutput("m/p/doc-files/pkg-file.txt", true,
       
   127                 "package text file");
       
   128         checkOutput("m/p/doc-files/pkg-file.html", true,
       
   129                 "Package HTML file");
    52     }
   130     }
    53 }
   131 }