elharo commented on code in PR #118: URL: https://github.com/apache/maven-changes-plugin/pull/118#discussion_r1976483542
########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -235,4 +260,35 @@ private static Date getDate(final String dateRelease, final DateFormat dateForma return new Date(); } } + + /** + * Simple {@link OutputStream} implementation that writes to a {@link Writer}. + * + * @since 1.3 + */ + private static class WriterOutputStream extends OutputStream { + private final Writer writer; + + WriterOutputStream(final Writer writer) { + this.writer = writer; + } + + @Override + public void write(final int b) throws IOException { Review Comment: This all depends on the platform dependent default encoding. ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -161,27 +163,50 @@ public List<String> getSupportedFeedTypes() { } /** - * Extract a feed and export it to a Writer. + * Extract a feed and export it to a Writer. This method is deprecated, use + * {@link #export(List, String, OutputStream)} instead. * * @param releases the List of Releases. Only the last release is used in the feed. * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for * supported values. * @param writer a Writer. Note that this is not flushed nor closed upon exit. * @throws IOException if an error occurs during export + * @deprecated Use {@link #export(List, String, OutputStream)} instead. */ + @Deprecated public void export(final List<Release> releases, final String feedType, final Writer writer) throws IOException { + export(releases, feedType, new BufferedOutputStream(new WriterOutputStream(writer))); + } + + /** + * Extract a feed and export it to an OutputStream. + * + * @param releases the List of Releases. Only the last release is used in the feed. + * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for + * supported values. + * @param outputStream an OutputStream. Note that this is not flushed nor closed upon exit. + * @throws IOException if an error occurs during export + * @since 1.3 + */ + public void export(final List<Release> releases, final String feedType, final OutputStream outputStream) + throws IOException { feed.setFeedType(feedType); feed.setTitle(title); feed.setAuthor(author); feed.setPublishedDate(new Date()); + exportInternal(releases, outputStream); + } + + private void exportInternal(final List<Release> releases, final OutputStream outputStream) throws IOException { + feed.setLink(link); feed.setDescription(rbundle.getString("report.changes.text.rssfeed.description")); feed.setLanguage(rbundle.getLocale().getLanguage()); feed.setEntries(getEntries(releases)); try { new SyndFeedOutput().output(feed, writer); - } catch (FeedException ex) { + } catch (FeedException ex) { //NOPMD Review Comment: delete comment ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -161,27 +163,50 @@ public List<String> getSupportedFeedTypes() { } /** - * Extract a feed and export it to a Writer. + * Extract a feed and export it to a Writer. This method is deprecated, use + * {@link #export(List, String, OutputStream)} instead. * * @param releases the List of Releases. Only the last release is used in the feed. * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for * supported values. * @param writer a Writer. Note that this is not flushed nor closed upon exit. * @throws IOException if an error occurs during export + * @deprecated Use {@link #export(List, String, OutputStream)} instead. */ + @Deprecated public void export(final List<Release> releases, final String feedType, final Writer writer) throws IOException { + export(releases, feedType, new BufferedOutputStream(new WriterOutputStream(writer))); + } + + /** + * Extract a feed and export it to an OutputStream. + * + * @param releases the List of Releases. Only the last release is used in the feed. + * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for + * supported values. + * @param outputStream an OutputStream. Note that this is not flushed nor closed upon exit. + * @throws IOException if an error occurs during export + * @since 1.3 + */ + public void export(final List<Release> releases, final String feedType, final OutputStream outputStream) + throws IOException { feed.setFeedType(feedType); feed.setTitle(title); feed.setAuthor(author); feed.setPublishedDate(new Date()); Review Comment: never sets encoding, which is the point of the bug ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -235,4 +260,35 @@ private static Date getDate(final String dateRelease, final DateFormat dateForma return new Date(); } } + + /** + * Simple {@link OutputStream} implementation that writes to a {@link Writer}. + * + * @since 1.3 + */ + private static class WriterOutputStream extends OutputStream { Review Comment: This class is insane. Who would create something this broken? ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -161,27 +163,50 @@ public List<String> getSupportedFeedTypes() { } /** - * Extract a feed and export it to a Writer. + * Extract a feed and export it to a Writer. This method is deprecated, use + * {@link #export(List, String, OutputStream)} instead. * * @param releases the List of Releases. Only the last release is used in the feed. * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for * supported values. * @param writer a Writer. Note that this is not flushed nor closed upon exit. * @throws IOException if an error occurs during export + * @deprecated Use {@link #export(List, String, OutputStream)} instead. */ + @Deprecated public void export(final List<Release> releases, final String feedType, final Writer writer) throws IOException { + export(releases, feedType, new BufferedOutputStream(new WriterOutputStream(writer))); + } + + /** + * Extract a feed and export it to an OutputStream. + * + * @param releases the List of Releases. Only the last release is used in the feed. + * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for + * supported values. + * @param outputStream an OutputStream. Note that this is not flushed nor closed upon exit. + * @throws IOException if an error occurs during export + * @since 1.3 + */ + public void export(final List<Release> releases, final String feedType, final OutputStream outputStream) + throws IOException { feed.setFeedType(feedType); feed.setTitle(title); feed.setAuthor(author); feed.setPublishedDate(new Date()); + exportInternal(releases, outputStream); + } + + private void exportInternal(final List<Release> releases, final OutputStream outputStream) throws IOException { Review Comment: This implementation probably shouldn't be shared. ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -161,27 +163,50 @@ public List<String> getSupportedFeedTypes() { } /** - * Extract a feed and export it to a Writer. + * Extract a feed and export it to a Writer. This method is deprecated, use + * {@link #export(List, String, OutputStream)} instead. * * @param releases the List of Releases. Only the last release is used in the feed. * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for * supported values. * @param writer a Writer. Note that this is not flushed nor closed upon exit. * @throws IOException if an error occurs during export + * @deprecated Use {@link #export(List, String, OutputStream)} instead. */ + @Deprecated public void export(final List<Release> releases, final String feedType, final Writer writer) throws IOException { + export(releases, feedType, new BufferedOutputStream(new WriterOutputStream(writer))); + } + + /** + * Extract a feed and export it to an OutputStream. + * + * @param releases the List of Releases. Only the last release is used in the feed. + * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for + * supported values. + * @param outputStream an OutputStream. Note that this is not flushed nor closed upon exit. + * @throws IOException if an error occurs during export + * @since 1.3 + */ + public void export(final List<Release> releases, final String feedType, final OutputStream outputStream) + throws IOException { feed.setFeedType(feedType); feed.setTitle(title); feed.setAuthor(author); feed.setPublishedDate(new Date()); + exportInternal(releases, outputStream); + } + + private void exportInternal(final List<Release> releases, final OutputStream outputStream) throws IOException { + feed.setLink(link); feed.setDescription(rbundle.getString("report.changes.text.rssfeed.description")); feed.setLanguage(rbundle.getLocale().getLanguage()); feed.setEntries(getEntries(releases)); try { new SyndFeedOutput().output(feed, writer); Review Comment: writer variable does not exist. This does not compile. ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -235,4 +260,35 @@ private static Date getDate(final String dateRelease, final DateFormat dateForma return new Date(); } } + + /** + * Simple {@link OutputStream} implementation that writes to a {@link Writer}. + * + * @since 1.3 + */ + private static class WriterOutputStream extends OutputStream { + private final Writer writer; + + WriterOutputStream(final Writer writer) { + this.writer = writer; + } + + @Override + public void write(final int b) throws IOException { + writer.write(b); + } + + @Override + public void write(final byte[] b) throws IOException { + writer.write(new String(b)); Review Comment: only works in ASCII and 8859-1 ########## src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java: ########## @@ -235,4 +260,35 @@ private static Date getDate(final String dateRelease, final DateFormat dateForma return new Date(); } } + + /** + * Simple {@link OutputStream} implementation that writes to a {@link Writer}. + * + * @since 1.3 + */ + private static class WriterOutputStream extends OutputStream { + private final Writer writer; + + WriterOutputStream(final Writer writer) { + this.writer = writer; + } + + @Override + public void write(final int b) throws IOException { + writer.write(b); + } + + @Override + public void write(final byte[] b) throws IOException { + writer.write(new String(b)); + } + + @Override + public void write(final byte[] b, final int off, final int len) throws IOException { Review Comment: avoid single letter and abbreviated variable names -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org