10
|
1 |
/*
|
5520
|
2 |
* Copyright (c) 2003, 2008, 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 |
|
|
26 |
package com.sun.tools.doclets.internal.toolkit;
|
|
27 |
|
|
28 |
import com.sun.tools.doclets.internal.toolkit.builders.*;
|
|
29 |
import com.sun.tools.doclets.internal.toolkit.util.*;
|
|
30 |
import com.sun.javadoc.*;
|
|
31 |
import java.util.*;
|
|
32 |
import java.io.*;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* An abstract implementation of a Doclet.
|
|
36 |
*
|
|
37 |
* This code is not part of an API.
|
|
38 |
* It is implementation that is subject to change.
|
|
39 |
* Do not use it as an API.
|
|
40 |
*
|
|
41 |
* @author Jamie Ho
|
|
42 |
*/
|
|
43 |
public abstract class AbstractDoclet {
|
|
44 |
|
|
45 |
/**
|
|
46 |
* The global configuration information for this run.
|
|
47 |
*/
|
1475
|
48 |
public Configuration configuration;
|
10
|
49 |
|
|
50 |
/**
|
|
51 |
* The only doclet that may use this toolkit is {@value}
|
|
52 |
*/
|
|
53 |
private static final String TOOLKIT_DOCLET_NAME = new
|
|
54 |
com.sun.tools.doclets.formats.html.HtmlDoclet().getClass().getName();
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Verify that the only doclet that is using this toolkit is
|
|
58 |
* {@value #TOOLKIT_DOCLET_NAME}.
|
|
59 |
*/
|
|
60 |
private boolean isValidDoclet(AbstractDoclet doclet) {
|
|
61 |
if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
|
|
62 |
configuration.message.error("doclet.Toolkit_Usage_Violation",
|
|
63 |
TOOLKIT_DOCLET_NAME);
|
|
64 |
return false;
|
|
65 |
}
|
|
66 |
return true;
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* The method that starts the execution of the doclet.
|
|
71 |
*
|
|
72 |
* @param doclet the doclet to start the execution for.
|
|
73 |
* @param root the {@link RootDoc} that points to the source to document.
|
|
74 |
* @return true if the doclet executed without error. False otherwise.
|
|
75 |
*/
|
|
76 |
public boolean start(AbstractDoclet doclet, RootDoc root) {
|
1475
|
77 |
configuration = configuration();
|
10
|
78 |
configuration.root = root;
|
|
79 |
if (! isValidDoclet(doclet)) {
|
|
80 |
return false;
|
|
81 |
}
|
|
82 |
try {
|
|
83 |
doclet.startGeneration(root);
|
|
84 |
} catch (Exception exc) {
|
|
85 |
exc.printStackTrace();
|
|
86 |
return false;
|
|
87 |
}
|
|
88 |
return true;
|
|
89 |
}
|
|
90 |
|
|
91 |
/**
|
|
92 |
* Indicate that this doclet supports the 1.5 language features.
|
|
93 |
* @return JAVA_1_5, indicating that the new features are supported.
|
|
94 |
*/
|
|
95 |
public static LanguageVersion languageVersion() {
|
|
96 |
return LanguageVersion.JAVA_1_5;
|
|
97 |
}
|
|
98 |
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Create the configuration instance and returns it.
|
|
102 |
* @return the configuration of the doclet.
|
|
103 |
*/
|
|
104 |
public abstract Configuration configuration();
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Start the generation of files. Call generate methods in the individual
|
|
108 |
* writers, which will in turn genrate the documentation files. Call the
|
|
109 |
* TreeWriter generation first to ensure the Class Hierarchy is built
|
|
110 |
* first and then can be used in the later generation.
|
|
111 |
*
|
|
112 |
* @see com.sun.javadoc.RootDoc
|
|
113 |
*/
|
|
114 |
private void startGeneration(RootDoc root) throws Exception {
|
|
115 |
if (root.classes().length == 0) {
|
|
116 |
configuration.message.
|
|
117 |
error("doclet.No_Public_Classes_To_Document");
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
configuration.setOptions();
|
|
121 |
configuration.getDocletSpecificMsg().notice("doclet.build_version",
|
|
122 |
configuration.getDocletSpecificBuildDate());
|
|
123 |
ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
|
|
124 |
|
|
125 |
generateClassFiles(root, classtree);
|
|
126 |
if (configuration.sourcepath != null && configuration.sourcepath.length() > 0) {
|
|
127 |
StringTokenizer pathTokens = new StringTokenizer(configuration.sourcepath,
|
|
128 |
String.valueOf(File.pathSeparatorChar));
|
|
129 |
boolean first = true;
|
|
130 |
while(pathTokens.hasMoreTokens()){
|
|
131 |
Util.copyDocFiles(configuration,
|
|
132 |
pathTokens.nextToken() + File.separator,
|
|
133 |
DocletConstants.DOC_FILES_DIR_NAME, first);
|
|
134 |
first = false;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
PackageListWriter.generate(configuration);
|
|
139 |
generatePackageFiles(classtree);
|
|
140 |
|
|
141 |
generateOtherFiles(root, classtree);
|
|
142 |
configuration.tagletManager.printReport();
|
|
143 |
}
|
|
144 |
|
|
145 |
/**
|
|
146 |
* Generate additional documentation that is added to the API documentation.
|
|
147 |
*
|
|
148 |
* @param root the RootDoc of source to document.
|
|
149 |
* @param classtree the data structure representing the class tree.
|
|
150 |
*/
|
|
151 |
protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
|
|
152 |
BuilderFactory builderFactory = configuration.getBuilderFactory();
|
|
153 |
AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
|
|
154 |
constantsSummaryBuilder.build();
|
|
155 |
AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
|
|
156 |
serializedFormBuilder.build();
|
|
157 |
}
|
|
158 |
|
|
159 |
/**
|
|
160 |
* Generate the package documentation.
|
|
161 |
*
|
|
162 |
* @param classtree the data structure representing the class tree.
|
|
163 |
*/
|
|
164 |
protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Generate the class documentation.
|
|
168 |
*
|
|
169 |
* @param classtree the data structure representing the class tree.
|
|
170 |
*/
|
|
171 |
protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Iterate through all classes and construct documentation for them.
|
|
175 |
*
|
|
176 |
* @param root the RootDoc of source to document.
|
|
177 |
* @param classtree the data structure representing the class tree.
|
|
178 |
*/
|
|
179 |
protected void generateClassFiles(RootDoc root, ClassTree classtree) {
|
|
180 |
generateClassFiles(classtree);
|
|
181 |
PackageDoc[] packages = root.specifiedPackages();
|
|
182 |
for (int i = 0; i < packages.length; i++) {
|
|
183 |
generateClassFiles(packages[i].allClasses(), classtree);
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Generate the class files for single classes specified on the command line.
|
|
189 |
*
|
|
190 |
* @param classtree the data structure representing the class tree.
|
|
191 |
*/
|
|
192 |
private void generateClassFiles(ClassTree classtree) {
|
|
193 |
String[] packageNames = configuration.classDocCatalog.packageNames();
|
|
194 |
for (int packageNameIndex = 0; packageNameIndex < packageNames.length;
|
|
195 |
packageNameIndex++) {
|
|
196 |
generateClassFiles(configuration.classDocCatalog.allClasses(
|
|
197 |
packageNames[packageNameIndex]), classtree);
|
|
198 |
}
|
|
199 |
}
|
|
200 |
}
|