src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 1033
7eba9df190ae
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

duke@1 1 /*
jjg@1357 2 * Copyright (c) 1997, 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 package com.sun.tools.doclets.formats.html;
duke@1 26
jjg@1357 27 import java.io.*;
jjg@1357 28 import java.util.*;
jjg@1357 29
jjg@1357 30 import com.sun.javadoc.*;
duke@1 31 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.builders.*;
duke@1 33 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 34
duke@1 35 /**
duke@1 36 * The class with "start" method, calls individual Writers.
duke@1 37 *
duke@1 38 * @author Atul M Dambalkar
duke@1 39 * @author Robert Field
duke@1 40 * @author Jamie Ho
duke@1 41 *
duke@1 42 */
duke@1 43 public class HtmlDoclet extends AbstractDoclet {
jjg@140 44 public HtmlDoclet() {
jjg@140 45 configuration = (ConfigurationImpl) configuration();
jjg@140 46 }
duke@1 47
duke@1 48 /**
duke@1 49 * The global configuration information for this run.
duke@1 50 */
jjg@140 51 public ConfigurationImpl configuration;
duke@1 52
duke@1 53 /**
duke@1 54 * The "start" method as required by Javadoc.
duke@1 55 *
duke@1 56 * @param root the root of the documentation tree.
duke@1 57 * @see com.sun.javadoc.RootDoc
duke@1 58 * @return true if the doclet ran without encountering any errors.
duke@1 59 */
duke@1 60 public static boolean start(RootDoc root) {
jjg@140 61 try {
jjg@140 62 HtmlDoclet doclet = new HtmlDoclet();
jjg@140 63 return doclet.start(doclet, root);
jjg@140 64 } finally {
jjg@140 65 ConfigurationImpl.reset();
jjg@140 66 }
duke@1 67 }
duke@1 68
duke@1 69 /**
duke@1 70 * Create the configuration instance.
duke@1 71 * Override this method to use a different
duke@1 72 * configuration.
duke@1 73 */
duke@1 74 public Configuration configuration() {
duke@1 75 return ConfigurationImpl.getInstance();
duke@1 76 }
duke@1 77
duke@1 78 /**
duke@1 79 * Start the generation of files. Call generate methods in the individual
duke@1 80 * writers, which will in turn genrate the documentation files. Call the
duke@1 81 * TreeWriter generation first to ensure the Class Hierarchy is built
duke@1 82 * first and then can be used in the later generation.
duke@1 83 *
duke@1 84 * For new format.
duke@1 85 *
duke@1 86 * @see com.sun.javadoc.RootDoc
duke@1 87 */
duke@1 88 protected void generateOtherFiles(RootDoc root, ClassTree classtree)
duke@1 89 throws Exception {
duke@1 90 super.generateOtherFiles(root, classtree);
duke@1 91 if (configuration.linksource) {
duke@1 92 if (configuration.destDirName.length() > 0) {
duke@1 93 SourceToHTMLConverter.convertRoot(configuration,
duke@1 94 root, configuration.destDirName + File.separator
duke@1 95 + DocletConstants.SOURCE_OUTPUT_DIR_NAME);
duke@1 96 } else {
duke@1 97 SourceToHTMLConverter.convertRoot(configuration,
duke@1 98 root, DocletConstants.SOURCE_OUTPUT_DIR_NAME);
duke@1 99 }
duke@1 100 }
duke@1 101
duke@1 102 if (configuration.topFile.length() == 0) {
duke@1 103 configuration.standardmessage.
duke@1 104 error("doclet.No_Non_Deprecated_Classes_To_Document");
duke@1 105 return;
duke@1 106 }
duke@1 107 boolean nodeprecated = configuration.nodeprecated;
duke@1 108 String configdestdir = configuration.destDirName;
duke@1 109 String confighelpfile = configuration.helpfile;
duke@1 110 String configstylefile = configuration.stylesheetfile;
duke@1 111 performCopy(configdestdir, confighelpfile);
duke@1 112 performCopy(configdestdir, configstylefile);
bpatel@1033 113 Util.copyResourceFile(configuration, "background.gif", false);
bpatel@1033 114 Util.copyResourceFile(configuration, "tab.gif", false);
bpatel@1033 115 Util.copyResourceFile(configuration, "titlebar.gif", false);
bpatel@1033 116 Util.copyResourceFile(configuration, "titlebar_end.gif", false);
duke@1 117 // do early to reduce memory footprint
duke@1 118 if (configuration.classuse) {
duke@1 119 ClassUseWriter.generate(configuration, classtree);
duke@1 120 }
duke@1 121 IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated);
duke@1 122
duke@1 123 if (configuration.createtree) {
duke@1 124 TreeWriter.generate(configuration, classtree);
duke@1 125 }
duke@1 126 if (configuration.createindex) {
duke@1 127 if (configuration.splitindex) {
duke@1 128 SplitIndexWriter.generate(configuration, indexbuilder);
duke@1 129 } else {
duke@1 130 SingleIndexWriter.generate(configuration, indexbuilder);
duke@1 131 }
duke@1 132 }
duke@1 133
duke@1 134 if (!(configuration.nodeprecatedlist || nodeprecated)) {
duke@1 135 DeprecatedListWriter.generate(configuration);
duke@1 136 }
duke@1 137
duke@1 138 AllClassesFrameWriter.generate(configuration,
duke@1 139 new IndexBuilder(configuration, nodeprecated, true));
duke@1 140
duke@1 141 FrameOutputWriter.generate(configuration);
duke@1 142
duke@1 143 if (configuration.createoverview) {
duke@1 144 PackageIndexWriter.generate(configuration);
duke@1 145 }
duke@1 146 if (configuration.helpfile.length() == 0 &&
duke@1 147 !configuration.nohelp) {
duke@1 148 HelpWriter.generate(configuration);
duke@1 149 }
bpatel@793 150 // If a stylesheet file is not specified, copy the default stylesheet
bpatel@793 151 // and replace newline with platform-specific newline.
duke@1 152 if (configuration.stylesheetfile.length() == 0) {
bpatel@766 153 Util.copyFile(configuration, "stylesheet.css", Util.RESOURCESDIR,
bpatel@766 154 (configdestdir.isEmpty()) ?
bpatel@793 155 System.getProperty("user.dir") : configdestdir, false, true);
duke@1 156 }
duke@1 157 }
duke@1 158
duke@1 159 /**
duke@1 160 * {@inheritDoc}
duke@1 161 */
duke@1 162 protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) {
duke@1 163 Arrays.sort(arr);
duke@1 164 for(int i = 0; i < arr.length; i++) {
duke@1 165 if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) {
duke@1 166 continue;
duke@1 167 }
duke@1 168 ClassDoc prev = (i == 0)?
duke@1 169 null:
duke@1 170 arr[i-1];
duke@1 171 ClassDoc curr = arr[i];
duke@1 172 ClassDoc next = (i+1 == arr.length)?
duke@1 173 null:
duke@1 174 arr[i+1];
duke@1 175 try {
duke@1 176 if (curr.isAnnotationType()) {
duke@1 177 AbstractBuilder annotationTypeBuilder =
duke@1 178 configuration.getBuilderFactory()
duke@1 179 .getAnnotationTypeBuilder((AnnotationTypeDoc) curr,
duke@1 180 prev, next);
duke@1 181 annotationTypeBuilder.build();
duke@1 182 } else {
duke@1 183 AbstractBuilder classBuilder =
duke@1 184 configuration.getBuilderFactory()
duke@1 185 .getClassBuilder(curr, prev, next, classtree);
duke@1 186 classBuilder.build();
duke@1 187 }
duke@1 188 } catch (Exception e) {
duke@1 189 e.printStackTrace();
duke@1 190 throw new DocletAbortException();
duke@1 191 }
duke@1 192 }
duke@1 193 }
duke@1 194
duke@1 195 /**
duke@1 196 * {@inheritDoc}
duke@1 197 */
duke@1 198 protected void generatePackageFiles(ClassTree classtree) throws Exception {
duke@1 199 PackageDoc[] packages = configuration.packages;
duke@1 200 if (packages.length > 1) {
duke@1 201 PackageIndexFrameWriter.generate(configuration);
duke@1 202 }
duke@1 203 PackageDoc prev = null, next;
bpatel@995 204 for (int i = 0; i < packages.length; i++) {
bpatel@995 205 // if -nodeprecated option is set and the package is marked as
bpatel@995 206 // deprecated, do not generate the package-summary.html, package-frame.html
bpatel@995 207 // and package-tree.html pages for that package.
bpatel@995 208 if (!(configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
bpatel@995 209 PackageFrameWriter.generate(configuration, packages[i]);
bpatel@995 210 next = (i + 1 < packages.length &&
bpatel@995 211 packages[i + 1].name().length() > 0) ? packages[i + 1] : null;
bpatel@995 212 //If the next package is unnamed package, skip 2 ahead if possible
bpatel@995 213 next = (i + 2 < packages.length && next == null) ? packages[i + 2] : next;
bpatel@995 214 AbstractBuilder packageSummaryBuilder =
bpatel@995 215 configuration.getBuilderFactory().getPackageSummaryBuilder(
bpatel@995 216 packages[i], prev, next);
bpatel@995 217 packageSummaryBuilder.build();
bpatel@995 218 if (configuration.createtree) {
bpatel@995 219 PackageTreeWriter.generate(configuration,
bpatel@995 220 packages[i], prev, next,
bpatel@995 221 configuration.nodeprecated);
bpatel@995 222 }
bpatel@995 223 prev = packages[i];
duke@1 224 }
duke@1 225 }
duke@1 226 }
duke@1 227
duke@1 228 /**
duke@1 229 * Check for doclet added options here.
duke@1 230 *
duke@1 231 * @return number of arguments to option. Zero return means
duke@1 232 * option not known. Negative value means error occurred.
duke@1 233 */
duke@1 234 public static int optionLength(String option) {
duke@1 235 // Construct temporary configuration for check
duke@1 236 return (ConfigurationImpl.getInstance()).optionLength(option);
duke@1 237 }
duke@1 238
duke@1 239 /**
duke@1 240 * Check that options have the correct arguments here.
duke@1 241 * <P>
duke@1 242 * This method is not required and will default gracefully
duke@1 243 * (to true) if absent.
duke@1 244 * <P>
duke@1 245 * Printing option related error messages (using the provided
duke@1 246 * DocErrorReporter) is the responsibility of this method.
duke@1 247 *
duke@1 248 * @return true if the options are valid.
duke@1 249 */
duke@1 250 public static boolean validOptions(String options[][],
duke@1 251 DocErrorReporter reporter) {
duke@1 252 // Construct temporary configuration for check
duke@1 253 return (ConfigurationImpl.getInstance()).validOptions(options, reporter);
duke@1 254 }
duke@1 255
duke@1 256 private void performCopy(String configdestdir, String filename) {
duke@1 257 try {
duke@1 258 String destdir = (configdestdir.length() > 0) ?
duke@1 259 configdestdir + File.separatorChar: "";
duke@1 260 if (filename.length() > 0) {
duke@1 261 File helpstylefile = new File(filename);
duke@1 262 String parent = helpstylefile.getParent();
duke@1 263 String helpstylefilename = (parent == null)?
duke@1 264 filename:
duke@1 265 filename.substring(parent.length() + 1);
duke@1 266 File desthelpfile = new File(destdir + helpstylefilename);
duke@1 267 if (!desthelpfile.getCanonicalPath().equals(
duke@1 268 helpstylefile.getCanonicalPath())) {
duke@1 269 configuration.message.
duke@1 270 notice((SourcePosition) null,
duke@1 271 "doclet.Copying_File_0_To_File_1",
duke@1 272 helpstylefile.toString(), desthelpfile.toString());
duke@1 273 Util.copyFile(desthelpfile, helpstylefile);
duke@1 274 }
duke@1 275 }
duke@1 276 } catch (IOException exc) {
duke@1 277 configuration.message.
duke@1 278 error((SourcePosition) null,
duke@1 279 "doclet.perform_copy_exception_encountered",
duke@1 280 exc.toString());
duke@1 281 throw new DocletAbortException();
duke@1 282 }
duke@1 283 }
duke@1 284 }

mercurial