1 /*
2  * Copyright (c) 2018, 2019, 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 8190875 8215599
27  * @summary modules not listed in overview/index page
28  * @library /tools/lib ../../lib
29  * @modules
30  *      jdk.javadoc/jdk.javadoc.internal.tool
31  *      jdk.compiler/com.sun.tools.javac.api
32  *      jdk.compiler/com.sun.tools.javac.main
33  * @build javadoc.tester.*
34  * @run main TestIndexWithModules
35  */
36 
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 
40 import builder.ClassBuilder;
41 import toolbox.ModuleBuilder;
42 import toolbox.ToolBox;
43 
44 
45 import javadoc.tester.JavadocTester;
46 
47 public class TestIndexWithModules extends JavadocTester {
48 
49     final ToolBox tb;
50     private final Path src;
51 
main(String... args)52     public static void main(String... args) throws Exception {
53         TestIndexWithModules tester = new TestIndexWithModules();
54         tester.runTests(m -> new Object[]{Paths.get(m.getName())});
55     }
56 
TestIndexWithModules()57     TestIndexWithModules() throws Exception{
58         tb = new ToolBox();
59         src = Paths.get("src");
60         initModules();
61     }
62 
63     @Test
testIndexWithOverviewPath(Path base)64     public void testIndexWithOverviewPath(Path base) throws Exception {
65         Path out = base.resolve("out");
66 
67         tb.writeFile("overview.html",
68                 "<html><body>The overview summary page header</body></html>");
69 
70         javadoc("-d", out.toString(),
71                 "-overview", "overview.html",
72                 "--module-source-path", src.toString(),
73                 "--module", "m1");
74 
75         checkExit(Exit.OK);
76         checkOrder("index.html",
77                 "The overview summary page header",
78                 "Modules",
79                 "<a href=\"m1/module-summary.html\">m1</a>");
80 
81     }
82 
83     //multiple modules with frames
84     @Test
testIndexWithMultipleModules1(Path base)85     public void testIndexWithMultipleModules1(Path base) throws Exception {
86         Path out = base.resolve("out");
87         javadoc("-d", out.toString(),
88                 "--module-source-path", src.toString(),
89                 "--module", "m1,m3,m4");
90 
91         checkExit(Exit.OK);
92 
93         checkOutput("overview-summary.html", true,
94                 "window.location.replace('index.html')");
95         checkOrder("index.html",
96                 "Modules",
97                 "<a href=\"m1/module-summary.html\">m1</a>",
98                 "<a href=\"m3/module-summary.html\">m3</a>",
99                 "<a href=\"m4/module-summary.html\">m4</a>");
100     }
101 
102     //multiple modules with out frames
103     @Test
testIndexWithMultipleModules2(Path base)104     public void testIndexWithMultipleModules2(Path base) throws Exception {
105         Path out = base.resolve("out");
106         javadoc("-d", out.toString(),
107                 "--module-source-path", src.toString(),
108                 "--module", "m1,m3,m4",
109                 "--no-frames");
110 
111         checkExit(Exit.OK);
112         checkOrder("index.html",
113                 "Modules",
114                 "<a href=\"m1/module-summary.html\">m1</a>",
115                 "<a href=\"m3/module-summary.html\">m3</a>",
116                 "<a href=\"m4/module-summary.html\">m4</a>");
117     }
118 
119     @Test
testIndexWithSingleModule(Path base)120     public void testIndexWithSingleModule(Path base) throws Exception {
121         Path out = base.resolve("out");
122         javadoc("-d", out.toString(),
123                 "--module-source-path", src.toString(),
124                 "--module", "m2");
125 
126         checkExit(Exit.OK);
127         checkOutput("index.html", true,
128                 "window.location.replace('m2/module-summary.html')");
129     }
130 
131     //no modules and multiple packages
132     @Test
testIndexWithNoModules1(Path base)133     public void testIndexWithNoModules1(Path base) throws Exception{
134         Path out = base.resolve("out");
135         new ClassBuilder(tb, "P1.A1")
136                 .setModifiers("public","class")
137                 .write(src);
138 
139         new ClassBuilder(tb, "P2.A2")
140                 .setModifiers("public","class")
141                 .write(src);
142 
143         javadoc("-d", out.toString(),
144                 "--no-frames",
145                 "-sourcepath", src.toString(),
146                 "P1","P2");
147 
148         checkExit(Exit.OK);
149         checkOrder("index.html",
150                 "Packages",
151                 "<a href=\"P1/package-summary.html\">P1</a>",
152                 "<a href=\"P2/package-summary.html\">P2</a>");
153 
154     }
155 
156     //no modules and one package
157     @Test
testIndexWithNoModules2(Path base)158     public void testIndexWithNoModules2(Path base) throws Exception{
159         Path out = base.resolve("out");
160         new ClassBuilder(tb, "P1.A1")
161                 .setModifiers("public","class")
162                 .write(src);
163 
164         javadoc("-d", out.toString(),
165                 "--no-frames",
166                 "-sourcepath", src.toString(),
167                 "P1");
168 
169         checkExit(Exit.OK);
170         checkOrder("index.html",
171                 "window.location.replace('P1/package-summary.html')");
172     }
173 
initModules()174     void initModules() throws Exception {
175         new ModuleBuilder(tb, "m1")
176                 .exports("p1")
177                 .classes("package p1; public class c1{}")
178                 .write(src);
179 
180         new ModuleBuilder(tb, "m2")
181                 .exports("p1")
182                 .exports("p2")
183                 .classes("package p1; public class c1{}")
184                 .classes("package p2; public class c2{}")
185                 .write(src);
186 
187         new ModuleBuilder(tb, "m3").write(src);
188 
189         new ModuleBuilder(tb, "m4").write(src);
190     }
191 }
192