Fri, 01 Mar 2013 10:47:39 -0800
8008949: javadoc stopped copying doc-files
Reviewed-by: bpatel
1 /*
2 * Copyright (c) 2003, 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
26 package com.sun.tools.doclets.internal.toolkit;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.builders.*;
30 import com.sun.tools.doclets.internal.toolkit.util.*;
32 /**
33 * An abstract implementation of a Doclet.
34 *
35 * <p><b>This is NOT part of any supported API.
36 * If you write code that depends on this, you do so at your own risk.
37 * This code and its internal interfaces are subject to change or
38 * deletion without notice.</b>
39 *
40 * @author Jamie Ho
41 */
42 public abstract class AbstractDoclet {
44 /**
45 * The global configuration information for this run.
46 */
47 public Configuration configuration;
49 /**
50 * The only doclet that may use this toolkit is {@value}
51 */
52 private static final String TOOLKIT_DOCLET_NAME =
53 com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName();
55 /**
56 * Verify that the only doclet that is using this toolkit is
57 * {@value #TOOLKIT_DOCLET_NAME}.
58 */
59 private boolean isValidDoclet(AbstractDoclet doclet) {
60 if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
61 configuration.message.error("doclet.Toolkit_Usage_Violation",
62 TOOLKIT_DOCLET_NAME);
63 return false;
64 }
65 return true;
66 }
68 /**
69 * The method that starts the execution of the doclet.
70 *
71 * @param doclet the doclet to start the execution for.
72 * @param root the {@link RootDoc} that points to the source to document.
73 * @return true if the doclet executed without error. False otherwise.
74 */
75 public boolean start(AbstractDoclet doclet, RootDoc root) {
76 configuration = configuration();
77 configuration.root = root;
78 if (! isValidDoclet(doclet)) {
79 return false;
80 }
81 try {
82 doclet.startGeneration(root);
83 } catch (Configuration.Fault f) {
84 root.printError(f.getMessage());
85 return false;
86 } catch (Exception exc) {
87 exc.printStackTrace();
88 return false;
89 }
90 return true;
91 }
93 /**
94 * Indicate that this doclet supports the 1.5 language features.
95 * @return JAVA_1_5, indicating that the new features are supported.
96 */
97 public static LanguageVersion languageVersion() {
98 return LanguageVersion.JAVA_1_5;
99 }
102 /**
103 * Create the configuration instance and returns it.
104 * @return the configuration of the doclet.
105 */
106 public abstract Configuration configuration();
108 /**
109 * Start the generation of files. Call generate methods in the individual
110 * writers, which will in turn generate the documentation files. Call the
111 * TreeWriter generation first to ensure the Class Hierarchy is built
112 * first and then can be used in the later generation.
113 *
114 * @see com.sun.javadoc.RootDoc
115 */
116 private void startGeneration(RootDoc root) throws Configuration.Fault, Exception {
117 if (root.classes().length == 0) {
118 configuration.message.
119 error("doclet.No_Public_Classes_To_Document");
120 return;
121 }
122 configuration.setOptions();
123 configuration.getDocletSpecificMsg().notice("doclet.build_version",
124 configuration.getDocletSpecificBuildDate());
125 ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
127 generateClassFiles(root, classtree);
128 Util.copyDocFiles(configuration, DocPaths.DOC_FILES);
130 PackageListWriter.generate(configuration);
131 generatePackageFiles(classtree);
132 generateProfileFiles();
134 generateOtherFiles(root, classtree);
135 configuration.tagletManager.printReport();
136 }
138 /**
139 * Generate additional documentation that is added to the API documentation.
140 *
141 * @param root the RootDoc of source to document.
142 * @param classtree the data structure representing the class tree.
143 */
144 protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
145 BuilderFactory builderFactory = configuration.getBuilderFactory();
146 AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
147 constantsSummaryBuilder.build();
148 AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
149 serializedFormBuilder.build();
150 }
152 /**
153 * Generate the profile documentation.
154 *
155 */
156 protected abstract void generateProfileFiles() throws Exception;
158 /**
159 * Generate the package documentation.
160 *
161 * @param classtree the data structure representing the class tree.
162 */
163 protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
165 /**
166 * Generate the class documentation.
167 *
168 * @param classtree the data structure representing the class tree.
169 */
170 protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
172 /**
173 * Iterate through all classes and construct documentation for them.
174 *
175 * @param root the RootDoc of source to document.
176 * @param classtree the data structure representing the class tree.
177 */
178 protected void generateClassFiles(RootDoc root, ClassTree classtree) {
179 generateClassFiles(classtree);
180 PackageDoc[] packages = root.specifiedPackages();
181 for (int i = 0; i < packages.length; i++) {
182 generateClassFiles(packages[i].allClasses(), classtree);
183 }
184 }
186 /**
187 * Generate the class files for single classes specified on the command line.
188 *
189 * @param classtree the data structure representing the class tree.
190 */
191 private void generateClassFiles(ClassTree classtree) {
192 String[] packageNames = configuration.classDocCatalog.packageNames();
193 for (int packageNameIndex = 0; packageNameIndex < packageNames.length;
194 packageNameIndex++) {
195 generateClassFiles(configuration.classDocCatalog.allClasses(
196 packageNames[packageNameIndex]), classtree);
197 }
198 }
199 }