1/*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.tools.doclets.internal.toolkit.util;
27
28import java.io.*;
29import java.util.*;
30
31import com.sun.javadoc.*;
32import com.sun.tools.doclets.internal.toolkit.*;
33
34/**
35 * Write out the package index.
36 *
37 *  <p><b>This is NOT part of any supported API.
38 *  If you write code that depends on this, you do so at your own risk.
39 *  This code and its internal interfaces are subject to change or
40 *  deletion without notice.</b>
41 *
42 * @see com.sun.javadoc.PackageDoc
43 * @author Atul M Dambalkar
44 */
45@Deprecated
46public class PackageListWriter extends PrintWriter {
47
48    private final Configuration configuration;
49    private final Utils utils;
50
51    /**
52     * Constructor.
53     *
54     * @param configuration the current configuration of the doclet.
55     */
56    public PackageListWriter(Configuration configuration) throws IOException {
57        super(DocFile.createFileForOutput(configuration, DocPaths.PACKAGE_LIST).openWriter());
58        this.configuration = configuration;
59        this.utils = configuration.utils;
60    }
61
62    /**
63     * Generate the package index.
64     *
65     * @param configuration the current configuration of the doclet.
66     * @throws DocletAbortException
67     */
68    public static void generate(Configuration configuration) {
69        PackageListWriter packgen;
70        try {
71            packgen = new PackageListWriter(configuration);
72            packgen.generatePackageListFile(configuration.root);
73            packgen.close();
74        } catch (IOException exc) {
75            configuration.message.error("doclet.exception_encountered",
76                exc.toString(), DocPaths.PACKAGE_LIST);
77            throw new DocletAbortException(exc);
78        }
79    }
80
81    protected void generatePackageListFile(RootDoc root) {
82        ArrayList<String> names = new ArrayList<>();
83        for (PackageDoc pkg : configuration.packages) {
84            // if the -nodeprecated option is set and the package is marked as
85            // deprecated, do not include it in the packages list.
86            if (!(configuration.nodeprecated && utils.isDeprecated(pkg)))
87                names.add(pkg.name());
88        }
89        Collections.sort(names);
90        for (String name : names) {
91            println(name);
92        }
93    }
94}
95