Tue, 23 Oct 2012 13:20:37 -0700
8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1357 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.internal.toolkit; |
duke@1 | 27 | |
jjg@1357 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.builders.*; |
duke@1 | 30 | import com.sun.tools.doclets.internal.toolkit.util.*; |
jjg@1357 | 31 | import java.io.File; |
jjg@1357 | 32 | import java.util.StringTokenizer; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * An abstract implementation of a Doclet. |
duke@1 | 36 | * |
jjg@1359 | 37 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 38 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 39 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 40 | * deletion without notice.</b> |
duke@1 | 41 | * |
duke@1 | 42 | * @author Jamie Ho |
duke@1 | 43 | */ |
duke@1 | 44 | public abstract class AbstractDoclet { |
duke@1 | 45 | |
duke@1 | 46 | /** |
duke@1 | 47 | * The global configuration information for this run. |
duke@1 | 48 | */ |
jjg@140 | 49 | public Configuration configuration; |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * The only doclet that may use this toolkit is {@value} |
duke@1 | 53 | */ |
duke@1 | 54 | private static final String TOOLKIT_DOCLET_NAME = new |
duke@1 | 55 | com.sun.tools.doclets.formats.html.HtmlDoclet().getClass().getName(); |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * Verify that the only doclet that is using this toolkit is |
duke@1 | 59 | * {@value #TOOLKIT_DOCLET_NAME}. |
duke@1 | 60 | */ |
duke@1 | 61 | private boolean isValidDoclet(AbstractDoclet doclet) { |
duke@1 | 62 | if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) { |
duke@1 | 63 | configuration.message.error("doclet.Toolkit_Usage_Violation", |
duke@1 | 64 | TOOLKIT_DOCLET_NAME); |
duke@1 | 65 | return false; |
duke@1 | 66 | } |
duke@1 | 67 | return true; |
duke@1 | 68 | } |
duke@1 | 69 | |
duke@1 | 70 | /** |
duke@1 | 71 | * The method that starts the execution of the doclet. |
duke@1 | 72 | * |
duke@1 | 73 | * @param doclet the doclet to start the execution for. |
duke@1 | 74 | * @param root the {@link RootDoc} that points to the source to document. |
duke@1 | 75 | * @return true if the doclet executed without error. False otherwise. |
duke@1 | 76 | */ |
duke@1 | 77 | public boolean start(AbstractDoclet doclet, RootDoc root) { |
jjg@140 | 78 | configuration = configuration(); |
duke@1 | 79 | configuration.root = root; |
duke@1 | 80 | if (! isValidDoclet(doclet)) { |
duke@1 | 81 | return false; |
duke@1 | 82 | } |
duke@1 | 83 | try { |
duke@1 | 84 | doclet.startGeneration(root); |
duke@1 | 85 | } catch (Exception exc) { |
duke@1 | 86 | exc.printStackTrace(); |
duke@1 | 87 | return false; |
duke@1 | 88 | } |
duke@1 | 89 | return true; |
duke@1 | 90 | } |
duke@1 | 91 | |
duke@1 | 92 | /** |
duke@1 | 93 | * Indicate that this doclet supports the 1.5 language features. |
duke@1 | 94 | * @return JAVA_1_5, indicating that the new features are supported. |
duke@1 | 95 | */ |
duke@1 | 96 | public static LanguageVersion languageVersion() { |
duke@1 | 97 | return LanguageVersion.JAVA_1_5; |
duke@1 | 98 | } |
duke@1 | 99 | |
duke@1 | 100 | |
duke@1 | 101 | /** |
duke@1 | 102 | * Create the configuration instance and returns it. |
duke@1 | 103 | * @return the configuration of the doclet. |
duke@1 | 104 | */ |
duke@1 | 105 | public abstract Configuration configuration(); |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Start the generation of files. Call generate methods in the individual |
duke@1 | 109 | * writers, which will in turn genrate the documentation files. Call the |
duke@1 | 110 | * TreeWriter generation first to ensure the Class Hierarchy is built |
duke@1 | 111 | * first and then can be used in the later generation. |
duke@1 | 112 | * |
duke@1 | 113 | * @see com.sun.javadoc.RootDoc |
duke@1 | 114 | */ |
duke@1 | 115 | private void startGeneration(RootDoc root) throws Exception { |
duke@1 | 116 | if (root.classes().length == 0) { |
duke@1 | 117 | configuration.message. |
duke@1 | 118 | error("doclet.No_Public_Classes_To_Document"); |
duke@1 | 119 | return; |
duke@1 | 120 | } |
duke@1 | 121 | configuration.setOptions(); |
duke@1 | 122 | configuration.getDocletSpecificMsg().notice("doclet.build_version", |
duke@1 | 123 | configuration.getDocletSpecificBuildDate()); |
duke@1 | 124 | ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated); |
duke@1 | 125 | |
duke@1 | 126 | generateClassFiles(root, classtree); |
duke@1 | 127 | if (configuration.sourcepath != null && configuration.sourcepath.length() > 0) { |
duke@1 | 128 | StringTokenizer pathTokens = new StringTokenizer(configuration.sourcepath, |
duke@1 | 129 | String.valueOf(File.pathSeparatorChar)); |
duke@1 | 130 | boolean first = true; |
duke@1 | 131 | while(pathTokens.hasMoreTokens()){ |
duke@1 | 132 | Util.copyDocFiles(configuration, |
jjg@1372 | 133 | new File(pathTokens.nextToken()), |
jjg@1372 | 134 | DocPaths.DOC_FILES, first); |
duke@1 | 135 | first = false; |
duke@1 | 136 | } |
duke@1 | 137 | } |
duke@1 | 138 | |
duke@1 | 139 | PackageListWriter.generate(configuration); |
duke@1 | 140 | generatePackageFiles(classtree); |
duke@1 | 141 | |
duke@1 | 142 | generateOtherFiles(root, classtree); |
duke@1 | 143 | configuration.tagletManager.printReport(); |
duke@1 | 144 | } |
duke@1 | 145 | |
duke@1 | 146 | /** |
duke@1 | 147 | * Generate additional documentation that is added to the API documentation. |
duke@1 | 148 | * |
duke@1 | 149 | * @param root the RootDoc of source to document. |
duke@1 | 150 | * @param classtree the data structure representing the class tree. |
duke@1 | 151 | */ |
duke@1 | 152 | protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception { |
duke@1 | 153 | BuilderFactory builderFactory = configuration.getBuilderFactory(); |
duke@1 | 154 | AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider(); |
duke@1 | 155 | constantsSummaryBuilder.build(); |
duke@1 | 156 | AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); |
duke@1 | 157 | serializedFormBuilder.build(); |
duke@1 | 158 | } |
duke@1 | 159 | |
duke@1 | 160 | /** |
duke@1 | 161 | * Generate the package documentation. |
duke@1 | 162 | * |
duke@1 | 163 | * @param classtree the data structure representing the class tree. |
duke@1 | 164 | */ |
duke@1 | 165 | protected abstract void generatePackageFiles(ClassTree classtree) throws Exception; |
duke@1 | 166 | |
duke@1 | 167 | /** |
duke@1 | 168 | * Generate the class documentation. |
duke@1 | 169 | * |
duke@1 | 170 | * @param classtree the data structure representing the class tree. |
duke@1 | 171 | */ |
duke@1 | 172 | protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree); |
duke@1 | 173 | |
duke@1 | 174 | /** |
duke@1 | 175 | * Iterate through all classes and construct documentation for them. |
duke@1 | 176 | * |
duke@1 | 177 | * @param root the RootDoc of source to document. |
duke@1 | 178 | * @param classtree the data structure representing the class tree. |
duke@1 | 179 | */ |
duke@1 | 180 | protected void generateClassFiles(RootDoc root, ClassTree classtree) { |
duke@1 | 181 | generateClassFiles(classtree); |
duke@1 | 182 | PackageDoc[] packages = root.specifiedPackages(); |
duke@1 | 183 | for (int i = 0; i < packages.length; i++) { |
duke@1 | 184 | generateClassFiles(packages[i].allClasses(), classtree); |
duke@1 | 185 | } |
duke@1 | 186 | } |
duke@1 | 187 | |
duke@1 | 188 | /** |
duke@1 | 189 | * Generate the class files for single classes specified on the command line. |
duke@1 | 190 | * |
duke@1 | 191 | * @param classtree the data structure representing the class tree. |
duke@1 | 192 | */ |
duke@1 | 193 | private void generateClassFiles(ClassTree classtree) { |
duke@1 | 194 | String[] packageNames = configuration.classDocCatalog.packageNames(); |
duke@1 | 195 | for (int packageNameIndex = 0; packageNameIndex < packageNames.length; |
duke@1 | 196 | packageNameIndex++) { |
duke@1 | 197 | generateClassFiles(configuration.classDocCatalog.allClasses( |
duke@1 | 198 | packageNames[packageNameIndex]), classtree); |
duke@1 | 199 | } |
duke@1 | 200 | } |
duke@1 | 201 | } |