langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
author ksrini
Sun, 15 Jun 2014 08:41:57 -0700
changeset 25454 376a52c9540c
parent 24221 2376793dd33b
permissions -rw-r--r--
8039028: [javadoc] refactor the usage of Util.java Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
package com.sun.tools.doclets.formats.html;
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9894
diff changeset
    27
import java.io.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9894
diff changeset
    28
import java.util.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9894
diff changeset
    29
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9894
diff changeset
    30
import com.sun.javadoc.*;
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
    31
import com.sun.tools.javac.jvm.Profile;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.doclets.internal.toolkit.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.doclets.internal.toolkit.builders.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * The class with "start" method, calls individual Writers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    40
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    42
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public class HtmlDoclet extends AbstractDoclet {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    50
    // An instance will be created by validOptions, and used by start.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    51
    private static HtmlDoclet docletToStart = null;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    52
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    53
    public HtmlDoclet() {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    54
        configuration = new ConfigurationImpl();
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    55
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    60
    public final ConfigurationImpl configuration;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * The "start" method as required by Javadoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * @param root the root of the documentation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * @see com.sun.javadoc.RootDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * @return true if the doclet ran without encountering any errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public static boolean start(RootDoc root) {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    70
        // In typical use, options will have been set up by calling validOptions,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    71
        // which will create an HtmlDoclet for use here.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    72
        HtmlDoclet doclet;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    73
        if (docletToStart != null) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    74
            doclet = docletToStart;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    75
            docletToStart = null;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    76
        } else {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    77
            doclet = new HtmlDoclet();
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    78
        }
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    79
        return doclet.start(doclet, root);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * Create the configuration instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * Override this method to use a different
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * configuration.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public Configuration configuration() {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    88
        return configuration;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Start the generation of files. Call generate methods in the individual
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * writers, which will in turn genrate the documentation files. Call the
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * TreeWriter generation first to ensure the Class Hierarchy is built
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * first and then can be used in the later generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * For new format.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * @see com.sun.javadoc.RootDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    protected void generateOtherFiles(RootDoc root, ClassTree classtree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        super.generateOtherFiles(root, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        if (configuration.linksource) {
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   105
            SourceToHTMLConverter.convertRoot(configuration,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   106
                root, DocPaths.SOURCE_OUTPUT);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   109
        if (configuration.topFile.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            configuration.standardmessage.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
                error("doclet.No_Non_Deprecated_Classes_To_Document");
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        boolean nodeprecated = configuration.nodeprecated;
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   115
        performCopy(configuration.helpfile);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   116
        performCopy(configuration.stylesheetfile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        // do early to reduce memory footprint
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        if (configuration.classuse) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            ClassUseWriter.generate(configuration, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        if (configuration.createtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            TreeWriter.generate(configuration, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        if (configuration.createindex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            if (configuration.splitindex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                SplitIndexWriter.generate(configuration, indexbuilder);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                SingleIndexWriter.generate(configuration, indexbuilder);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        if (!(configuration.nodeprecatedlist || nodeprecated)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            DeprecatedListWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        AllClassesFrameWriter.generate(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            new IndexBuilder(configuration, nodeprecated, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        FrameOutputWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        if (configuration.createoverview) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            PackageIndexWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        if (configuration.helpfile.length() == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            !configuration.nohelp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            HelpWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   150
        // If a stylesheet file is not specified, copy the default stylesheet
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   151
        // and replace newline with platform-specific newline.
14549
0599d73bf1da 8002304: Group methods by types in methods summary section
bpatel
parents: 14542
diff changeset
   152
        DocFile f;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        if (configuration.stylesheetfile.length() == 0) {
14549
0599d73bf1da 8002304: Group methods by types in methods summary section
bpatel
parents: 14542
diff changeset
   154
            f = DocFile.createFileForOutput(configuration, DocPaths.STYLESHEET);
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   155
            f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.STYLESHEET), false, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        }
14549
0599d73bf1da 8002304: Group methods by types in methods summary section
bpatel
parents: 14542
diff changeset
   157
        f = DocFile.createFileForOutput(configuration, DocPaths.JAVASCRIPT);
0599d73bf1da 8002304: Group methods by types in methods summary section
bpatel
parents: 14542
diff changeset
   158
        f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.JAVASCRIPT), true, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        Arrays.sort(arr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        for(int i = 0; i < arr.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
            ClassDoc prev = (i == 0)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                null:
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                arr[i-1];
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            ClassDoc curr = arr[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            ClassDoc next = (i+1 == arr.length)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                null:
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                arr[i+1];
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                if (curr.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                    AbstractBuilder annotationTypeBuilder =
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                        configuration.getBuilderFactory()
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                            .getAnnotationTypeBuilder((AnnotationTypeDoc) curr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                                prev, next);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                    annotationTypeBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                    AbstractBuilder classBuilder =
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                        configuration.getBuilderFactory()
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                            .getClassBuilder(curr, prev, next, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                    classBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                }
20600
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 19937
diff changeset
   190
            } catch (IOException e) {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 19937
diff changeset
   191
                throw new DocletAbortException(e);
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 19937
diff changeset
   192
            } catch (DocletAbortException de) {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 19937
diff changeset
   193
                throw de;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            } catch (Exception e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                e.printStackTrace();
19667
fdfce85627a9 8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents: 15723
diff changeset
   196
                throw new DocletAbortException(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     */
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   204
    protected void generateProfileFiles() throws Exception {
19937
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   205
        if (configuration.showProfiles && configuration.profilePackages.size() > 0) {
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   206
            ProfileIndexFrameWriter.generate(configuration);
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   207
            Profile prevProfile = null, nextProfile;
19937
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   208
            String profileName;
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   209
            for (int i = 1; i < configuration.profiles.getProfileCount(); i++) {
19937
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   210
                profileName = Profile.lookup(i).name;
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   211
                // Generate profile package pages only if there are any packages
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   212
                // in a profile to be documented. The profilePackages map will not
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   213
                // contain an entry for the profile if there are no packages to be documented.
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   214
                if (!configuration.shouldDocumentProfile(profileName))
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   215
                    continue;
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   216
                ProfilePackageIndexFrameWriter.generate(configuration, profileName);
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   217
                List<PackageDoc> packages = configuration.profilePackages.get(
19937
7dacecdfbad4 8015496: Information that package is deprecated is missing in profiles view
bpatel
parents: 19667
diff changeset
   218
                        profileName);
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   219
                PackageDoc prev = null, next;
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   220
                for (int j = 0; j < packages.size(); j++) {
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   221
                    // if -nodeprecated option is set and the package is marked as
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   222
                    // deprecated, do not generate the profilename-package-summary.html
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   223
                    // and profilename-package-frame.html pages for that package.
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   224
                    PackageDoc pkg = packages.get(j);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
   225
                    if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   226
                        ProfilePackageFrameWriter.generate(configuration, pkg, i);
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   227
                        next = getNamedPackage(packages, j + 1);
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   228
                        AbstractBuilder profilePackageSummaryBuilder =
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   229
                                configuration.getBuilderFactory().getProfilePackageSummaryBuilder(
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   230
                                pkg, prev, next, Profile.lookup(i));
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   231
                        profilePackageSummaryBuilder.build();
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   232
                        prev = pkg;
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   233
                    }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   234
                }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   235
                nextProfile = (i + 1 < configuration.profiles.getProfileCount()) ?
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   236
                        Profile.lookup(i + 1) : null;
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   237
                AbstractBuilder profileSummaryBuilder =
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   238
                        configuration.getBuilderFactory().getProfileSummaryBuilder(
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   239
                        Profile.lookup(i), prevProfile, nextProfile);
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   240
                profileSummaryBuilder.build();
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   241
                prevProfile = Profile.lookup(i);
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   242
            }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   243
        }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   244
    }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   245
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   246
    PackageDoc getNamedPackage(List<PackageDoc> list, int idx) {
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   247
        if (idx < list.size()) {
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   248
            PackageDoc pkg = list.get(idx);
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   249
            if (!pkg.name().isEmpty()) {
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   250
                return pkg;
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   251
            }
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   252
        }
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   253
        return null;
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   254
    }
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   255
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   256
    /**
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   257
     * {@inheritDoc}
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14549
diff changeset
   258
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    protected void generatePackageFiles(ClassTree classtree) throws Exception {
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   260
        Set<PackageDoc> packages = configuration.packages;
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   261
        if (packages.size() > 1) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            PackageIndexFrameWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        }
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   264
        List<PackageDoc> pList = new ArrayList<>(configuration.packages);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        PackageDoc prev = null, next;
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   266
        for (int i = 0; i < pList.size(); i++) {
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   267
            // if -nodeprecated option is set and the package is marked as
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   268
            // deprecated, do not generate the package-summary.html, package-frame.html
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   269
            // and package-tree.html pages for that package.
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   270
            PackageDoc pkg = pList.get(i);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
   271
            if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   272
                PackageFrameWriter.generate(configuration, pkg);
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   273
                next = getNamedPackage(pList, i + 1);
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   274
                //If the next package is unnamed package, skip 2 ahead if possible
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   275
                if (next == null)
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   276
                    next = getNamedPackage(pList, i + 2);
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   277
                AbstractBuilder packageSummaryBuilder =
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   278
                        configuration.getBuilderFactory().getPackageSummaryBuilder(
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   279
                        pkg, prev, next);
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   280
                packageSummaryBuilder.build();
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   281
                if (configuration.createtree) {
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   282
                    PackageTreeWriter.generate(configuration,
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   283
                            pkg, prev, next,
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   284
                            configuration.nodeprecated);
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 7681
diff changeset
   285
                }
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22447
diff changeset
   286
                prev = pkg;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   291
    public static final ConfigurationImpl sharedInstanceForOptions =
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   292
            new ConfigurationImpl();
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   293
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * Check for doclet added options here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * @return number of arguments to option. Zero return means
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     * option not known.  Negative value means error occurred.
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    public static int optionLength(String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        // Construct temporary configuration for check
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   302
        return sharedInstanceForOptions.optionLength(option);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     * Check that options have the correct arguments here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     * <P>
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     * This method is not required and will default gracefully
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     * (to true) if absent.
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     * <P>
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     * Printing option related error messages (using the provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     * DocErrorReporter) is the responsibility of this method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * @return true if the options are valid.
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    public static boolean validOptions(String options[][],
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            DocErrorReporter reporter) {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   318
        docletToStart = new HtmlDoclet();
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
   319
        return docletToStart.configuration.validOptions(options, reporter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   322
    private void performCopy(String filename) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   323
        if (filename.isEmpty())
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   324
            return;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   325
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        try {
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   327
            DocFile fromfile = DocFile.createFileForInput(configuration, filename);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   328
            DocPath path = DocPath.create(fromfile.getName());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   329
            DocFile toFile = DocFile.createFileForOutput(configuration, path);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   330
            if (toFile.isSameFile(fromfile))
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   331
                return;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   332
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   333
            configuration.message.notice((SourcePosition) null,
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   334
                    "doclet.Copying_File_0_To_File_1",
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   335
                    fromfile.toString(), path.getPath());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   336
            toFile.copyFile(fromfile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        } catch (IOException exc) {
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   338
            configuration.message.error((SourcePosition) null,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                    "doclet.perform_copy_exception_encountered",
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                    exc.toString());
19667
fdfce85627a9 8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents: 15723
diff changeset
   341
            throw new DocletAbortException(exc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
}