author | pmuthuswamy |
Wed, 20 Mar 2019 09:58:12 +0530 | |
changeset 54198 | 6ba98ff89499 |
permissions | -rw-r--r-- |
54198
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
1 |
/* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
4 |
* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
8 |
* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
13 |
* accompanied this code). |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
14 |
* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
18 |
* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
21 |
* questions. |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
22 |
*/ |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
23 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
24 |
/* |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
25 |
* @test |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
26 |
* @bug 8219958 |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
27 |
* @summary Automatically load taglets from a jar file |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
28 |
* @library /tools/lib ../../lib |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
29 |
* @modules |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
30 |
* jdk.javadoc/jdk.javadoc.internal.tool |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.api |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
33 |
* @build javadoc.tester.* toolbox.ToolBox builder.ClassBuilder toolbox.JarTask |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
34 |
* @run main/othervm TestAutoLoadTaglets |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
35 |
*/ |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
36 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
37 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
38 |
import java.nio.file.Path; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
39 |
import java.nio.file.Paths; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
40 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
41 |
import builder.ClassBuilder; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
42 |
import toolbox.JarTask; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
43 |
import toolbox.JavacTask; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
44 |
import toolbox.ToolBox; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
45 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
46 |
import javadoc.tester.JavadocTester; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
47 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
48 |
public class TestAutoLoadTaglets extends JavadocTester { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
49 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
50 |
final ToolBox tb; |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
51 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
52 |
public static void main(String... args) throws Exception { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
53 |
TestAutoLoadTaglets tester = new TestAutoLoadTaglets(); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
54 |
tester.runTests(m -> new Object[]{Paths.get(m.getName())}); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
55 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
56 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
57 |
TestAutoLoadTaglets() { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
58 |
tb = new ToolBox(); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
59 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
60 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
61 |
@Test |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
62 |
public void test(Path base) throws Exception { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
63 |
Path srcDir = base.resolve("src"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
64 |
Path outDir = base.resolve("out"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
65 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
66 |
createTagletsJar(base, srcDir); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
67 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
68 |
new ClassBuilder(tb, "pkg.A") |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
69 |
.setComments("test {@taglet1} and {@taglet2}") |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
70 |
.setModifiers("public", "class") |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
71 |
.write(srcDir); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
72 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
73 |
javadoc("-d", outDir.toString(), |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
74 |
"-sourcepath", srcDir.toString(), |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
75 |
"-tagletpath", "taglets.jar", |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
76 |
"pkg"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
77 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
78 |
checkExit(Exit.OK); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
79 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
80 |
checkOutput("pkg/A.html", true, |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
81 |
"test user taglet taglet1 and user taglet taglet2"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
82 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
83 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
84 |
private void createTagletsJar(Path base, Path srcDir) throws Exception { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
85 |
Path classes = base.resolve("classes"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
86 |
tb.createDirectories(classes); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
87 |
createTaglets(srcDir); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
88 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
89 |
new JavacTask(tb).files(srcDir.resolve("Taglet1.java"), srcDir.resolve("Taglet2.java")) |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
90 |
.outdir(classes).run(); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
91 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
92 |
Path services = classes.resolve("META-INF").resolve("services").resolve("jdk.javadoc.doclet.Taglet"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
93 |
tb.writeFile(services, |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
94 |
"Taglet1\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
95 |
+ "Taglet2"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
96 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
97 |
new JarTask(tb, srcDir).run("cf", "taglets.jar", "-C", classes.toString(), "."); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
98 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
99 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
100 |
private void createTaglets(Path srcDir) throws Exception { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
101 |
for (int i = 1; i < 3; i++) { |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
102 |
tb.writeJavaFiles(srcDir, |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
103 |
"import com.sun.source.doctree.DocTree;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
104 |
+ "import jdk.javadoc.doclet.Taglet;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
105 |
+ "import javax.lang.model.element.Element;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
106 |
+ "import java.util.List;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
107 |
+ "import java.util.Set;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
108 |
+ "public class Taglet" + i + " implements Taglet {\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
109 |
+ " @Override\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
110 |
+ " public Set<Location> getAllowedLocations() {\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
111 |
+ " return null;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
112 |
+ " }\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
113 |
+ " @Override\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
114 |
+ " public boolean isInlineTag() {\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
115 |
+ " return true;\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
116 |
+ " }\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
117 |
+ " @Override\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
118 |
+ " public String getName() {\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
119 |
+ " return \"taglet" + i + "\";\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
120 |
+ " }\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
121 |
+ " @Override\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
122 |
+ " public String toString(List<? extends DocTree> tags, Element " |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
123 |
+ "element) {\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
124 |
+ " return \"user taglet taglet" + i + "\";\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
125 |
+ " }\n" |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
126 |
+ "}\n"); |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
127 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
128 |
} |
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
129 |
|
6ba98ff89499
8219958: Automatically load taglets from a jar file
pmuthuswamy
parents:
diff
changeset
|
130 |
} |