|
1 /* |
|
2 * Copyright (c) 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 8219958 |
|
27 * @summary Automatically load taglets from a jar file |
|
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.* toolbox.ToolBox builder.ClassBuilder toolbox.JarTask |
|
34 * @run main/othervm TestAutoLoadTaglets |
|
35 */ |
|
36 |
|
37 |
|
38 import java.nio.file.Path; |
|
39 import java.nio.file.Paths; |
|
40 |
|
41 import builder.ClassBuilder; |
|
42 import toolbox.JarTask; |
|
43 import toolbox.JavacTask; |
|
44 import toolbox.ToolBox; |
|
45 |
|
46 import javadoc.tester.JavadocTester; |
|
47 |
|
48 public class TestAutoLoadTaglets extends JavadocTester { |
|
49 |
|
50 final ToolBox tb; |
|
51 |
|
52 public static void main(String... args) throws Exception { |
|
53 TestAutoLoadTaglets tester = new TestAutoLoadTaglets(); |
|
54 tester.runTests(m -> new Object[]{Paths.get(m.getName())}); |
|
55 } |
|
56 |
|
57 TestAutoLoadTaglets() { |
|
58 tb = new ToolBox(); |
|
59 } |
|
60 |
|
61 @Test |
|
62 public void test(Path base) throws Exception { |
|
63 Path srcDir = base.resolve("src"); |
|
64 Path outDir = base.resolve("out"); |
|
65 |
|
66 createTagletsJar(base, srcDir); |
|
67 |
|
68 new ClassBuilder(tb, "pkg.A") |
|
69 .setComments("test {@taglet1} and {@taglet2}") |
|
70 .setModifiers("public", "class") |
|
71 .write(srcDir); |
|
72 |
|
73 javadoc("-d", outDir.toString(), |
|
74 "-sourcepath", srcDir.toString(), |
|
75 "-tagletpath", "taglets.jar", |
|
76 "pkg"); |
|
77 |
|
78 checkExit(Exit.OK); |
|
79 |
|
80 checkOutput("pkg/A.html", true, |
|
81 "test user taglet taglet1 and user taglet taglet2"); |
|
82 } |
|
83 |
|
84 private void createTagletsJar(Path base, Path srcDir) throws Exception { |
|
85 Path classes = base.resolve("classes"); |
|
86 tb.createDirectories(classes); |
|
87 createTaglets(srcDir); |
|
88 |
|
89 new JavacTask(tb).files(srcDir.resolve("Taglet1.java"), srcDir.resolve("Taglet2.java")) |
|
90 .outdir(classes).run(); |
|
91 |
|
92 Path services = classes.resolve("META-INF").resolve("services").resolve("jdk.javadoc.doclet.Taglet"); |
|
93 tb.writeFile(services, |
|
94 "Taglet1\n" |
|
95 + "Taglet2"); |
|
96 |
|
97 new JarTask(tb, srcDir).run("cf", "taglets.jar", "-C", classes.toString(), "."); |
|
98 } |
|
99 |
|
100 private void createTaglets(Path srcDir) throws Exception { |
|
101 for (int i = 1; i < 3; i++) { |
|
102 tb.writeJavaFiles(srcDir, |
|
103 "import com.sun.source.doctree.DocTree;\n" |
|
104 + "import jdk.javadoc.doclet.Taglet;\n" |
|
105 + "import javax.lang.model.element.Element;\n" |
|
106 + "import java.util.List;\n" |
|
107 + "import java.util.Set;\n" |
|
108 + "public class Taglet" + i + " implements Taglet {\n" |
|
109 + " @Override\n" |
|
110 + " public Set<Location> getAllowedLocations() {\n" |
|
111 + " return null;\n" |
|
112 + " }\n" |
|
113 + " @Override\n" |
|
114 + " public boolean isInlineTag() {\n" |
|
115 + " return true;\n" |
|
116 + " }\n" |
|
117 + " @Override\n" |
|
118 + " public String getName() {\n" |
|
119 + " return \"taglet" + i + "\";\n" |
|
120 + " }\n" |
|
121 + " @Override\n" |
|
122 + " public String toString(List<? extends DocTree> tags, Element " |
|
123 + "element) {\n" |
|
124 + " return \"user taglet taglet" + i + "\";\n" |
|
125 + " }\n" |
|
126 + "}\n"); |
|
127 } |
|
128 } |
|
129 |
|
130 } |