43 * This code and its internal interfaces are subject to change or |
41 * This code and its internal interfaces are subject to change or |
44 * deletion without notice.</b> |
42 * deletion without notice.</b> |
45 * |
43 * |
46 * @author Atul M Dambalkar |
44 * @author Atul M Dambalkar |
47 */ |
45 */ |
48 public class PackageListWriter extends PrintWriter { |
46 public class PackageListWriter { |
49 |
47 |
50 private final Configuration configuration; |
48 private final Configuration configuration; |
51 private final Utils utils; |
49 private final Utils utils; |
|
50 private final DocFile file; |
52 |
51 |
53 /** |
52 /** |
54 * Constructor. |
53 * Constructor. |
55 * |
54 * |
56 * @param configuration the current configuration of the doclet. |
55 * @param configuration the current configuration of the doclet. |
57 */ |
56 */ |
58 public PackageListWriter(Configuration configuration) throws IOException { |
57 public PackageListWriter(Configuration configuration) { |
59 super(DocFile.createFileForOutput(configuration, DocPaths.PACKAGE_LIST).openWriter()); |
58 file = DocFile.createFileForOutput(configuration, DocPaths.PACKAGE_LIST); |
60 this.configuration = configuration; |
59 this.configuration = configuration; |
61 this.utils = configuration.utils; |
60 this.utils = configuration.utils; |
62 } |
61 } |
63 |
62 |
64 /** |
63 /** |
65 * Generate the package index. |
64 * Generate the package index. |
66 * |
65 * |
67 * @param configuration the current configuration of the doclet. |
66 * @param configuration the current configuration of the doclet. |
68 * @throws DocletAbortException |
67 * @throws DocFileIOException if there is a problem writing the output |
69 */ |
68 */ |
70 public static void generate(Configuration configuration) { |
69 public static void generate(Configuration configuration) throws DocFileIOException { |
71 PackageListWriter packgen; |
70 PackageListWriter packgen = new PackageListWriter(configuration); |
72 try { |
71 packgen.generatePackageListFile(configuration.docEnv); |
73 packgen = new PackageListWriter(configuration); |
72 } |
74 packgen.generatePackageListFile(configuration.docEnv); |
73 |
75 packgen.close(); |
74 protected void generatePackageListFile(DocletEnvironment docEnv) throws DocFileIOException { |
76 } catch (IOException exc) { |
75 try (BufferedWriter out = new BufferedWriter(file.openWriter())) { |
77 Messages messages = configuration.getMessages(); |
76 for (PackageElement pkg : configuration.packages) { |
78 messages.error("doclet.exception_encountered", |
77 // if the -nodeprecated option is set and the package is marked as |
79 exc.toString(), DocPaths.PACKAGE_LIST); |
78 // deprecated, do not include it in the packages list. |
80 throw new DocletAbortException(exc); |
79 if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) { |
|
80 out.write(pkg.toString()); |
|
81 out.newLine(); |
|
82 } |
|
83 } |
|
84 } catch (IOException e) { |
|
85 throw new DocFileIOException(file, DocFileIOException.Mode.WRITE, e); |
81 } |
86 } |
82 } |
87 } |
83 |
|
84 protected void generatePackageListFile(DocletEnvironment docEnv) { |
|
85 ArrayList<PackageElement> names = new ArrayList<>(); |
|
86 for (PackageElement pkg : configuration.packages) { |
|
87 // if the -nodeprecated option is set and the package is marked as |
|
88 // deprecated, do not include it in the packages list. |
|
89 if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) |
|
90 names.add(pkg); |
|
91 } |
|
92 names.stream().forEach((name) -> { |
|
93 println(name); |
|
94 }); |
|
95 } |
|
96 } |
88 } |