author | ksrini |
Thu, 18 Aug 2016 05:48:35 -0700 | |
changeset 40508 | 74ef30d16fb9 |
parent 40315 | 9e994c77db6a |
child 40587 | 1c355ea550ed |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
27 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
28 |
import java.util.SortedSet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
29 |
import java.util.TreeSet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
30 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
31 |
import javax.lang.model.SourceVersion; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
32 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
33 |
import javax.lang.model.element.TypeElement; |
10 | 34 |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
35 |
import jdk.javadoc.doclet.Doclet; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
36 |
import jdk.javadoc.doclet.DocletEnvironment; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
42 |
import jdk.javadoc.internal.doclets.toolkit.util.PackageListWriter; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
43 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
44 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
45 |
import static javax.tools.Diagnostic.Kind.*; |
10 | 46 |
|
47 |
/** |
|
48 |
* An abstract implementation of a Doclet. |
|
49 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
50 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
51 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
52 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
53 |
* deletion without notice.</b> |
10 | 54 |
* |
55 |
* @author Jamie Ho |
|
56 |
*/ |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
57 |
public abstract class AbstractDoclet implements Doclet { |
10 | 58 |
|
59 |
/** |
|
60 |
* The global configuration information for this run. |
|
61 |
*/ |
|
40303 | 62 |
private Configuration configuration; |
63 |
||
64 |
protected Messages messages; |
|
65 |
||
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
66 |
/* |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
67 |
* a handle to our utility methods |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
68 |
*/ |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
69 |
protected Utils utils; |
10 | 70 |
|
71 |
/** |
|
72 |
* The only doclet that may use this toolkit is {@value} |
|
73 |
*/ |
|
14542 | 74 |
private static final String TOOLKIT_DOCLET_NAME = |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
75 |
jdk.javadoc.internal.doclets.formats.html.HtmlDoclet.class.getName(); |
10 | 76 |
|
77 |
/** |
|
78 |
* Verify that the only doclet that is using this toolkit is |
|
79 |
* {@value #TOOLKIT_DOCLET_NAME}. |
|
80 |
*/ |
|
26269
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
81 |
private boolean isValidDoclet() { |
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
82 |
if (!getClass().getName().equals(TOOLKIT_DOCLET_NAME)) { |
40303 | 83 |
messages.error("doclet.Toolkit_Usage_Violation", |
10 | 84 |
TOOLKIT_DOCLET_NAME); |
85 |
return false; |
|
86 |
} |
|
87 |
return true; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* The method that starts the execution of the doclet. |
|
92 |
* |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
93 |
* @param docEnv the {@link DocletEnvironment}. |
10 | 94 |
* @return true if the doclet executed without error. False otherwise. |
95 |
*/ |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
96 |
@Override |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
97 |
public boolean run(DocletEnvironment docEnv) { |
1475 | 98 |
configuration = configuration(); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
99 |
configuration.docEnv = docEnv; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
100 |
configuration.cmtUtils = new CommentUtils(configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
101 |
configuration.utils = new Utils(configuration); |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
102 |
utils = configuration.utils; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
103 |
configuration.workArounds = new WorkArounds(configuration); |
40303 | 104 |
messages = configuration.getMessages(); |
105 |
||
26269
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
106 |
if (!isValidDoclet()) { |
10 | 107 |
return false; |
108 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
109 |
|
10 | 110 |
try { |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
111 |
startGeneration(docEnv); |
16324 | 112 |
} catch (Configuration.Fault f) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
113 |
configuration.reporter.print(ERROR, f.getMessage()); |
16324 | 114 |
return false; |
20600
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
115 |
} catch (DocletAbortException e) { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
116 |
Throwable cause = e.getCause(); |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
117 |
if (cause != null) { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
118 |
if (cause.getLocalizedMessage() != null) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
119 |
configuration.reporter.print(ERROR, cause.getLocalizedMessage()); |
20600
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
120 |
} else { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
121 |
configuration.reporter.print(ERROR, cause.toString()); |
20600
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
122 |
} |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
123 |
} |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
124 |
return false; |
10 | 125 |
} catch (Exception exc) { |
40303 | 126 |
exc.printStackTrace(System.err); |
10 | 127 |
return false; |
128 |
} |
|
129 |
return true; |
|
130 |
} |
|
131 |
||
132 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
133 |
* Returns the SourceVersion indicating the features supported by this doclet. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
134 |
* @return SourceVersion |
10 | 135 |
*/ |
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
136 |
@Override |
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
137 |
public SourceVersion getSupportedSourceVersion() { |
39090
10c2cda4358d
8159396: javadoc getSupportedVersion returns 8 instead of 9
ksrini
parents:
36526
diff
changeset
|
138 |
return SourceVersion.RELEASE_9; |
10 | 139 |
} |
140 |
||
141 |
||
142 |
/** |
|
143 |
* Create the configuration instance and returns it. |
|
144 |
* @return the configuration of the doclet. |
|
145 |
*/ |
|
146 |
public abstract Configuration configuration(); |
|
147 |
||
148 |
/** |
|
149 |
* Start the generation of files. Call generate methods in the individual |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
150 |
* writers, which will in turn generate the documentation files. Call the |
10 | 151 |
* TreeWriter generation first to ensure the Class Hierarchy is built |
152 |
* first and then can be used in the later generation. |
|
153 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
154 |
* @see jdk.doclet.DocletEnvironment |
10 | 155 |
*/ |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
156 |
private void startGeneration(DocletEnvironment docEnv) throws Configuration.Fault, Exception { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
157 |
if (docEnv.getIncludedTypeElements().isEmpty()) { |
40303 | 158 |
messages.error("doclet.No_Public_Classes_To_Document"); |
10 | 159 |
return; |
160 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
161 |
if (!configuration.setOptions()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
162 |
return; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
163 |
} |
40303 | 164 |
messages.notice("doclet.build_version", |
10 | 165 |
configuration.getDocletSpecificBuildDate()); |
166 |
ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated); |
|
167 |
||
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
168 |
generateClassFiles(docEnv, classtree); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
169 |
configuration.utils.copyDocFiles(DocPaths.DOC_FILES); |
10 | 170 |
|
171 |
PackageListWriter.generate(configuration); |
|
172 |
generatePackageFiles(classtree); |
|
36526 | 173 |
generateModuleFiles(); |
10 | 174 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
175 |
generateOtherFiles(docEnv, classtree); |
10 | 176 |
configuration.tagletManager.printReport(); |
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Generate additional documentation that is added to the API documentation. |
|
181 |
* |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
182 |
* @param docEnv the DocletEnvironment. |
10 | 183 |
* @param classtree the data structure representing the class tree. |
184 |
*/ |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
185 |
protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree) throws Exception { |
10 | 186 |
BuilderFactory builderFactory = configuration.getBuilderFactory(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
187 |
AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuilder(); |
10 | 188 |
constantsSummaryBuilder.build(); |
189 |
AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); |
|
190 |
serializedFormBuilder.build(); |
|
191 |
} |
|
192 |
||
193 |
/** |
|
36526 | 194 |
* Generate the module documentation. |
195 |
* |
|
196 |
*/ |
|
197 |
protected abstract void generateModuleFiles() throws Exception; |
|
198 |
||
199 |
/** |
|
10 | 200 |
* Generate the package documentation. |
201 |
* |
|
202 |
* @param classtree the data structure representing the class tree. |
|
203 |
*/ |
|
204 |
protected abstract void generatePackageFiles(ClassTree classtree) throws Exception; |
|
205 |
||
206 |
/** |
|
207 |
* Generate the class documentation. |
|
208 |
* |
|
209 |
* @param classtree the data structure representing the class tree. |
|
210 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
211 |
protected abstract void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree); |
10 | 212 |
|
213 |
/** |
|
214 |
* Iterate through all classes and construct documentation for them. |
|
215 |
* |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
216 |
* @param docEnv the DocletEnvironment. |
10 | 217 |
* @param classtree the data structure representing the class tree. |
218 |
*/ |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
219 |
protected void generateClassFiles(DocletEnvironment docEnv, ClassTree classtree) { |
10 | 220 |
generateClassFiles(classtree); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
221 |
SortedSet<PackageElement> packages = new TreeSet<>(utils.makePackageComparator()); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
222 |
packages.addAll(configuration.getSpecifiedPackages()); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
223 |
configuration.modulePackages.values().stream().forEach(pset -> { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
224 |
packages.addAll(pset); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
225 |
}); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
226 |
packages.stream().forEach((pkg) -> { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
227 |
generateClassFiles(utils.getAllClasses(pkg), classtree); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
228 |
}); |
10 | 229 |
} |
230 |
||
231 |
/** |
|
232 |
* Generate the class files for single classes specified on the command line. |
|
233 |
* |
|
234 |
* @param classtree the data structure representing the class tree. |
|
235 |
*/ |
|
236 |
private void generateClassFiles(ClassTree classtree) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
237 |
SortedSet<PackageElement> packages = configuration.typeElementCatalog.packages(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
238 |
packages.stream().forEach((pkg) -> { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
239 |
generateClassFiles(configuration.typeElementCatalog.allClasses(pkg), classtree); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
240 |
}); |
10 | 241 |
} |
242 |
} |