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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 1
9a66ca7c79fa
child 140
22c4c1143a3a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

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

mercurial