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

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 2225
b8ebde062692
child 2525
2eb010b6cb22
child 3315
6f0746b6de9f
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

duke@1 1 /*
bpatel@1568 2 * Copyright (c) 1997, 2013, 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.*;
bpatel@1568 31 import com.sun.tools.javac.sym.Profiles;
bpatel@1568 32 import com.sun.tools.javac.jvm.Profile;
duke@1 33 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 34 import com.sun.tools.doclets.internal.toolkit.builders.*;
duke@1 35 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 36
duke@1 37 /**
duke@1 38 * The class with "start" method, calls individual Writers.
duke@1 39 *
jjg@1359 40 * <p><b>This is NOT part of any supported API.
jjg@1359 41 * If you write code that depends on this, you do so at your own risk.
jjg@1359 42 * This code and its internal interfaces are subject to change or
jjg@1359 43 * deletion without notice.</b>
jjg@1359 44 *
duke@1 45 * @author Atul M Dambalkar
duke@1 46 * @author Robert Field
duke@1 47 * @author Jamie Ho
duke@1 48 *
duke@1 49 */
duke@1 50 public class HtmlDoclet extends AbstractDoclet {
jjg@1410 51 // An instance will be created by validOptions, and used by start.
jjg@1410 52 private static HtmlDoclet docletToStart = null;
jjg@1410 53
jjg@140 54 public HtmlDoclet() {
jjg@1410 55 configuration = new ConfigurationImpl();
jjg@140 56 }
duke@1 57
duke@1 58 /**
duke@1 59 * The global configuration information for this run.
duke@1 60 */
jjg@1410 61 public final ConfigurationImpl configuration;
duke@1 62
duke@1 63 /**
duke@1 64 * The "start" method as required by Javadoc.
duke@1 65 *
duke@1 66 * @param root the root of the documentation tree.
duke@1 67 * @see com.sun.javadoc.RootDoc
duke@1 68 * @return true if the doclet ran without encountering any errors.
duke@1 69 */
duke@1 70 public static boolean start(RootDoc root) {
jjg@1410 71 // In typical use, options will have been set up by calling validOptions,
jjg@1410 72 // which will create an HtmlDoclet for use here.
jjg@1410 73 HtmlDoclet doclet;
jjg@1410 74 if (docletToStart != null) {
jjg@1410 75 doclet = docletToStart;
jjg@1410 76 docletToStart = null;
jjg@1410 77 } else {
jjg@1410 78 doclet = new HtmlDoclet();
jjg@140 79 }
jjg@1410 80 return doclet.start(doclet, root);
duke@1 81 }
duke@1 82
duke@1 83 /**
duke@1 84 * Create the configuration instance.
duke@1 85 * Override this method to use a different
duke@1 86 * configuration.
duke@1 87 */
duke@1 88 public Configuration configuration() {
jjg@1410 89 return configuration;
duke@1 90 }
duke@1 91
duke@1 92 /**
duke@1 93 * Start the generation of files. Call generate methods in the individual
duke@1 94 * writers, which will in turn genrate the documentation files. Call the
duke@1 95 * TreeWriter generation first to ensure the Class Hierarchy is built
duke@1 96 * first and then can be used in the later generation.
duke@1 97 *
duke@1 98 * For new format.
duke@1 99 *
duke@1 100 * @see com.sun.javadoc.RootDoc
duke@1 101 */
duke@1 102 protected void generateOtherFiles(RootDoc root, ClassTree classtree)
duke@1 103 throws Exception {
duke@1 104 super.generateOtherFiles(root, classtree);
duke@1 105 if (configuration.linksource) {
jjg@1372 106 SourceToHTMLConverter.convertRoot(configuration,
jjg@1372 107 root, DocPaths.SOURCE_OUTPUT);
duke@1 108 }
duke@1 109
jjg@1372 110 if (configuration.topFile.isEmpty()) {
duke@1 111 configuration.standardmessage.
duke@1 112 error("doclet.No_Non_Deprecated_Classes_To_Document");
duke@1 113 return;
duke@1 114 }
duke@1 115 boolean nodeprecated = configuration.nodeprecated;
jjg@1383 116 performCopy(configuration.helpfile);
jjg@1383 117 performCopy(configuration.stylesheetfile);
duke@1 118 // do early to reduce memory footprint
duke@1 119 if (configuration.classuse) {
duke@1 120 ClassUseWriter.generate(configuration, classtree);
duke@1 121 }
duke@1 122 IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated);
duke@1 123
duke@1 124 if (configuration.createtree) {
duke@1 125 TreeWriter.generate(configuration, classtree);
duke@1 126 }
duke@1 127 if (configuration.createindex) {
duke@1 128 if (configuration.splitindex) {
duke@1 129 SplitIndexWriter.generate(configuration, indexbuilder);
duke@1 130 } else {
duke@1 131 SingleIndexWriter.generate(configuration, indexbuilder);
duke@1 132 }
duke@1 133 }
duke@1 134
duke@1 135 if (!(configuration.nodeprecatedlist || nodeprecated)) {
duke@1 136 DeprecatedListWriter.generate(configuration);
duke@1 137 }
duke@1 138
duke@1 139 AllClassesFrameWriter.generate(configuration,
duke@1 140 new IndexBuilder(configuration, nodeprecated, true));
duke@1 141
duke@1 142 FrameOutputWriter.generate(configuration);
duke@1 143
duke@1 144 if (configuration.createoverview) {
duke@1 145 PackageIndexWriter.generate(configuration);
duke@1 146 }
duke@1 147 if (configuration.helpfile.length() == 0 &&
duke@1 148 !configuration.nohelp) {
duke@1 149 HelpWriter.generate(configuration);
duke@1 150 }
bpatel@793 151 // If a stylesheet file is not specified, copy the default stylesheet
bpatel@793 152 // and replace newline with platform-specific newline.
bpatel@1417 153 DocFile f;
duke@1 154 if (configuration.stylesheetfile.length() == 0) {
bpatel@1417 155 f = DocFile.createFileForOutput(configuration, DocPaths.STYLESHEET);
jjg@1383 156 f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.STYLESHEET), false, true);
duke@1 157 }
bpatel@1417 158 f = DocFile.createFileForOutput(configuration, DocPaths.JAVASCRIPT);
bpatel@1417 159 f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.JAVASCRIPT), true, true);
duke@1 160 }
duke@1 161
duke@1 162 /**
duke@1 163 * {@inheritDoc}
duke@1 164 */
duke@1 165 protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) {
duke@1 166 Arrays.sort(arr);
duke@1 167 for(int i = 0; i < arr.length; i++) {
duke@1 168 if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) {
duke@1 169 continue;
duke@1 170 }
duke@1 171 ClassDoc prev = (i == 0)?
duke@1 172 null:
duke@1 173 arr[i-1];
duke@1 174 ClassDoc curr = arr[i];
duke@1 175 ClassDoc next = (i+1 == arr.length)?
duke@1 176 null:
duke@1 177 arr[i+1];
duke@1 178 try {
duke@1 179 if (curr.isAnnotationType()) {
duke@1 180 AbstractBuilder annotationTypeBuilder =
duke@1 181 configuration.getBuilderFactory()
duke@1 182 .getAnnotationTypeBuilder((AnnotationTypeDoc) curr,
duke@1 183 prev, next);
duke@1 184 annotationTypeBuilder.build();
duke@1 185 } else {
duke@1 186 AbstractBuilder classBuilder =
duke@1 187 configuration.getBuilderFactory()
duke@1 188 .getClassBuilder(curr, prev, next, classtree);
duke@1 189 classBuilder.build();
duke@1 190 }
kizune@2071 191 } catch (IOException e) {
kizune@2071 192 throw new DocletAbortException(e);
kizune@2071 193 } catch (DocletAbortException de) {
kizune@2071 194 throw de;
duke@1 195 } catch (Exception e) {
duke@1 196 e.printStackTrace();
jjg@1985 197 throw new DocletAbortException(e);
duke@1 198 }
duke@1 199 }
duke@1 200 }
duke@1 201
duke@1 202 /**
duke@1 203 * {@inheritDoc}
duke@1 204 */
bpatel@1568 205 protected void generateProfileFiles() throws Exception {
bpatel@2023 206 if (configuration.showProfiles && configuration.profilePackages.size() > 0) {
bpatel@1568 207 ProfileIndexFrameWriter.generate(configuration);
bpatel@1568 208 Profile prevProfile = null, nextProfile;
bpatel@2023 209 String profileName;
bpatel@1568 210 for (int i = 1; i < configuration.profiles.getProfileCount(); i++) {
bpatel@2023 211 profileName = Profile.lookup(i).name;
bpatel@2023 212 // Generate profile package pages only if there are any packages
bpatel@2023 213 // in a profile to be documented. The profilePackages map will not
bpatel@2023 214 // contain an entry for the profile if there are no packages to be documented.
bpatel@2023 215 if (!configuration.shouldDocumentProfile(profileName))
bpatel@2023 216 continue;
bpatel@2023 217 ProfilePackageIndexFrameWriter.generate(configuration, profileName);
bpatel@1568 218 PackageDoc[] packages = configuration.profilePackages.get(
bpatel@2023 219 profileName);
bpatel@1568 220 PackageDoc prev = null, next;
bpatel@1568 221 for (int j = 0; j < packages.length; j++) {
bpatel@1568 222 // if -nodeprecated option is set and the package is marked as
bpatel@1568 223 // deprecated, do not generate the profilename-package-summary.html
bpatel@1568 224 // and profilename-package-frame.html pages for that package.
bpatel@1568 225 if (!(configuration.nodeprecated && Util.isDeprecated(packages[j]))) {
bpatel@1568 226 ProfilePackageFrameWriter.generate(configuration, packages[j], i);
bpatel@1568 227 next = (j + 1 < packages.length
bpatel@1568 228 && packages[j + 1].name().length() > 0) ? packages[j + 1] : null;
bpatel@1568 229 AbstractBuilder profilePackageSummaryBuilder =
bpatel@1568 230 configuration.getBuilderFactory().getProfilePackageSummaryBuilder(
bpatel@1568 231 packages[j], prev, next, Profile.lookup(i));
bpatel@1568 232 profilePackageSummaryBuilder.build();
bpatel@1568 233 prev = packages[j];
bpatel@1568 234 }
bpatel@1568 235 }
bpatel@1568 236 nextProfile = (i + 1 < configuration.profiles.getProfileCount()) ?
bpatel@1568 237 Profile.lookup(i + 1) : null;
bpatel@1568 238 AbstractBuilder profileSummaryBuilder =
bpatel@1568 239 configuration.getBuilderFactory().getProfileSummaryBuilder(
bpatel@1568 240 Profile.lookup(i), prevProfile, nextProfile);
bpatel@1568 241 profileSummaryBuilder.build();
bpatel@1568 242 prevProfile = Profile.lookup(i);
bpatel@1568 243 }
bpatel@1568 244 }
bpatel@1568 245 }
bpatel@1568 246
bpatel@1568 247 /**
bpatel@1568 248 * {@inheritDoc}
bpatel@1568 249 */
duke@1 250 protected void generatePackageFiles(ClassTree classtree) throws Exception {
duke@1 251 PackageDoc[] packages = configuration.packages;
duke@1 252 if (packages.length > 1) {
duke@1 253 PackageIndexFrameWriter.generate(configuration);
duke@1 254 }
duke@1 255 PackageDoc prev = null, next;
bpatel@995 256 for (int i = 0; i < packages.length; i++) {
bpatel@995 257 // if -nodeprecated option is set and the package is marked as
bpatel@995 258 // deprecated, do not generate the package-summary.html, package-frame.html
bpatel@995 259 // and package-tree.html pages for that package.
bpatel@995 260 if (!(configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
bpatel@995 261 PackageFrameWriter.generate(configuration, packages[i]);
bpatel@995 262 next = (i + 1 < packages.length &&
bpatel@995 263 packages[i + 1].name().length() > 0) ? packages[i + 1] : null;
bpatel@995 264 //If the next package is unnamed package, skip 2 ahead if possible
bpatel@995 265 next = (i + 2 < packages.length && next == null) ? packages[i + 2] : next;
bpatel@995 266 AbstractBuilder packageSummaryBuilder =
bpatel@995 267 configuration.getBuilderFactory().getPackageSummaryBuilder(
bpatel@995 268 packages[i], prev, next);
bpatel@995 269 packageSummaryBuilder.build();
bpatel@995 270 if (configuration.createtree) {
bpatel@995 271 PackageTreeWriter.generate(configuration,
bpatel@995 272 packages[i], prev, next,
bpatel@995 273 configuration.nodeprecated);
bpatel@995 274 }
bpatel@995 275 prev = packages[i];
duke@1 276 }
duke@1 277 }
duke@1 278 }
duke@1 279
jjg@1410 280 public static final ConfigurationImpl sharedInstanceForOptions =
jjg@1410 281 new ConfigurationImpl();
jjg@1410 282
duke@1 283 /**
duke@1 284 * Check for doclet added options here.
duke@1 285 *
duke@1 286 * @return number of arguments to option. Zero return means
duke@1 287 * option not known. Negative value means error occurred.
duke@1 288 */
duke@1 289 public static int optionLength(String option) {
duke@1 290 // Construct temporary configuration for check
jjg@1410 291 return sharedInstanceForOptions.optionLength(option);
duke@1 292 }
duke@1 293
duke@1 294 /**
duke@1 295 * Check that options have the correct arguments here.
duke@1 296 * <P>
duke@1 297 * This method is not required and will default gracefully
duke@1 298 * (to true) if absent.
duke@1 299 * <P>
duke@1 300 * Printing option related error messages (using the provided
duke@1 301 * DocErrorReporter) is the responsibility of this method.
duke@1 302 *
duke@1 303 * @return true if the options are valid.
duke@1 304 */
duke@1 305 public static boolean validOptions(String options[][],
duke@1 306 DocErrorReporter reporter) {
jjg@1410 307 docletToStart = new HtmlDoclet();
jjg@1410 308 return docletToStart.configuration.validOptions(options, reporter);
duke@1 309 }
duke@1 310
jjg@1383 311 private void performCopy(String filename) {
jjg@1383 312 if (filename.isEmpty())
jjg@1383 313 return;
jjg@1383 314
duke@1 315 try {
jjg@1383 316 DocFile fromfile = DocFile.createFileForInput(configuration, filename);
jjg@1383 317 DocPath path = DocPath.create(fromfile.getName());
jjg@1383 318 DocFile toFile = DocFile.createFileForOutput(configuration, path);
jjg@1383 319 if (toFile.isSameFile(fromfile))
jjg@1383 320 return;
jjg@1383 321
jjg@1383 322 configuration.message.notice((SourcePosition) null,
jjg@1383 323 "doclet.Copying_File_0_To_File_1",
jjg@1383 324 fromfile.toString(), path.getPath());
jjg@1383 325 toFile.copyFile(fromfile);
duke@1 326 } catch (IOException exc) {
jjg@1383 327 configuration.message.error((SourcePosition) null,
duke@1 328 "doclet.perform_copy_exception_encountered",
duke@1 329 exc.toString());
jjg@1985 330 throw new DocletAbortException(exc);
duke@1 331 }
duke@1 332 }
duke@1 333 }

mercurial