author | bpatel |
Mon, 19 Nov 2012 16:10:34 -0800 | |
changeset 14549 | 0599d73bf1da |
parent 14542 | 7062120649c2 |
child 15723 | 58a73dac9ee4 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14258 | 2 |
* Copyright (c) 1997, 2012, 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 |
package com.sun.tools.doclets.formats.html; |
|
26 |
||
14258 | 27 |
import java.io.*; |
28 |
import java.util.*; |
|
29 |
||
30 |
import com.sun.javadoc.*; |
|
10 | 31 |
import com.sun.tools.doclets.internal.toolkit.*; |
32 |
import com.sun.tools.doclets.internal.toolkit.builders.*; |
|
33 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
34 |
||
35 |
/** |
|
36 |
* The class with "start" method, calls individual Writers. |
|
37 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
38 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
39 |
* 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
|
40 |
* 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
|
41 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
42 |
* |
10 | 43 |
* @author Atul M Dambalkar |
44 |
* @author Robert Field |
|
45 |
* @author Jamie Ho |
|
46 |
* |
|
47 |
*/ |
|
48 |
public class HtmlDoclet extends AbstractDoclet { |
|
14542 | 49 |
// An instance will be created by validOptions, and used by start. |
50 |
private static HtmlDoclet docletToStart = null; |
|
51 |
||
1475 | 52 |
public HtmlDoclet() { |
14542 | 53 |
configuration = new ConfigurationImpl(); |
1475 | 54 |
} |
10 | 55 |
|
56 |
/** |
|
57 |
* The global configuration information for this run. |
|
58 |
*/ |
|
14542 | 59 |
public final ConfigurationImpl configuration; |
10 | 60 |
|
61 |
/** |
|
62 |
* The "start" method as required by Javadoc. |
|
63 |
* |
|
64 |
* @param root the root of the documentation tree. |
|
65 |
* @see com.sun.javadoc.RootDoc |
|
66 |
* @return true if the doclet ran without encountering any errors. |
|
67 |
*/ |
|
68 |
public static boolean start(RootDoc root) { |
|
14542 | 69 |
// In typical use, options will have been set up by calling validOptions, |
70 |
// which will create an HtmlDoclet for use here. |
|
71 |
HtmlDoclet doclet; |
|
72 |
if (docletToStart != null) { |
|
73 |
doclet = docletToStart; |
|
74 |
docletToStart = null; |
|
75 |
} else { |
|
76 |
doclet = new HtmlDoclet(); |
|
1475 | 77 |
} |
14542 | 78 |
return doclet.start(doclet, root); |
10 | 79 |
} |
80 |
||
81 |
/** |
|
82 |
* Create the configuration instance. |
|
83 |
* Override this method to use a different |
|
84 |
* configuration. |
|
85 |
*/ |
|
86 |
public Configuration configuration() { |
|
14542 | 87 |
return configuration; |
10 | 88 |
} |
89 |
||
90 |
/** |
|
91 |
* Start the generation of files. Call generate methods in the individual |
|
92 |
* writers, which will in turn genrate the documentation files. Call the |
|
93 |
* TreeWriter generation first to ensure the Class Hierarchy is built |
|
94 |
* first and then can be used in the later generation. |
|
95 |
* |
|
96 |
* For new format. |
|
97 |
* |
|
98 |
* @see com.sun.javadoc.RootDoc |
|
99 |
*/ |
|
100 |
protected void generateOtherFiles(RootDoc root, ClassTree classtree) |
|
101 |
throws Exception { |
|
102 |
super.generateOtherFiles(root, classtree); |
|
103 |
if (configuration.linksource) { |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
104 |
SourceToHTMLConverter.convertRoot(configuration, |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
105 |
root, DocPaths.SOURCE_OUTPUT); |
10 | 106 |
} |
107 |
||
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
108 |
if (configuration.topFile.isEmpty()) { |
10 | 109 |
configuration.standardmessage. |
110 |
error("doclet.No_Non_Deprecated_Classes_To_Document"); |
|
111 |
return; |
|
112 |
} |
|
113 |
boolean nodeprecated = configuration.nodeprecated; |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
114 |
performCopy(configuration.helpfile); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
115 |
performCopy(configuration.stylesheetfile); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
116 |
copyResourceFile("background.gif"); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
117 |
copyResourceFile("tab.gif"); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
118 |
copyResourceFile("titlebar.gif"); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
119 |
copyResourceFile("titlebar_end.gif"); |
14549
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
120 |
copyResourceFile("activetitlebar.gif"); |
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
121 |
copyResourceFile("activetitlebar_end.gif"); |
10 | 122 |
// do early to reduce memory footprint |
123 |
if (configuration.classuse) { |
|
124 |
ClassUseWriter.generate(configuration, classtree); |
|
125 |
} |
|
126 |
IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated); |
|
127 |
||
128 |
if (configuration.createtree) { |
|
129 |
TreeWriter.generate(configuration, classtree); |
|
130 |
} |
|
131 |
if (configuration.createindex) { |
|
132 |
if (configuration.splitindex) { |
|
133 |
SplitIndexWriter.generate(configuration, indexbuilder); |
|
134 |
} else { |
|
135 |
SingleIndexWriter.generate(configuration, indexbuilder); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
if (!(configuration.nodeprecatedlist || nodeprecated)) { |
|
140 |
DeprecatedListWriter.generate(configuration); |
|
141 |
} |
|
142 |
||
143 |
AllClassesFrameWriter.generate(configuration, |
|
144 |
new IndexBuilder(configuration, nodeprecated, true)); |
|
145 |
||
146 |
FrameOutputWriter.generate(configuration); |
|
147 |
||
148 |
if (configuration.createoverview) { |
|
149 |
PackageIndexWriter.generate(configuration); |
|
150 |
} |
|
151 |
if (configuration.helpfile.length() == 0 && |
|
152 |
!configuration.nohelp) { |
|
153 |
HelpWriter.generate(configuration); |
|
154 |
} |
|
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
155 |
// If a stylesheet file is not specified, copy the default stylesheet |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
156 |
// and replace newline with platform-specific newline. |
14549
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
157 |
DocFile f; |
10 | 158 |
if (configuration.stylesheetfile.length() == 0) { |
14549
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
159 |
f = DocFile.createFileForOutput(configuration, DocPaths.STYLESHEET); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
160 |
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.STYLESHEET), false, true); |
10 | 161 |
} |
14549
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
162 |
f = DocFile.createFileForOutput(configuration, DocPaths.JAVASCRIPT); |
0599d73bf1da
8002304: Group methods by types in methods summary section
bpatel
parents:
14542
diff
changeset
|
163 |
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.JAVASCRIPT), true, true); |
10 | 164 |
} |
165 |
||
166 |
/** |
|
167 |
* {@inheritDoc} |
|
168 |
*/ |
|
169 |
protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) { |
|
170 |
Arrays.sort(arr); |
|
171 |
for(int i = 0; i < arr.length; i++) { |
|
172 |
if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) { |
|
173 |
continue; |
|
174 |
} |
|
175 |
ClassDoc prev = (i == 0)? |
|
176 |
null: |
|
177 |
arr[i-1]; |
|
178 |
ClassDoc curr = arr[i]; |
|
179 |
ClassDoc next = (i+1 == arr.length)? |
|
180 |
null: |
|
181 |
arr[i+1]; |
|
182 |
try { |
|
183 |
if (curr.isAnnotationType()) { |
|
184 |
AbstractBuilder annotationTypeBuilder = |
|
185 |
configuration.getBuilderFactory() |
|
186 |
.getAnnotationTypeBuilder((AnnotationTypeDoc) curr, |
|
187 |
prev, next); |
|
188 |
annotationTypeBuilder.build(); |
|
189 |
} else { |
|
190 |
AbstractBuilder classBuilder = |
|
191 |
configuration.getBuilderFactory() |
|
192 |
.getClassBuilder(curr, prev, next, classtree); |
|
193 |
classBuilder.build(); |
|
194 |
} |
|
195 |
} catch (Exception e) { |
|
196 |
e.printStackTrace(); |
|
197 |
throw new DocletAbortException(); |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* {@inheritDoc} |
|
204 |
*/ |
|
205 |
protected void generatePackageFiles(ClassTree classtree) throws Exception { |
|
206 |
PackageDoc[] packages = configuration.packages; |
|
207 |
if (packages.length > 1) { |
|
208 |
PackageIndexFrameWriter.generate(configuration); |
|
209 |
} |
|
210 |
PackageDoc prev = null, next; |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
211 |
for (int i = 0; i < packages.length; i++) { |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
212 |
// if -nodeprecated option is set and the package is marked as |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
213 |
// deprecated, do not generate the package-summary.html, package-frame.html |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
214 |
// and package-tree.html pages for that package. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
215 |
if (!(configuration.nodeprecated && Util.isDeprecated(packages[i]))) { |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
216 |
PackageFrameWriter.generate(configuration, packages[i]); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
217 |
next = (i + 1 < packages.length && |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
218 |
packages[i + 1].name().length() > 0) ? packages[i + 1] : null; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
219 |
//If the next package is unnamed package, skip 2 ahead if possible |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
220 |
next = (i + 2 < packages.length && next == null) ? packages[i + 2] : next; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
221 |
AbstractBuilder packageSummaryBuilder = |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
222 |
configuration.getBuilderFactory().getPackageSummaryBuilder( |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
223 |
packages[i], prev, next); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
224 |
packageSummaryBuilder.build(); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
225 |
if (configuration.createtree) { |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
226 |
PackageTreeWriter.generate(configuration, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
227 |
packages[i], prev, next, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
228 |
configuration.nodeprecated); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
229 |
} |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
230 |
prev = packages[i]; |
10 | 231 |
} |
232 |
} |
|
233 |
} |
|
234 |
||
14542 | 235 |
public static final ConfigurationImpl sharedInstanceForOptions = |
236 |
new ConfigurationImpl(); |
|
237 |
||
10 | 238 |
/** |
239 |
* Check for doclet added options here. |
|
240 |
* |
|
241 |
* @return number of arguments to option. Zero return means |
|
242 |
* option not known. Negative value means error occurred. |
|
243 |
*/ |
|
244 |
public static int optionLength(String option) { |
|
245 |
// Construct temporary configuration for check |
|
14542 | 246 |
return sharedInstanceForOptions.optionLength(option); |
10 | 247 |
} |
248 |
||
249 |
/** |
|
250 |
* Check that options have the correct arguments here. |
|
251 |
* <P> |
|
252 |
* This method is not required and will default gracefully |
|
253 |
* (to true) if absent. |
|
254 |
* <P> |
|
255 |
* Printing option related error messages (using the provided |
|
256 |
* DocErrorReporter) is the responsibility of this method. |
|
257 |
* |
|
258 |
* @return true if the options are valid. |
|
259 |
*/ |
|
260 |
public static boolean validOptions(String options[][], |
|
261 |
DocErrorReporter reporter) { |
|
14542 | 262 |
docletToStart = new HtmlDoclet(); |
263 |
return docletToStart.configuration.validOptions(options, reporter); |
|
10 | 264 |
} |
265 |
||
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
266 |
/** |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
267 |
* Copy a file in the resources directory to the destination directory. |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
268 |
* @param resource The name of the resource file to copy |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
269 |
*/ |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
270 |
private void copyResourceFile(String resource) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
271 |
DocPath p = DocPaths.RESOURCES.resolve(resource); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
272 |
DocFile f = DocFile.createFileForOutput(configuration, p); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
273 |
f.copyResource(p, false, false); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
274 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
275 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
276 |
private void performCopy(String filename) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
277 |
if (filename.isEmpty()) |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
278 |
return; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
279 |
|
10 | 280 |
try { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
281 |
DocFile fromfile = DocFile.createFileForInput(configuration, filename); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
282 |
DocPath path = DocPath.create(fromfile.getName()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
283 |
DocFile toFile = DocFile.createFileForOutput(configuration, path); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
284 |
if (toFile.isSameFile(fromfile)) |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
285 |
return; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
286 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
287 |
configuration.message.notice((SourcePosition) null, |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
288 |
"doclet.Copying_File_0_To_File_1", |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
289 |
fromfile.toString(), path.getPath()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
290 |
toFile.copyFile(fromfile); |
10 | 291 |
} catch (IOException exc) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
292 |
configuration.message.error((SourcePosition) null, |
10 | 293 |
"doclet.perform_copy_exception_encountered", |
294 |
exc.toString()); |
|
295 |
throw new DocletAbortException(); |
|
296 |
} |
|
297 |
} |
|
298 |
} |