langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/PackageListWriter.java
author jjg
Mon, 22 Aug 2016 16:32:40 -0700
changeset 40587 1c355ea550ed
parent 40508 74ef30d16fb9
child 45417 f7479ee8de69
permissions -rw-r--r--
8164130: Simplify doclet IOException handling Reviewed-by: bpatel, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 35426
diff changeset
     2
 * Copyright (c) 1998, 2016, 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: 10
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: 10
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: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    31
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import jdk.javadoc.doclet.DocletEnvironment;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import jdk.javadoc.internal.doclets.toolkit.Configuration;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9606
diff changeset
    35
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * Write out the package index.
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>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    46
public class PackageListWriter {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    48
    private final Configuration configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    49
    private final Utils utils;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    50
    private final DocFile file;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    57
    public PackageListWriter(Configuration configuration) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    58
        file = DocFile.createFileForOutput(configuration, DocPaths.PACKAGE_LIST);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        this.configuration = configuration;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    60
        this.utils = configuration.utils;
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * Generate the package index.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * @param configuration the current configuration of the doclet.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    67
     * @throws DocFileIOException if there is a problem writing the output
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    69
    public static void generate(Configuration configuration) throws DocFileIOException {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    70
        PackageListWriter packgen = new PackageListWriter(configuration);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    71
        packgen.generatePackageListFile(configuration.docEnv);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    72
    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    73
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    74
    protected void generatePackageListFile(DocletEnvironment docEnv) throws DocFileIOException {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    75
        try (BufferedWriter out = new BufferedWriter(file.openWriter())) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    76
            for (PackageElement pkg : configuration.packages) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    77
                // if the -nodeprecated option is set and the package is marked as
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    78
                // deprecated, do not include it in the packages list.
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    79
                if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    80
                    out.write(pkg.toString());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    81
                    out.newLine();
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    82
                }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    83
            }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    84
        } catch (IOException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    85
            throw new DocFileIOException(file, DocFileIOException.Mode.WRITE, e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
}