From 835e0ada3a844606d7146b632704144ceec6dc7a Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 1 Mar 2025 14:59:57 -0500 Subject: [PATCH] DO NOT MERGE Gemini "fix for MCHANGES-467 --- .../maven/plugins/changes/FeedGenerator.java | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java b/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java index 7a9019ef..40fddf2c 100644 --- a/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java +++ b/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java @@ -18,6 +18,7 @@ */ package org.apache.maven.plugins.changes; +import java.io.BufferedOutputStream; import java.io.IOException; import java.io.Writer; import java.text.DateFormat; @@ -25,6 +26,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.io.OutputStream; import java.util.Locale; import java.util.ResourceBundle; @@ -161,19 +163,42 @@ public List 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 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 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 releases, final OutputStream outputStream) throws IOException { + feed.setLink(link); feed.setDescription(rbundle.getString("report.changes.text.rssfeed.description")); feed.setLanguage(rbundle.getLocale().getLanguage()); @@ -181,7 +206,7 @@ public void export(final List releases, final String feedType, final Wr try { new SyndFeedOutput().output(feed, writer); - } catch (FeedException ex) { + } catch (FeedException ex) { //NOPMD throw new IOException(ex.getMessage(), ex); } } @@ -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 { + writer.write(new String(b, off, len)); + } + + } + + }