Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/
package org.apache.maven.plugins.changes;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.io.OutputStream;
import java.util.Locale;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -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());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never sets encoding, which is the point of the bug

exportInternal(releases, outputStream);
}

private void exportInternal(final List<Release> releases, final OutputStream outputStream) throws IOException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation probably shouldn't be shared.


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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer variable does not exist. This does not compile.

} catch (FeedException ex) {
} catch (FeedException ex) { //NOPMD
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete comment

throw new IOException(ex.getMessage(), ex);
}
}
Expand Down Expand Up @@ -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 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is insane. Who would create something this broken?

private final Writer writer;

WriterOutputStream(final Writer writer) {
this.writer = writer;
}

@Override
public void write(final int b) throws IOException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all depends on the platform dependent default encoding.

writer.write(b);
}

@Override
public void write(final byte[] b) throws IOException {
writer.write(new String(b));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only works in ASCII and 8859-1

}

@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid single letter and abbreviated variable names

writer.write(new String(b, off, len));
}

}


}