1 /*
2  * Copyright (c) 2016, 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 8157611
27  * @summary test DocTrees is working correctly relative to HTML access
28  * @modules
29  *      jdk.javadoc/jdk.javadoc.internal.api
30  *      jdk.javadoc/jdk.javadoc.internal.tool
31  *      jdk.compiler/com.sun.tools.javac.api
32  *      jdk.compiler/com.sun.tools.javac.main
33  * @library /tools/lib
34  * @build toolbox.ToolBox toolbox.TestRunner
35  * @run main TestDocTrees
36  */
37 
38 import java.io.File;
39 import java.io.IOException;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 
43 import toolbox.*;
44 import toolbox.Task.Expect;
45 
46 import static toolbox.Task.OutputKind.*;
47 
48 /**
49  * This class is used to test DocTrees functionality relating to
50  * package and overview HTML files.
51  */
52 public class TestDocTrees extends TestRunner {
53     final ToolBox tb;
54     final File testFile;
55     final File testSrc;
56     final File overviewFile;
57 
TestDocTrees()58     TestDocTrees() throws IOException {
59         super(System.err);
60         tb = new ToolBox();
61         testSrc = new File(System.getProperty("test.src"));
62         testFile = new File(testSrc, "TestDocTrees.java");
63         overviewFile = new File(testSrc, "overview.html");
64     }
65 
runTests()66     protected void runTests() throws Exception {
67         runTests(m -> new Object[]{Paths.get(m.getName())});
68     }
69 
main(String... args)70     public static void main(String... args) throws Exception {
71         new TestDocTrees().runTests();
72     }
73 
74     @Test
testOverviewWithRelease8(Path out)75     public void testOverviewWithRelease8(Path out) {
76         execTask("-d", out.toString(),
77                 "--release", "8",
78                 "-Xdoclint:all",
79                 "-Xdoclint:-missing",
80                 "-sourcepath", testSrc.getAbsolutePath(),
81                 testFile.getAbsolutePath(),
82                 "-overview", overviewFile.getAbsolutePath());
83     }
84 
85     @Test
testOverviewWithoutRelease(Path out)86     public void testOverviewWithoutRelease(Path out) throws Exception {
87         execTask("-d", out.toString(),
88                 "-Xdoclint:all",
89                 "-Xdoclint:-missing",
90                 "-sourcepath", testSrc.getAbsolutePath(),
91                 testFile.getAbsolutePath(),
92                 "-overview", overviewFile.getAbsolutePath());
93     }
94 
execTask(String... args)95     private Task.Result execTask(String... args) {
96         JavadocTask et = new JavadocTask(tb, Task.Mode.CMDLINE);
97         //args.forEach((a -> System.err.println("arg: " + a)));
98         return et.options(args).run();
99     }
100 }
101